Skip to content

Instantly share code, notes, and snippets.

@redlotus
Last active August 29, 2015 14:23
Show Gist options
  • Save redlotus/da21b83306390a68805a to your computer and use it in GitHub Desktop.
Save redlotus/da21b83306390a68805a to your computer and use it in GitHub Desktop.
get subtitles from subscene.com
javascript: (function() { var subs = []; var base = "http://subscene.com"; var find = "http://subscene.com/subtitles/title?q="; var langs = ['vietnamese', 'english']; var url; var rq = prompt("input: ", "name"); var xhr = new XMLHttpRequest(); var parser = new DOMParser(); xhr.open("GET", find + rq.split(" ").join("+") + "&l=", false); xhr.send(); var rPage = parser.parseFromString(xhr.response, "text/html"); var result = (rPage.getElementsByClassName("search-result")[0]).getElementsByTagName("h2")[0].innerHTML; if (result == "No results found") { return "no results"; } else { var lsFilm = (rPage.getElementsByClassName("search-result")[0]).getElementsByTagName("li"); var lsFilm_2 = []; for (var f = 0; f < lsFilm.length; f++) { lsFilm_2[f] = f + ". " + lsFilm[f].getElementsByTagName("a")[0].innerHTML; } alert(lsFilm_2.join("\n")); var choice = prompt("your choice: ", "0"); if (parseInt(choice) < lsFilm.length) { url = lsFilm[parseInt(choice)].getElementsByTagName("a")[0].getAttribute("href"); } } var dlsub = prompt("download option (0: vn, 1: en, 2: all, 3: no): ", "0"); switch (parseInt(dlsub)) { case 0: xhr.open("GET", base + url + "/vietnamese", false); xhr.send(); var lsPages = parser.parseFromString(xhr.response, "text/html"); var lsSubs = ((lsPages.getElementsByTagName("table")[0]).getElementsByTagName("tbody")[0]).getElementsByTagName("tr"); for (var j = 1; j < lsSubs.length; j++) { var sub = (lsSubs[j].getElementsByTagName("td")[0]).getElementsByTagName("a")[0].getAttribute("href"); var sname = (((lsSubs[j].getElementsByTagName("td")[0]).getElementsByTagName("a")[0]).getElementsByTagName("span")[1].innerHTML).trim(); if (sname) { var sowner = ((lsSubs[j].getElementsByTagName("td")[3]).getElementsByTagName("a")[0].innerHTML).trim(); xhr = new XMLHttpRequest(); xhr.open("GET", base + sub, false); xhr.send(); var dl = parser.parseFromString(xhr.response, "text/html"); subs.push({ name: sname, owner: sowner, language: langs[i], link: base + dl.getElementById("downloadButton").getAttribute("href") }); } } break; case 1: xhr.open("GET", base + url + "/english", false); xhr.send(); var lsPages = parser.parseFromString(xhr.response, "text/html"); var lsSubs = ((lsPages.getElementsByTagName("table")[0]).getElementsByTagName("tbody")[0]).getElementsByTagName("tr"); for (var j = 1; j < lsSubs.length; j++) { var sub = (lsSubs[j].getElementsByTagName("td")[0]).getElementsByTagName("a")[0].getAttribute("href"); var sname = (((lsSubs[j].getElementsByTagName("td")[0]).getElementsByTagName("a")[0]).getElementsByTagName("span")[1].innerHTML).trim(); if (sname) { var sowner = ((lsSubs[j].getElementsByTagName("td")[3]).getElementsByTagName("a")[0].innerHTML).trim(); xhr = new XMLHttpRequest(); xhr.open("GET", base + sub, false); xhr.send(); var dl = parser.parseFromString(xhr.response, "text/html"); subs.push({ name: sname, owner: sowner, language: langs[i], link: base + dl.getElementById("downloadButton").getAttribute("href") }); } } break; case 2: for (var i = 0; i < 2; i++) { xhr.open("GET", base + url + "/" + langs[i], false); xhr.send(); var lsPages = parser.parseFromString(xhr.response, "text/html"); var lsSubs = ((lsPages.getElementsByTagName("table")[0]).getElementsByTagName("tbody")[0]).getElementsByTagName("tr"); for (var j = 1; j < lsSubs.length; j++) { var sub = (lsSubs[j].getElementsByTagName("td")[0]).getElementsByTagName("a")[0].getAttribute("href"); var sname = (((lsSubs[j].getElementsByTagName("td")[0]).getElementsByTagName("a")[0]).getElementsByTagName("span")[1].innerHTML).trim(); if (sname) { var sowner = ((lsSubs[j].getElementsByTagName("td")[3]).getElementsByTagName("a")[0].innerHTML).trim(); xhr = new XMLHttpRequest(); xhr.open("GET", base + sub, false); xhr.send(); var dl = parser.parseFromString(xhr.response, "text/html"); subs.push({ name: sname, owner: sowner, language: langs[i], link: base + dl.getElementById("downloadButton").getAttribute("href") }); } } } break; default: break; } return JSON.stringify(subs); })();
var v = "2.0.0"; // the minimum version of jQuery we want
if (window.jQuery === undefined || window.jQuery.fn.jquery < v) {
var done = false;
var script = document.createElement("script");
script.src = "http://ajax.googleapis.com/ajax/libs/jquery/" + v + "/jquery.min.js";
document.getElementsByTagName("head")[0].appendChild(script);
}
(function() {
var subs = [];
var base = "http://subscene.com";
var find = "http://subscene.com/subtitles/title?q=";
var langs = ['vietnamese', 'english'];
var url = "";
var flag = 0; // script terminal
var subDeferreds = [];
function notiDl() {
//var deferred = $.Deferred();
//deferred.resolve();
//return deferred;
return JSON.stringify(subs);
}
function getFilmUrl(data) {
var rPage = $.parseHTML(data);
var result = $($(rPage).find(".search-result").get(0)).find("h2").get(0);
if (result == "No results found") {
return "no results";
} else {
var lsFilm = $($(rPage).find(".search-result").get(0)).find("li");
var lsFilm_2 = [];
for (var f = 0; f < lsFilm.length; f++) {
lsFilm_2[f] = f + ". " + $($($(lsFilm).get(f)).find("a").get(0)).html();
// console.log(lsFilm_2[f]);
}
alert(lsFilm_2.join("\n"));
var choice = prompt("your choice: ", "0");
url = $($($(lsFilm).get(parseInt(choice))).find("a").get(0)).attr("href");
}
return url;
}
function getSub(url) {
var sxhr = $.ajax(url)
.done(function(data) {
var lsPages = $.parseHTML(data);
var lsSubs = $($($(lsPages).find("table").get(0)).find("tbody").get(0)).find("tr");
for (var j = 1; j < lsSubs.length; j++) {
var sub = $($($($(lsSubs).get(j)).find("td").get(0)).find("a").get(0)).attr("href");
var sname = $($($($($(lsSubs).get(j)).find("td").get(0)).find("a").get(0)).find("span").get(1)).html().trim();
if (sname) {
var sowner = $($($($(lsSubs).get(j)).find("td").get(3)).find("a").get(0)).html().trim();
var lxhr = $.ajax(base + sub)
.done(function(data) {
var dl = $.parseHTML(data);
var link = $($(dl).find("#downloadButton")).attr("href");
subs.push({
link: base + link
});
});
subDeferreds.push(lxhr);
}
}
$.when.apply($, subDeferreds).done(function() {
flag = 1;
notiDl();
});
})
.fail(function(data) {
alert("error");
})
.always(function() {});
}
var rq = prompt("input: ", "name");
var xhr = $.ajax(find + rq.split(" ").join("+") + "&l=")
.done(function(data) {
var filmUrl = getFilmUrl(data);
if (filmUrl !== 'no results') {
var dlsub = prompt("download option (0: vn, 1: en, 2: no): ", "0");
switch (parseInt(dlsub)) {
case 0:
getSub(base + filmUrl + "/vietnamese");
break;
case 1:
getSub(base + filmUrl + "/english");
break;
default:
break;
}
}
})
.fail(function() {
alert("error");
})
.always(function() {});
//notiDl().done(function () {
// alert('yolo');
//});
// return subs;
})();
javascript: (function() {
var subs = [];
var base = "http://subscene.com";
var find = "http://subscene.com/subtitles/title?q=";
var langs = ['vietnamese', 'english'];
var url;
var rq = prompt("input: ", "name");
var xhr = new XMLHttpRequest();
var parser = new DOMParser();
xhr.open("GET", find + rq.split(" ").join("+") + "&l=", false);
xhr.send();
var rPage = parser.parseFromString(xhr.response, "text/html");
var result = (rPage.getElementsByClassName("search-result")[0]).getElementsByTagName("h2")[0].innerHTML;
if (result == "No results found") {
return "no results";
} else {
var lsFilm = (rPage.getElementsByClassName("search-result")[0]).getElementsByTagName("li");
var lsFilm_2 = [];
for (var f = 0; f < lsFilm.length; f++) {
lsFilm_2[f] = f + ". " + lsFilm[f].getElementsByTagName("a")[0].innerHTML;
}
alert(lsFilm_2.join("\n"));
var choice = prompt("your choice: ", "0");
if (parseInt(choice) < lsFilm.length) {
url = lsFilm[parseInt(choice)].getElementsByTagName("a")[0].getAttribute("href");
}
}
var dlsub = prompt("download option (0: vn, 1: en, 2: all, 3: no): ", "0");
switch (parseInt(dlsub)) {
case 0:
xhr.open("GET", base + url + "/vietnamese", false);
xhr.send();
var lsPages = parser.parseFromString(xhr.response, "text/html");
var lsSubs = ((lsPages.getElementsByTagName("table")[0]).getElementsByTagName("tbody")[0]).getElementsByTagName("tr");
for (var j = 1; j < lsSubs.length; j++) {
var sub = (lsSubs[j].getElementsByTagName("td")[0]).getElementsByTagName("a")[0].getAttribute("href");
var sname = (((lsSubs[j].getElementsByTagName("td")[0]).getElementsByTagName("a")[0]).getElementsByTagName("span")[1].innerHTML).trim();
if (sname) {
var sowner = ((lsSubs[j].getElementsByTagName("td")[3]).getElementsByTagName("a")[0].innerHTML).trim();
xhr = new XMLHttpRequest();
xhr.open("GET", base + sub, false);
xhr.send();
var dl = parser.parseFromString(xhr.response, "text/html");
subs.push({
name: sname,
owner: sowner,
language: langs[i],
link: base + dl.getElementById("downloadButton").getAttribute("href")
});
}
}
break;
case 1:
xhr.open("GET", base + url + "/english", false);
xhr.send();
var lsPages = parser.parseFromString(xhr.response, "text/html");
var lsSubs = ((lsPages.getElementsByTagName("table")[0]).getElementsByTagName("tbody")[0]).getElementsByTagName("tr");
for (var j = 1; j < lsSubs.length; j++) {
var sub = (lsSubs[j].getElementsByTagName("td")[0]).getElementsByTagName("a")[0].getAttribute("href");
var sname = (((lsSubs[j].getElementsByTagName("td")[0]).getElementsByTagName("a")[0]).getElementsByTagName("span")[1].innerHTML).trim();
if (sname) {
var sowner = ((lsSubs[j].getElementsByTagName("td")[3]).getElementsByTagName("a")[0].innerHTML).trim();
xhr = new XMLHttpRequest();
xhr.open("GET", base + sub, false);
xhr.send();
var dl = parser.parseFromString(xhr.response, "text/html");
subs.push({
name: sname,
owner: sowner,
language: langs[i],
link: base + dl.getElementById("downloadButton").getAttribute("href")
});
}
}
break;
case 2:
for (var i = 0; i < 2; i++) {
xhr.open("GET", base + url + "/" + langs[i], false);
xhr.send();
var lsPages = parser.parseFromString(xhr.response, "text/html");
var lsSubs = ((lsPages.getElementsByTagName("table")[0]).getElementsByTagName("tbody")[0]).getElementsByTagName("tr");
for (var j = 1; j < lsSubs.length; j++) {
var sub = (lsSubs[j].getElementsByTagName("td")[0]).getElementsByTagName("a")[0].getAttribute("href");
var sname = (((lsSubs[j].getElementsByTagName("td")[0]).getElementsByTagName("a")[0]).getElementsByTagName("span")[1].innerHTML).trim();
if (sname) {
var sowner = ((lsSubs[j].getElementsByTagName("td")[3]).getElementsByTagName("a")[0].innerHTML).trim();
xhr = new XMLHttpRequest();
xhr.open("GET", base + sub, false);
xhr.send();
var dl = parser.parseFromString(xhr.response, "text/html");
subs.push({
name: sname,
owner: sowner,
language: langs[i],
link: base + dl.getElementById("downloadButton").getAttribute("href")
});
}
}
}
break;
default:
break;
}
return JSON.stringify(subs);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment