Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save guilhermeprokisch/71cd9aa0585c26749eb384c510676d50 to your computer and use it in GitHub Desktop.
Save guilhermeprokisch/71cd9aa0585c26749eb384c510676d50 to your computer and use it in GitHub Desktop.
Play on Torrent
// ==UserScript==
// @name Play on Torrent
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://www.google.com*
// @grant GM_xmlhttpRequest
// @grant GM_addStyle
// @run-at document-end
//google
// @include *://google.*
// @include *://www.google.*
// @include *://encrypted.google.*
// @require http://code.jquery.com/jquery-3.4.1.min.js
// ==/UserScript==
let movieTorrents = [];
(function() {
movieTorrents = [];
function searchMovies(ImbdLink){
GM_xmlhttpRequest ({
method: 'GET',
url: ImbdLink,
onload: function (response) {
var IMDBpage = $.parseHTML(response.responseText);
const imdbTitle = $(".title_block .title_bar_wrapper .title_wrapper h1", IMDBpage).text();
const typeHtml = $(".heroic-overview .title_block .title_bar_wrapper a:link", IMDBpage).text();
const typeMatches = typeHtml.match(/(Series)/);
const imdbTitleText = imdbTitle.replace(/\([0-9]*\)/, "").trim();
const imdbID = ImbdLink.match(/(tt[0-9]{5,8})/)[0]
var imdbInfo = {
Id: imdbID,
Title: imdbTitleText,
Type: typeMatches && typeMatches.length > 0 ? "series" : "movie",
}
// check which type of call we have to do
let htmlOutput = "";
switch (imdbInfo.Type) {
case "movie":
// this page contains a movie
htmlOutput = GM_xmlhttpRequest({
method: 'GET',
url: "https://tv-v2.api-fetch.sh/movie/" + imdbInfo.Id,
onload: function(response){
var result = JSON.parse(response.responseText);
//console.log(Object.keys(result.torrents))
// require atleast one result
if (!result) return "No download results";
// check if we got enough results
if (Object.keys(result.torrents).length > 0) {
// prefer en language but fallback to the first key in the list
const lang = result.torrents.en ? "en" : Object.keys(result.torrents).shift();
// get torrent list
const torrents = result.torrents[lang];
// loop through available torrents
Object.keys(torrents).map((quality) => {
// get torrent info
const torrent = torrents[quality];
// create a list
movieTorrents.push({
peers: torrent.peer,
seeds: torrent.seed,
quality: quality,
size: torrent.filesize,
size_bytes: torrent.size,
magnet_url: torrent.url,
});
});
};
var youtubeSection = $("span:contains('Play trailer on YouTube')").parent().parent();
var torrentSection = youtubeSection.clone()
torrentSection.find("a").attr("href", movieTorrents[0].magnet_url)
torrentSection.find("span.ellip").text("Play on Torrent")
torrentSection.find("svg").attr("style", "fill: green")
torrentSection.appendTo(youtubeSection.parent())
console.log(movieTorrents)
}
})
break;
case "series":
// this page contains a series
//htmlOutput = await getSeries();
}
console.log(imdbInfo)
}
});
};
var ImbdLink = $('span[title="IMDb"]').parent().attr('href');
searchMovies(ImbdLink);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment