我正在尝试重复从 Google Drive 获取可下载链接的过程,就像在 Internet Download Manager (Windows) 中使用的那样。
我正在做以下事情:
fmt_stream_map .互联网下载管理器使用了相同的方法,而且效果很好。我正在使用我的手机获取链接,并通过我的手机访问它。所以基本上它是相同的 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 链接:
所需的 header 未记录,因为您不应该以这种方式集成 google drive
关于java - 从 Google 云端硬盘获取可流式链接 [代码已准备就绪,访问被拒绝],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50044904/
如何在buildr项目中使用Ruby?我在很多不同的项目中使用过Ruby、JRuby、Java和Clojure。我目前正在使用我的标准Ruby开发一个模拟应用程序,我想尝试使用Clojure后端(我确实喜欢功能代码)以及JRubygui和测试套件。我还可以看到在未来的不同项目中使用Scala作为后端。我想我要为我的项目尝试一下buildr(http://buildr.apache.org/),但我注意到buildr似乎没有设置为在项目中使用JRuby代码本身!这看起来有点傻,因为该工具旨在统一通用的JVM语言并且是在ruby中构建的。除了将输出的jar包含在一个独特的、仅限ruby
在rails源中:https://github.com/rails/rails/blob/master/activesupport/lib/active_support/lazy_load_hooks.rb可以看到以下内容@load_hooks=Hash.new{|h,k|h[k]=[]}在IRB中,它只是初始化一个空哈希。和做有什么区别@load_hooks=Hash.new 最佳答案 查看rubydocumentationforHashnew→new_hashclicktotogglesourcenew(obj)→new_has
我真的很习惯使用Ruby编写以下代码:my_hash={}my_hash['test']=1Java中对应的数据结构是什么? 最佳答案 HashMapmap=newHashMap();map.put("test",1);我假设? 关于java-等价于Java中的RubyHash,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/22737685/
我的主要目标是能够完全理解我正在使用的库/gem。我尝试在Github上从头到尾阅读源代码,但这真的很难。我认为更有趣、更温和的踏脚石就是在使用时阅读每个库/gem方法的源代码。例如,我想知道RubyonRails中的redirect_to方法是如何工作的:如何查找redirect_to方法的源代码?我知道在pry中我可以执行类似show-methodmethod的操作,但我如何才能对Rails框架中的方法执行此操作?您对我如何更好地理解Gem及其API有什么建议吗?仅仅阅读源代码似乎真的很难,尤其是对于框架。谢谢! 最佳答案 Ru
我的假设是moduleAmoduleBendend和moduleA::Bend是一样的。我能够从thisblog找到解决方案,thisSOthread和andthisSOthread.为什么以及什么时候应该更喜欢紧凑语法A::B而不是另一个,因为它显然有一个缺点?我有一种直觉,它可能与性能有关,因为在更多命名空间中查找常量需要更多计算。但是我无法通过对普通类进行基准测试来验证这一点。 最佳答案 这两种写作方法经常被混淆。首先要说的是,据我所知,没有可衡量的性能差异。(在下面的书面示例中不断查找)最明显的区别,可能也是最著名的,是你的
几个月前,我读了一篇关于rubygem的博客文章,它可以通过阅读代码本身来确定编程语言。对于我的生活,我不记得博客或gem的名称。谷歌搜索“ruby编程语言猜测”及其变体也无济于事。有人碰巧知道相关gem的名称吗? 最佳答案 是这个吗:http://github.com/chrislo/sourceclassifier/tree/master 关于ruby-寻找通过阅读代码确定编程语言的rubygem?,我们在StackOverflow上找到一个类似的问题:
我正在尝试使用boilerpipe来自JRuby。我看过guide从JRuby调用Java,并成功地将它与另一个Java包一起使用,但无法弄清楚为什么同样的东西不能用于boilerpipe。我正在尝试基本上从JRuby中执行与此Java等效的操作:URLurl=newURL("http://www.example.com/some-location/index.html");Stringtext=ArticleExtractor.INSTANCE.getText(url);在JRuby中试过这个:require'java'url=java.net.URL.new("http://www
我目前正在使用以下方法获取页面的源代码:Net::HTTP.get(URI.parse(page.url))我还想获取HTTP状态,而无需发出第二个请求。有没有办法用另一种方法做到这一点?我一直在查看文档,但似乎找不到我要找的东西。 最佳答案 在我看来,除非您需要一些真正的低级访问或控制,否则最好使用Ruby的内置Open::URI模块:require'open-uri'io=open('http://www.example.org/')#=>#body=io.read[0,50]#=>"["200","OK"]io.base_ur
我只想对我一直在思考的这个问题有其他意见,例如我有classuser_controller和classuserclassUserattr_accessor:name,:usernameendclassUserController//dosomethingaboutanythingaboutusersend问题是我的User类中是否应该有逻辑user=User.newuser.do_something(user1)oritshouldbeuser_controller=UserController.newuser_controller.do_something(user1,user2)我
什么是ruby的rack或python的Java的wsgi?还有一个路由库。 最佳答案 来自Python标准PEP333:Bycontrast,althoughJavahasjustasmanywebapplicationframeworksavailable,Java's"servlet"APImakesitpossibleforapplicationswrittenwithanyJavawebapplicationframeworktoruninanywebserverthatsupportstheservletAPI.ht