/* * onOpen event */ function onOpen() { var ss = SpreadsheetApp.getActiveSpreadsheet(); if(ss){ var menuEntries = [ {name: "Get", functionName: "main"} ]; ss.addMenu("Torrents", menuEntries); } } /** * Do replacements to clean text * * @param {String} str * @return {String} */ var replaces = function(str){ return str.replace(/<[^>]*>/g," ") .replace(/[\t\r\n]/g,"") .replace(/\[.*\]/g,"") .replace(/^\s+|\s+$/g,"") .replace(/\./g," ") .replace(/\s{2,}/g, ' ') ; } /** * Get content between ">" and next closing "tag" (" or init "")+1),str.indexOf("-1){ return true; } } return false; } /** * Global data services to query */ var dataServices = { //"eztv" : "eztvData", "pb" : "pirateBayData", "kickass" : "kickassData" }; /** * Searches for torrent content * * @param {String} strtorrent * @param {Array} services * @param {Array} includes * @return {Array} */ var getData = function(strtorrent, services, includes, min_torrent_files, min_seeds){ var torrents = []; var self = this; for(var i=0,z=services.length;i0){ var cols,title,link,aux; var oks = []; for(var i=1,z=data.length;i-1){ //torrent file link = cols[4].split("href=\""); link = link[1].slice(0, link[1].indexOf("\"")); if(title!=="" && ((includes.length>0 && existsArrInStr(includes,title)) || includes.length===0)){ oks.push([title,[link]]); } } } return oks; } } /** * Adapter for eztv.it * * @param {String} strtorrent * @param {String} includes * @return {Array} */ /*var eztvData = function(strtorrent,includes){ var response = httpMutedRequest("http://eztv.it/search/",{ 'payload' : { 'SearchString1': strtorrent }, 'headers' : { 'contentType' : 'text/html; charset=utf-8', }, 'method' : 'post', }); if(response===null){ return []; } var data = response.getContentText(); data = data.split("forum_header_border"); if(data.length>0){ var cols,title,link,aux; var oks = []; for(var i=7,z=data.length;i-1){ //torrent file torrents = getTagContent(cols[3],false,"td"); torrents = torrents.split("=3){ aux = torrents[3].split("href=\""); if(aux.length>1 && aux[1].indexOf("magnet")===-1){ link.push((aux[1].indexOf("http://")===-1?"http:":"")+aux[1].slice(0,aux[1].indexOf('"'))); } } if(title!=="" && link.length>0 && ((includes.length>0 && existsArrInStr(includes,title)) || includes.length===0)){ oks.push([title,link]); } } } return oks; } }*/ /** * Get the current DNS for piratebay and set its in Public Cache (if it was shared...) * */ var getPirateBayDNS = function(){ if(!dataServices["pb"]) return null; var dns = ["cr","org","sx","se","pe"]; for(var d=0,r=dns.length;d"); if(data.length>0){ var cols,title,link,aux,torrents; var oks = [], seeds; var prob_oks = 0; for(var i=1,z=data.length;i-1){ prob_oks++; torrents = cols[2].split("magnet:?"); if(torrents.length>1){ seeds = parseInt(getTagContent(cols[3],false,"td")) if((includes.length>0 && !existsArrInStr(includes,title)) || seeds0){ return; } ScriptApp.newTrigger('main') .timeBased() .everyHours(4) .create(); } /** * Check for the TV Shows in the User Properties and emails the torrents if it finds them. * Pattern of properties has to be "tvshow sXXeXX" > "dexter s07s07" */ function main(){ var body = [], props = [], r, as = SpreadsheetApp.getActiveSheet(), priority = PropertiesService.getScriptProperties().getProperty("priority"), includes = PropertiesService.getScriptProperties().getProperty("include"), //string that must be present in links min_torrent_files =PropertiesService.getScriptProperties().getProperty("min_torrent_files"), min_seeds =PropertiesService.getScriptProperties().getProperty("min_seeds"); priority = priority===null?["pb","kickass"]:priority.split(","); includes = includes===null || includes===""?[]:includes.split(","); min_torrent_files = min_torrent_files!==null?min_torrent_files:10; min_seeds = min_seeds!==null?min_seeds:1000; checkTriggers(); if(as){ var c = 1; do{ r = as.getRange("A"+c).getValue(); if(r!=""){ props.push(r); } c++; }while(r!="") }else{ props = PropertiesService.getScriptProperties().getKeys(); } var chapter; for(var l=0,x=props.length;l0){ body.push("
  • ",chapter.toUpperCase(),"
      "); for(var i=0;i",r[i][0],""); } body.push("
"); updateProperties(chapter,as,l+1,props[l]); } if(body.length>0){ MailApp.sendEmail(Session.getActiveUser().getEmail(), "[Google Apps Torrent Email] - " + chapter.toUpperCase(),"", {htmlBody: body.join("")}); } body=[]; } }