Git Product home page Git Product logo

apollonbar / resourcedetector Goto Github PK

View Code? Open in Web Editor NEW

This project forked from qqliu10u/resourcedetector

0.0 0.0 0.0 185 KB

这是一个Android端对网页内的图片/视频进行探测的一个小应用,目前可用于Tumblr的资源下载。但通过自己编写资源探测脚本,可以支持任意网页的资源嗅探工作。原理比较简单,通过WebView加载页面和页面内合适的iframe子页面,通过注入js检测页面的资源并回调到java下载。This is a simple tool to download video and pics from urls in android phone. The tools is designed for downloading tumblr video and pics at the beginning, but it can also be used to detect other website when we specify a *.js file for detecting.

JavaScript 7.92% Java 92.08%

resourcedetector's Introduction

ResourceDetector使用方法介绍

如果不需要对其他网站进行资源嗅探,那么下载最新版本apk就可以了,我后面会不断优化tumblr内的资源的探测,毕竟目前还是有些资源探测不到,需要调整探测算法。

##1 具体的使用方法

  1. 通过点击感兴趣的内容条目上的分享按钮,选择分享对象时选择“资源嗅探器”即可调起工具进行资源嗅探流程,在嗅探过程中,可以返回到上个页面继续浏览。
  2. 如果想要自己输入url探测,则在桌面启动应用点击右上角“探测资源”进入探测界面,然后输入url点击开始探测即可。

##2 自己写探测脚本 我们以user.tumblr.com为例,来说明探测脚本的写法: 首先这个页面内既可能是嵌套iframe来展示资源(如展示图集或展示视频),也可能直接展示资源(单个图集和部分视频)。所以这个页面两个嗅探逻辑都需要写。 其次,这个页面需要一个判断是当前网站的一个url正则表达式,而且需要与www.tumblr.com分开,我这里写的是"http://[^www]..tumblr.com/."。 所以这个页面的探测脚本如下:

//探测合适的iframe
registerIFrameDetectFunction(USER_TUMBLR_COM_URL_REG, function () {
    var iframeArray = new Array;

    //通过内容区定位iframe
    detectIframeByContent(iframeArray);

    //通过视频容器区收集iframe
    detectIframeByVideoContainer(iframeArray);

    return iframeArray;
});

//探测资源
registerResourceDetectFunction(USER_TUMBLR_COM_URL_REG, function () {
    //探测图集
    detectPicSet();

	//探测视频
	detectVideoByVideoTag();

	//探测单张图片
	detectOnePic();
});

因为这个url对应的页面结构比较复杂,所以我们需要多种iframe的探测方法(代码中的注册iframe检测registerIFrameDetectFunction需要注册两种iframe的探测方法,注册资源检测registerResourceDetectFunction需要完成三种资源检测步骤)。但总体逻辑都是相同的,使用者需要针对指定页面完成三步:

  1. 确定url的正则表达式,以字符串参数形式传递作为registerIFrameDetectFunction和registerResourceDetectFunction第一个参数。
  2. 根据页面的Dom树的className和id完成iframe的过滤,脚本函数作为registerIFrameDetectFunction的第二个参数注册。
  3. 根据页面的Dom树的className和id完成资源的过滤,包括视频和图片两部分,脚本函数作为registerResourceDetectFunction第三个参数注册。

三步写完,一个新网址的资源探测过程脚本就编写完成了,将文件存为XX.js,放入/sdcard/ResourceDetector/detect_code/目录下,重启应用即可生效。

使用方法很简单吧,想看具体的设计思路与细节:请参考:http://blog.csdn.net/u013478336/article/details/53539526

resourcedetector's People

Contributors

qqliu10u avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.