// ==UserScript==
// @name TorrentZ [load IMDB info]
// @namespace
// @version 1.02
// @description Show info of movie/series (rating, poster, actors, ...) from IMDB on TorrentZ domains (torrentz.eu, torrentz.com, ...)
// @author hossam6236
// @license GNU General Public License v3.0
// @include https://torrentz.eu/*
// @include https://www.torrentz.eu/*
// @include https://torrentz.ph/*
// @include https://www.torrentz.ph/*
// @include https://torrentz.li/*
// @include https://www.torrentz.li/*
// @include https://torrentz.com/*
// @include https://www.torrentz.com/*
// @include https://torrentz.me/*
// @include https://www.torrentz.me/*
// @include https://torrentz.in/*
// @include https://www.torrentz.in/*
// @include https://torrentz.hk/*
// @include https://www.torrentz.hk/*
// @include https://torrentz.ch/*
// @include https://www.torrentz.ch/*
// @include https://torrents.de/*
// @include https://www.torrents.de/*
// @include https://tz.ai/*
// @include https://www.tz.ai/*
// @include https://torrentz-proxy.com/*
// @include https://www.torrentz-proxy.com/*
// @include https://bestdownload.eu/*
// @include https://www.bestdownload.eu/*
// @include https://torrentsmirror.com/*
// @include https://www.torrentsmirror.com/*
// @require https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js
// @grant GM_xmlhttpRequest
// ==/UserScript==
// regext for cleaning the titles
var reM = /\d{4}/;
var reS = /S\d{2}E\d{2}|\d{1}x\d{2}/;
var from_imdb = false;
var live = false;
movie_db = {};
try {
var c = localStorage.getItem('movie_db');
if (c) {
$.extend(movie_db, JSON.parse(c));
}
var count = 0;
start_button = $('<div style="width: 200px; height: 60px;display: inline-block;"><div style="height: 20px; margin: 0px;"><input type="checkbox" name="from_imdb" id="from_imdb" style="margin: 0px; display: inline-block;" checked /><label for="from_imdb" style="font:10pt Tahoma; margin: 0px; display: inline-block;">from IMDb</label> | <input type="checkbox" name="live" id="live" style="margin: 0px; display: inline-block;" /><label for="live" style="font:10pt Tahoma; margin: 0px; display: inline-block;">live</label> | <a href="javascript:location.reload();" style="color:#000; font:7pt Tahoma;" id="clear">(clear cache)</a></div><button style="display: inline-block; margin:0px; padding:7px; font:12pt Tahoma;" id="start"> load IMDb info </button></div>');
//start_button.appendTo($('h1').first());
// start_button.appendTo($('h1').first());
start_button.insertAfter($('h1').first());
start_button.css({height: start_button.parent().height()>0 ? start_button.parents('div').height() : start_button.parents('div').height()});
var updateElement_dl = function(stor_title, dl_element){
if (movie_db[stor_title]==false) {
$('a', dl_element).css('color','#777');
return true;
}
//alert(stor_title);
var el_title = movie_db[stor_title].imdbVotes + ' votes - ' + movie_db[stor_title].Runtime + ' - Rated ' + movie_db[stor_title].Rated + ' - Awards: ' + movie_db[stor_title].Awards;
var star = '';
var reg_wins = /([0-9]+) win(s|)/;
var reg_noms = /([0-9]+) nomination(s|)/;
var reg_wins_sig = /won ([0-9]+) /;
var reg_noms_sig = /nominated for ([0-9]+) /;
var wins = reg_wins.exec(movie_db[stor_title].Awards.toLowerCase()); if(wins) wins = parseFloat(wins[1]);
var noms = reg_noms.exec(movie_db[stor_title].Awards.toLowerCase()); if(noms) noms = parseFloat(noms[1]);
var wins_sig = reg_wins_sig.exec(movie_db[stor_title].Awards.toLowerCase()); if(wins_sig) wins_sig = parseFloat(wins_sig[1]);
var noms_sig = reg_noms_sig.exec(movie_db[stor_title].Awards.toLowerCase()); if(noms_sig) noms_sig = parseFloat(noms_sig[1]);
//if(match) alert(match[1]);
if((wins_sig >= 1 || noms_sig >= 3) && (wins >= 5 || noms >= 10)){
star = '<span style="color:#DD0000">★</span>';
}else if(wins >= 10 || (noms_sig >= 1 && noms >= 5)){
star = '<span style="color:#660000">★</span>';
}else if(wins >= 5 || noms >= 10 || noms_sig >= 1){
star = '★';
}else if(wins + noms >= 1){
star = '☆';
}
var el = '<a href="http://www.imdb.com/title/' + movie_db[stor_title].imdbID + '" target="_blank" title="' + el_title + '">' + movie_db[stor_title].imdbRating + star + '</a>';
//$('a', dl_element).first().attr('title', movie_db[stor_title].Title + ' (' + movie_db[stor_title].Year + ') - ' + movie_db[stor_title].Plot);
//$('a', dl_element).first().after(' <b style="font-size:80%;">('+movie_db[stor_title].Genre + ')</b>');
$('a', dl_element).first().on('mouseover', function(e){
poster_img.find('img').attr('src', "");
poster_img.find('img').attr('src', movie_db[stor_title].Poster);
poster_img.find('#imdb_a').attr('href', 'http://www.imdb.com/title/' + movie_db[stor_title].imdbID + '');
poster_img.find('#imdb_a').attr('title', movie_db[stor_title].Title + ' (' + movie_db[stor_title].Year + ')');
poster_img.find('#imdb_title').html(movie_db[stor_title].Title);
poster_img.find('#imdb_year').html(movie_db[stor_title].Year);
poster_img.find('#imdb_rating').html(movie_db[stor_title].imdbRating);
poster_img.find('#imdb_votes').html(movie_db[stor_title].imdbVotes);
poster_img.find('#imdb_rated').html(movie_db[stor_title].Rated);
poster_img.find('#imdb_runtime').html(movie_db[stor_title].Runtime);
poster_img.find('#imdb_awards').html(movie_db[stor_title].Awards.replace('Another ', '<br />Another '));
poster_img.find('#imdb_genre').html(movie_db[stor_title].Genre);
poster_img.find('#imdb_actors').html(movie_db[stor_title].Actors);
poster_img.find('#imdb_director').html(movie_db[stor_title].Director);
poster_img.find('#imdb_writer').html(movie_db[stor_title].Writer);
poster_img.find('#imdb_plot').html(movie_db[stor_title].Plot);
//alert(1);
if (movie_db[stor_title].Trailer!==undefined) {
poster_img.find('#imdb_trailer').show();
poster_img.find('#imdb_trailer').find('a').attr('href', movie_db[stor_title].Trailer);
poster_img.find('#imdb_trailer').find('a').attr('onclick', "javascript:window.open('" + movie_db[stor_title].Trailer + "', '', 'width=400, height=225'); return false;");
//poster_img.find('#imdb_trailer').find('iframe').prop('src',movie_db[stor_title].Trailer);
//alert(2);
}else{
poster_img.find('#imdb_trailer').hide()
//alert(3);
}
poster_img.css({
left: $(window).width()*2/3 - poster_img.width()/2, //e.pageX + 100,
top: $(window).height()/2 - poster_img.height()/2
});
//poster_img.attr('stor_title','Actors: ' + movie_db[stor_title].Actors + ' - Director: ' + movie_db[stor_title].Director)
poster_img.stop(true, true).show();
});
$('a', dl_element).first().on('mouseout', function(e){
poster_img.stop(true, true).fadeOut(2000);
});
//$('b', this).attr('style','font-size:65%;')
var rating = parseFloat(movie_db[stor_title].imdbRating);//alert(rating);
var votes = parseFloat(movie_db[stor_title].imdbVotes.replace(',',''));
if (rating >= 7.5) { el = '<b>'+el+'</b>'; }
$('dt', dl_element).prepend(el+ ' ');
if(rating <= 5.0 || votes <= 1000){
$('dt', dl_element).css({opacity: Math.max(0.15, Math.min(rating/10, votes/1000/2))});
}else if(movie_db[stor_title].imdbRating == "N/A" || movie_db[stor_title].imdbVotes == "N/A"){
$('dt', dl_element).css({opacity: 0.15});
}
$('#loading', dl_element).hide();
};
var getImdbInfo = function(title, year, dl_element) {
if(!$(dl_element).is(":visible")){
return true;
}
$(' <span id="loading" style="font-size:55%; display:inline-block; width:40px;"> (Loading) </span> ').insertBefore($('a', dl_element).first());
var stor_title = ( title + '_' + year + from_imdb );
//alert("\""+title + "\""+year);
//alert(url);
if ( !live && stor_title in movie_db && movie_db[stor_title]!==false ) {
updateElement_dl(stor_title, dl_element);
return true;
}else{
if (from_imdb){
var url = 'http://www.imdb.com/xml/find?json=1&nr=1&tt=on&q=' + encodeURIComponent(title /*+ ' (' + year + ')'*/);
$('#loading', dl_element).text('Loading1');
GM_xmlhttpRequest({
method: 'GET',
url: url,
onload: function(response) {
//alert(title + ' (' + year + ')' + ':' + response.responseText);
var resp = JSON.parse(response.responseText);
var results = [];
var data = [];
if(resp['title_popular']){
results = $.merge(results, resp['title_popular']);
}
if(resp['title_exact']){
results = $.merge(results, resp['title_exact']);
}
if(resp['title_approx']){
results = $.merge(results, resp['title_approx']);
}
if(reM.exec(year)){
$.each(results, function(index, item){
if(item['title_description'].indexOf(year)>-1){
data = $.merge(data, [item]);
//break;
}
});
results = data;
}else{
$.each(results, function(index, item){
if(item['title_description'].toLowerCase().indexOf('series')>-1){
data = $.merge(data, [item]);
//break;
}
});
results = data;
}
data = 0;
//alert(JSON.stringify(results));
$.each(results, function(index, item){
if(data===0 && item['title']==title){
data = item;
//break;
}
});
if(data===0){ data = results[0]; }
//alert(title + ' (' + year + ')' + ':' + JSON.stringify(resp['title_approx']));
if (data){
var movie_imdb = {};
movie_imdb['imdbID'] = data['id'];
movie_imdb['Title'] = data['title'];
//if(movie_imdb['Title'] == 'Babysitting 2'){ alert(); }
//movie_imdb['Year'] = /\d{4}/.exec(data['title_description']); movie_imdb['Year'] = movie_imdb['Year'][0]
//movie_imdb['Director'] = $(data['title_description'].replace(movie_imdb['Year']+',', '')).text();
movie_imdb['Year'] = /[0-9]{4}/.exec(data['title_description']); movie_imdb['Year'] = movie_imdb['Year'][0]
movie_imdb['Director'] = $(data['title_description'].substring(data['title_description'].indexOf(',')+1, data['title_description'].length)).text();
var url2 = 'http://m.imdb.com/title/' + movie_imdb['imdbID'] + '/';
$('#loading', dl_element).text('Loading2');
GM_xmlhttpRequest({
method: 'GET',
url: url2,
onload: function(response2) {
//if(movie_imdb['Title'] == 'The Intern'){ alert(url2+': '+JSON.stringify(movie_imdb)); }
//var resp2 = response2.responseText.replace(/<script([\S\s]*?)>([\S\s]*?)<\/script>/igm,'');
//resp2 = resp2.replace(/<style([\S\s]*?)>([\S\s]*?)<\/style>/igm,'');
//$('body').append('<div>aaaaaaaaaa <!--'+response2.responseText+'--></div');
//alert( JSON.stringify('<div>' + /<img[^>]*>/.exec(response2.responseText) + '</div>' ) );
//var poster_match = '<div>' + /<img[^P>]*Poster[^>]*>/igm.exec(response2.responseText) + '</div>'; // alert(poster_match);
var resp2 = $(response2.responseText.replace(/<img[^>]*>/igm,""));//.replace('="http:', '="httpX'));
//alert(title + ' (' + year + ')' + ':' + movie_imdb['imdbID'] + ':\n' + resp2);
//movie_imdb['Poster'] = resp2.find('div.media').first().find('img[itemprop="image"]').first().attr('data-src-x2');
//movie_imdb['Poster'] = $(poster_match).find('img.media-object[itemprop="image"]').first().attr('data-src-x2'); //alert(movie_imdb['Poster']);
movie_imdb['Poster'] = /data-src-x2="([^"]*)"/igm.exec(/<img[^P>]*Poster[^>]*>/igm.exec(response2.responseText)); if(movie_imdb['Poster']) movie_imdb['Poster'] = movie_imdb['Poster'][1]; //alert(movie_imdb['Poster']);
movie_imdb['Plot'] = resp2.find('p[itemprop="description"]').first().text().trim();
movie_imdb['Trailer'] = 'https://m.imdb.com' + resp2.find('a.video-link').first().attr('href');
movie_imdb['imdbRating'] = resp2.find('#ratings-bar').first().find('div').first().text() + ''; if(movie_imdb['imdbRating']) movie_imdb['imdbRating'] = movie_imdb['imdbRating'].trim();
movie_imdb['imdbVotes'] = /\/10([0-9,]+)/.exec(movie_imdb['imdbRating']); movie_imdb['imdbVotes'] = movie_imdb['imdbVotes'] ? (movie_imdb['imdbVotes'][1]) : ''; if(movie_imdb['imdbVotes'].length==0) movie_imdb['imdbVotes'] = 'N/A';
movie_imdb['imdbRating'] = /([0-9.]+)\/10/.exec(movie_imdb['imdbRating']); movie_imdb['imdbRating'] = movie_imdb['imdbRating'] ? (movie_imdb['imdbRating'][1]) : ''; if(movie_imdb['imdbRating'].length==1) movie_imdb['imdbRating'] = movie_imdb['imdbRating'] + '.0'; if(movie_imdb['imdbRating'].length==0) movie_imdb['imdbRating'] = 'N/A';
movie_imdb['Rated'] = resp2.find('p.infobar').first().find('meta[itemprop="contentRating"]').first().attr('content'); if(movie_imdb['Rated']) movie_imdb['Rated'] = movie_imdb['Rated'].trim(); else movie_imdb['Rated'] = 'N/A';
movie_imdb['Runtime'] = resp2.find('p.infobar').first().find('time[itemprop="duration"]').first().text() + ''; movie_imdb['Runtime'] = movie_imdb['Runtime'] ? (movie_imdb['Runtime'].trim()) : '';
tmp = [];
resp2.find('p.infobar').first().find('span[itemprop="genre"]').each(function(){ tmp = $.merge(tmp, [$(this).text().trim()]); });
movie_imdb['Genre'] = tmp.join(', ').trim();
tmp = [];
resp2.find('#awards').first().find('span[itemprop="awards"]').each(function(){ tmp = $.merge(tmp, [$(this).text().trim().replace('\n', ' ').replace("\n", ' ')]); });
movie_imdb['Awards'] = tmp.join(' ').trim();
tmp = [];
resp2.find('div#cast-and-crew').first().find('strong').slice(0,4).each(function(){ tmp = $.merge(tmp, [$(this).text().trim()]); });
movie_imdb['Actors'] = tmp.join(', ').trim();
//alert(JSON.stringify(movie_imdb));
movie_db[stor_title] = movie_imdb;
updateElement_dl(stor_title, dl_element);
localStorage.setItem('movie_db', JSON.stringify(movie_db));
},
onerror: function(e2){
//alert(e2);
$('#loading', dl_element).text(' Error2 ');
//alert('xxx request failed xxx: ' + JSON.stringify(e2) + ' : ' + url2);
console.warn('request failed: ' + url2);
}
});
}else{
$('#loading', dl_element).text(' NotFound ');
}
},
onerror: function(e1){
$('#loading', dl_element).text(' Error1 ');
//alert('xxx request failed xxx: ' + JSON.stringify(e1) + ' : ' + url);
console.warn('request failed: ' + url);
}
});
} else {
var url = 'http://www.omdbapi.com/?t=' + encodeURIComponent(title) + '&y=' + encodeURIComponent(year) + '&plot=full&r=json';
GM_xmlhttpRequest({
method: 'GET',
url: url,
onload: function(response) {
var data = JSON.parse(response.responseText);
if (data.Response === 'False') {
if((title+" ").indexOf("s ")-(title+" ").indexOf("'s ") > 1){
return getImdbInfo((title+" ").replace("s ", "'s "), year, dl_element);
}else{
movie_db[stor_title] = false;
updateElement_dl(stor_title, dl_element);
count++;
}
} else {
movie_db[stor_title] = data;
updateElement_dl(stor_title, dl_element);
return true;
}
//alert(title);
localStorage.setItem('movie_db', JSON.stringify(movie_db));
},
onerror: function(){
console.warn('request failed: ' + url);
}
});
}
//if (movie_db[stor_title]===false){
//$('#loading', dl_element).hide();
//return false;
//}
//else{
// return true;
//}
}
};
$(document).ready(function() {
$('dl').each(function() {
if ( ( this.innerHTML.toLowerCase().indexOf('xxx') + this.innerHTML.toLowerCase().indexOf('porn') ) > -1 ) {
//this.hide()
this.outerHTML = '';
} else {
var hash = /[a-zA-Z0-9]{40}/.exec( $('a', this).attr('href') );
//alert(hash);
//hash = hash1;
//hash = hash.substring(hash.length-40, 40);
if(hash){
var trackers = '';
var elem = '<div style="float:left; margin-left:1px; margin-top:-3px; opacity:0.3; font-size:50%; display: inline-block;">';
elem += '<a href="magnet:?xt=urn:'+hash+'" style="display: inline-block;background-color:#FFB090; width:10px; height:10px; margin:1px; text-align:center;">m</a> ';
elem += '<a href="http://torcache.net/torrent/'+hash+'.torrent" style="display: inline-block;background-color:#748DAB; width:10px; height:10px; margin:1px; text-align:center;">t1</a> ';
//elem += '<a href="http://torrage.com/torrent/'+hash+'.torrent" style="display: inline-block;background-color:#748DAB; width:10px; height:10px; margin:1px; text-align:center;">t1</a> ';
//elem += '<a href="https://zoink.it/torrent/'+hash+'.torrent" style="display: inline-block;background-color:#748DAB; width:10px; height:10px; margin:1px; text-align:center;">t1</a> ';
elem += '<a href="http://torrentproject.se/torrent/'+hash+'.torrent" style="display: inline-block;background-color:#748DAB; width:10px; height:10px; margin:1px; text-align:center;">m</a> ';
elem += '</div>';
//elem.appendTo($('dd', this));
$('dd', this).append(elem);
//$(this).append(elem);
//alert(hash);
}
}
});
});
start_button.find('#clear').click(function() {
localStorage.removeItem('movie_db');
});
start_button.find('#start').click(function() {
from_imdb = start_button.find('#from_imdb').is(':checked')
live = start_button.find('#live').is(':checked')
//$('body').find('iframe').hide();//.outerHTML='';
start_button.hide();
poster_img = $('<table style="position: fixed; width:475px; height:283px; background-color:white; border:2px solid black; border-collapse: collapse; border-spacing:0px; cell-spacing:0px;"><tr>' +
'<td><a href="" target="_blank" title="" id="imdb_a" style="display:flex;"><img width="200" height="283" border="0"></a></td>' +
'<td style="border:1px solid black;"><div style="text-align:left; padding:3px; font-size:10pt; font-family:Tahoma; height:277px; overflow:auto;">' +
' <div style="text-align:center; font-size:125%pt; font-weight:bold;"><span id="imdb_title">The Martian</span> (<span id="imdb_year">2015</span>)</div>' +
' <span id="imdb_trailer"><a href="" target="_new"><u>Trailer</u></a> <iframe src="" style="display:none;"></iframe> - </span>' +
' <u>Rating</u>: <span id="imdb_rating">8.1</span> - <span id="imdb_votes">275,300</span> votes' +
' <br /><u>Genre</u>: <span id="imdb_genre">Adventure, Comedy, Drama</span>' +
' <br /><u>Rated</u>: <span id="imdb_rated">PG-13</span>, <u>Runtime</u>: <span id="imdb_runtime">144 min</span>' +
' <br /><u>Awards</u>: <span id="imdb_awards"></span>' +
' <br /><u>Actors</u>: <span id="imdb_actors">Matt Damon, Jessica Chastain, Kristen Wiig, Jeff Daniels</span>' +
' <br /><u>Director</u>: <span id="imdb_director">Ridley Scott</span>' +
//' <br /><u>Writer</u>: <span id="imdb_writer">Drew Goddard (screenplay), Andy Weir (book)</span>' +
//' <br /><u>Country</u>: <span id="country">USA, UK</span>' +
' <br /><u>Plot</u>: <span id="imdb_plot">During a manned mission to Mars, Astronaut Mark Watney is presumed dead after a fierce storm and left behind by his crew. But Watney has survived and finds himself stranded and alone on the hostile planet. With only meager supplies, he must draw upon his ingenuity, wit and spirit to subsist and find a way to signal to Earth that he is alive.</span>' +
' </div></td>' +
'</tr></table>');
poster_img.on('mouseover', function(e){ poster_img.stop(true, true).show(); });
poster_img.on('mouseout', function(e){ poster_img.stop(true, true).fadeOut(2000); });
poster_img.hide();
poster_img.appendTo('body');
$('dl').each(function() {
var title = $('a', this).text();
title = title.replace('1080p', '');
title = title.replace('720p', '');
var year = '';
match = reM.exec(title);
if(match >= 1900){
year = match;
title = title.substr(0, title.search(reM)).trim();
}else{
match = reS.exec(title);
if(match){
year = '-';
title = title.substr(0, title.search(reS)).trim();
}
}
//alert(title+':'+year);
if (match){
if(match.length && count < 40) { // count increased by ajax call failures
getImdbInfo(title, year, this); // calls "updateElement_dl" from inside
} else if (match.length) {
title = title.substr(0, title.search(re));
var nel = '<a href="http://www.imdb.com/find?ref_=nv_sr_fn&q=' + title + '&s=all" target="_blank">??</a>';
$('dt', this).prepend(nel+ ' ');
}
} else {
//alert('aaa');
$('a', this).css('color','#777');
}
});
});
} catch (e) {
unsafeWindow.console.log(e);
}