fiddler2 脚本

customize rules

public static var mp3BasePath:String = "F:\doubanMP3";
public static var doubanPlayList:String=null;
public static var imgBasePath:String = "F:\Img";

static function OnBeforeResponse(oSession: Session) {
if (m_Hide304s && oSession.responseCode == 304) {
oSession["ui-hide"] = "true";
}

DownloadDoubanMP3(oSession);
}

 

static function DownloadDoubanMP3(oS:Session)
{
if(oS.HostnameIs("douban.fm")&&oS.uriContains("playlist"))
{
LogString("++++++++++PlayList-----------");
LogString(oS.url);
oS.utilDecodeResponse();
var temp:String=System.Text.Encoding.UTF8.GetString(oS.responseBodyBytes);
if(temp!="\"ok\""&&temp.Replace(/(^\s*)|(\s*$)/g, "")!="")
{
doubanPlayList=temp;
//FiddlerObject.alert(doubanPlayList);
LogString("Content:"+temp);
}
//FiddlerObject.alert(doubanPlayList);
LogString("----------PlayList+++++++++++");
}
if(oS.hostname.Contains("douban.com")&&oS.url.EndsWith(".mp3"))
{
LogString("++++++++++MP3-----------");
if(oS.oResponse.headers.ExistsAndContains("Content-Type", "audio/mpeg")){
//FiddlerObject.alert(doubanPlayList);
//FiddlerObject.alert(oSession.url.Substring(oSession.url.LastIndexOf("/")));
var reg:RegExp=new RegExp(".*\"artist\":\"(.*?)\".*?"+oS.url.Substring(oS.url.LastIndexOf("/"))+".*?\"title\":\"(.*?)\".*?}");
LogString("Reg:"+reg);
LogString("PlayList:"+doubanPlayList);
var arr:Array=reg.exec(doubanPlayList);
// FiddlerObject.alert(arr[1]+" "+arr[2]);
var path: String = System.IO.Path.Combine(mp3BasePath, arr[1]+"-"+arr[2]+".mp3");
LogString("Path:"+path);
if(!System.IO.File.Exists(path))
{
oS.SaveResponseBody(path);
}
}
LogString("---------MP3++++++++++++");
}
}

static function DownloadImages(oS:Session)
{
if ((oS.oResponse != null) && (oS.oResponse.headers != null)&&oS.oResponse.headers.ExistsAndContains("Content-Type", "image/"))
{
//FiddlerObject.alert("ok");
try{
var oMS: System.IO.MemoryStream = new System.IO.MemoryStream(oS.responseBodyBytes);
var i:System.Drawing.Bitmap = new System.Drawing.Bitmap(oMS);
if(i.Width>400&i.Height>400)
{
var path:String=System.IO.Path.Combine(imgBasePath,Guid.NewGuid()+oS.url.Substring(oS.url.LastIndexOf(".")));
i.Save(path);
}
}
catch(e) { return e; }
}
}

 

To be continue...

你可能感兴趣的:(fiddler)