Created
July 27, 2010 18:45
-
-
Save arestov/492658 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(function(){ | |
var logger = $('<p></p>').css('color', '#222'); | |
var log = function(logtext){ | |
$(document.body).append(logger.clone().text(logtext + ' ')); | |
} | |
log('btapp: ' + typeof btapp) | |
log('btapp.events: ' + typeof btapp.events) | |
log('btapp.events.all(): ' + typeof btapp.events.all()) | |
log('btapp.events.all(): ' + JSON.stringify(btapp.events.all())) | |
log('btapp.events.all().torrent: ' + typeof btapp.events.all().torrent); | |
var init_torrent = function(torrent){ | |
log('mmemmeme'); | |
log("typeof torrent: " + typeof torrent); | |
log("typeof torrent.properties: " + typeof torrent.properties); | |
log("typeof torrent.properties.get: " + typeof torrent.properties.get); | |
var download_url = torrent.properties.get('download_url'); | |
log(download_url + 'z') | |
if (torrent_index[download_url] && !torrent_index[download_url].stopped_at_init){ | |
log('typeof torrent: ' + typeof torrent) | |
torrent.pause(); | |
torrent.stop(); | |
log('after stop') | |
log('typeof torrent.pause: ' + typeof torrent.pause) | |
log('typeof torrent.stop: ' + typeof torrent.stop) | |
log('typeof torrent.stop: ' + typeof torrent.stop) | |
log('typeof torrent.start: ' + typeof torrent.start) | |
log('typeof torrent.file: ' + typeof torrent.file) | |
log('typeof torrent.file.all: ' + typeof torrent.file.all) | |
log('typeof torrent.all(): ' + typeof torrent.file.all()) | |
//torrent.stop(); | |
var files = torrent.file.all(); | |
for (var file_num in files) { | |
var file = files[file_num]; | |
log('typeof file.properties.set: ' + typeof file.properties.set) | |
file.properties.set('priority', 0) | |
}; | |
torrent_index[download_url].stopped_at_init = true; | |
log('inited: ' + download_url) | |
} else{ | |
log('not inited: ' + download_url) | |
} | |
} | |
var added_torrents_check = function(torrents){ | |
for (var torrent in torrents) { | |
init_torrent(torrents[torrent]); | |
}; | |
} | |
log("bt.torrent.all(): " + bt.torrent.all()); | |
log("btapp.torrent.all(): " + btapp.torrent.all()); | |
log('typeof btapp.events.set: ' + typeof btapp.events.set) | |
if (typeof btapp.events.set == 'function'){ | |
log('btapp.events.set') | |
btapp.events.set('torrent', function(r){ | |
if (r.message == 'success'){ | |
var trt = btapp.torrent.get(r.hash); | |
init_torrent(trt); | |
} | |
}); | |
} else{ | |
log('added_torrents_checking') | |
log('typeof btapp.torrent: ' + typeof btapp.torrent) | |
log('typeof btapp.torrent.all: ' + typeof btapp.torrent.all) | |
log('typeof btapp.torrent.all(): ' + typeof btapp.torrent.all()) | |
var added_torrents_checking = setInterval(function(){ | |
added_torrents_check(btapp.torrent.all()); | |
},100) | |
} | |
log('all fine'); | |
window.bigii_songs = []; | |
var torrent_index = {}; | |
window.torrent_index = torrent_index; | |
var search_song = function(song){ | |
$.ajax({ | |
global: false, | |
type: "GET", | |
dataType: "jsonp", | |
url: "http://ajax.googleapis.com/ajax/services/search/web?cx=001069742470440223270:ftotl-vgnbs", | |
data: { | |
v: "1.0", | |
q: "allintext:" + song + '.mp3' | |
}, | |
error:function(){ | |
console.log('google search requset error') | |
}, | |
success: function(r){ | |
bigii_songs.push(r) | |
if (r.responseData && r.responseData.results && r.responseData.results && r.responseData.results.length){ | |
for (var i=0; i < r.responseData.results.length; i++) { | |
var simple_part = r.responseData.results[i].unescapedUrl | |
.replace(/(.)+torrent_details\//,'') | |
.replace(/\?(.)+/,''); | |
var link_to_torrent = 'http://isohunt.com/download/' + simple_part + '.torrent'; | |
if (!torrent_index[link_to_torrent]){torrent_index[link_to_torrent] = { waiting_searches : []}} | |
torrent_index[link_to_torrent].waiting_searches.push(song); | |
btapp.add.torrent(link_to_torrent) | |
}; | |
} | |
} | |
}) | |
} | |
var songs = ['The Killers - Somebody Told Me', | |
'The Killers - Mr. Brightside', | |
'The Killers - When You Were Young', | |
'The Killers - Smile Like You Mean It', | |
"The Killers - All These Things That I've Done"]; | |
for (var i=0; i < songs.length; i++) { | |
search_song(songs[i]); | |
}; | |
log(location.href) | |
}) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment