gpt4 book ai didi

java - 从 Google 云端硬盘获取可流式链接 [代码已准备就绪,访问被拒绝]

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:04:09 25 4
gpt4 key购买 nike

我正在尝试重复从 Google Drive 获取可下载链接的过程,就像在 Internet Download Manager (Windows) 中使用的那样。

我正在做以下事情:

  1. 下载链接的 HTML 源代码。
  2. 使用正则表达式搜索 fmt_stream_map .
  3. 解码。
  4. 正在尝试访问链接。
  5. 访问被拒绝。

互联网下载管理器使用了相同的方法,而且效果很好。我正在使用我的手机获取链接,并通过我的手机访问它。所以基本上它是相同的 IP 和相同的设备。

我的代码首先下载源代码。搜索 map 列表,然后将质量及其描述存储在数组中。之后,我搜索 fmt_stream_map 的链接,并将它们添加到最终的 model 中。 , 以便轻松访问它们。

我有 3 个类,其中两个是模型,最后一个是这个过程的主要类。

public class ItemStreamList {

private String quality;
private String description;

public ItemStreamList(){

}

public ItemStreamList(String quality, String description){
this.quality = quality;
this.description = description;
}

public String getQuality() {
return quality;
}

public void setQuality(String quality) {
this.quality = quality;
}

public String getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;
}
}





public class ItemLink {

private String quality;
private String qualityDesc;
private String link;

public ItemLink(){

}

public ItemLink(String quality, String qualityDesc, String link){
this.quality = quality;
this.qualityDesc = qualityDesc;
this.link = link;
}

public String getQualityDesc() {
return qualityDesc;
}

public void setQualityDesc(String qualityDesc) {
this.qualityDesc = qualityDesc;
}

public String getLink() {
return link;
}

public void setLink(String link) {
this.link = link;
}

public String getQuality() {
return quality;
}

public void setQuality(String quality) {
this.quality = quality;
}
}

现在我们来到主类。这是一个“位”记录。

  @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

getPageHTML("https://drive.google.com/file/d/0B7--EhvK76QDNmduLWFZMXh1dGs/view");
}

private void getPageHTML(final String mURL){
new Thread(new Runnable() {
@Override
public void run() {
try {
Document mDoc = Jsoup.connect(mURL).get();
String mHTML = mDoc.toString();

boolean hasSetStreamMapList = setStreamMapList(mHTML);

String mStreamMap = getMatchRegex(mHTML,"\"fmt_stream_map\",\"","\"]");
mStreamMap = org.apache.commons.text.StringEscapeUtils.unescapeJava(mStreamMap);
String[] mStreamMapQualities = mStreamMap.split(",");

if(hasSetStreamMapList){
List<ItemLink> mLinks = new ArrayList<>();

for (int i = 0; i < mStreamMapQualities.length; i++){
String[] mLinksArray = mStreamMapQualities[i].split("\\|");
String mLink = mLinksArray[1];
mLink = mLink.replaceAll("%2",",");
mLinks.add(new ItemLink(mLinksArray[0],getQualityDescription(mLinksArray[0]),mLink));
}

for (int i = 0; i < mLinks.size(); i++){
Log.i("StreamMap","Quality: " + mLinks.get(i).getQuality() + " - " + mLinks.get(i).getQualityDesc() + "\n" + "Link: " + mLinks.get(i).getLink());
Log.i("StreamMap","---------------------------");
}

startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(mLinks.get(0).getLink())));


} else {
Log.i("StreamMap","Stream Map is NOT set");
}

} catch (IOException e) {
e.printStackTrace();
}
}
}).start();
}

private List<ItemStreamList> mStreamListItems;

private String getQualityDescription(String mQuality){
// Loop through the Stream Map's Array
for (int i = 0; i < mStreamListItems.size(); i++){
// If the Quality contains the Param, then return it
if(mStreamListItems.get(i).getQuality().contains(mQuality))
return mStreamListItems.get(i).getDescription();
}
// Didn't find the quality, return null
return null;
}

private boolean setStreamMapList(String mSource){

// Define the Array
mStreamListItems = new ArrayList<>();

// Get the fmt_list from the HTML
String mStreamMapList = getMatchRegex(mSource,"\"fmt_list\",\"","\"]");
// Check if isn't null
if(mStreamMapList != null){
// Split the qualities by ","
String[] mStreamMapListArray = mStreamMapList.split(",");
// Loop through the Array
for (int i = 0; i < mStreamMapListArray.length; i++){
/*
Split the array by "/"
First index has the quality
Second index has the quality's description
*/
String[] mModelArray = mStreamMapListArray[i].split("/");
mStreamListItems.add(new ItemStreamList(mModelArray[0],mModelArray[1]));
}

return true;

}

// It's null or not set, return false
return false;
}

private String getMatchRegex(String mSource, String mFirst, String mSecond){
String regexString = Pattern.quote(mFirst) + "(.*?)" + Pattern.quote(mSecond);
Pattern mPattern = Pattern.compile(regexString);
Matcher mMatcher = mPattern.matcher(mSource);
while(mMatcher.find())
{
String resultString = mMatcher.group(1);


return resultString;
}
return null;
}

最佳答案

您得到一个 403 代码,因为您没有在 fmt_stream_map 链接上的请求中传递任何 header 。

在浏览器中打开顶部链接时,将使用所有这些 header 查询 fmt_stream_map 链接:

enter image description here

所需的 header 未记录,因为您不应该以这种方式集成 google drive

关于java - 从 Google 云端硬盘获取可流式链接 [代码已准备就绪,访问被拒绝],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50044904/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com