// ==UserScript==
// @name TorrentZ [load IMDB info]
// @namespace
// @version 1.03
// @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
// @downloadURL none
// ==/UserScript==
// regext for cleaning the titles
var reM = /[0-9]{4}/i;
var reS = /S[0-9]{2}E[0-9]{2}|[0-9]{1}x[0-9]{2}/i;
var from_imdb = false;
var live = false;
movie_db = {};
movie_loading = {};
try {
var c = localStorage.getItem('movie_db');
if (c) {
$.extend(movie_db, JSON.parse(c));
}
var count = 0;
start_button = $('
');
//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){
var dl_element = '.'+stor_title;
if (movie_db[stor_title]==false) {
$('a', dl_element).css('color','#777');
return true;
}
//alert(stor_title);
var awards_text = $(''+movie_db[stor_title].Awards+'').text(); //awards_text = awards_text ? awards_text : 'N/A';
var el_title = movie_db[stor_title].imdbVotes + ' votes - ' + movie_db[stor_title].Runtime + ' - Rated ' + $(''+movie_db[stor_title].Rated+'').text() + ' - Awards: ' + awards_text;
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(awards_text.toLowerCase()); if(wins) wins = parseFloat(wins[1]);
var noms = reg_noms.exec(awards_text.toLowerCase()); if(noms) noms = parseFloat(noms[1]);
var wins_sig = reg_wins_sig.exec(awards_text.toLowerCase()); if(wins_sig) wins_sig = parseFloat(wins_sig[1]);
var noms_sig = reg_noms_sig.exec(awards_text.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 = '★';
}else if(wins >= 10 || (noms_sig >= 1 && noms >= 5)){
star = '★';
}else if(wins >= 5 || noms >= 10 || noms_sig >= 1){
star = '★';
}else if(wins + noms >= 1){
star = '☆';
}
var el = '' + movie_db[stor_title].imdbRating + star + '';
//$('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(' ('+movie_db[stor_title].Genre + ')');
$(dl_element).each(function(){
$(this).find('a').first().on('mouseover', function(e){
poster_img.find('img').attr('src', 'http://ia.media-imdb.com/images/G/01/imdb/images/nopicture/large/film-184890147._CB379391879_.png');
if (movie_db[stor_title].Poster){
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 ', '
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) {
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=600, height=338'); 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.clientX+20,//
top: $(window).height()/2 - poster_img.height()/2 //e.clientY//
});
//poster_img.attr('stor_title','Actors: ' + movie_db[stor_title].Actors + ' - Director: ' + movie_db[stor_title].Director)
poster_img.stop(true, true).show();
});
$(this).find('a').first().on('mouseout', function(e){
poster_img.stop(true, true).fadeOut(2000);
//poster_img.find('img').attr('src', '');
});
});
//$('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 = ''+el+''; }
$('dt', dl_element).prepend(el+ ' ');
if(rating <= 5.0 || votes <= 1000){
$(dl_element).each(function(){$(this).find('dt').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"){
$(dl_element).each(function(){$(this).find('dt').css({opacity: 0.15})});
}
$(dl_element).each(function(){$(this).find('#loading').hide()});
};
var getImdbInfo = function(title, year) {
var stor_title = classFromTitle( title + '_' + year + '_' + from_imdb );
var dl_element = $('.'+stor_title);
//alert($('.'+stor_title).length);
//$(' (Loading) ').insertBefore($('a', dl_element).first());
$(dl_element).each(function(){ $(' (Loading) ').insertBefore($(this).find('a').first()); });
//alert("\""+title + "\""+year);
//alert(url);
if ( !live && stor_title in movie_db && movie_db[stor_title]!==false ) {
updateElement_dl(stor_title);
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(/