Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- exports.url = "http://www.movie4k.tv/";
- exports.req = require("request");
- exports.cheerio = require("cheerio");
- exports.parse = require("url");
- var fs = require("fs");
- exports.name = "movie4k";
- exports.hasSleep = true;
- exports.scrapping = true;
- exports.getHostName = function($url) {
- console.log($url);
- var _h = this.parse.parse($url);
- __h = _h.hostname.split('.');
- var _l = __h.length;
- if (_l < 3) {
- return __h[0];
- }
- return __h[1];
- }
- exports.counter = 0;
- exports.resetCounter = function() {
- this.counter = 0;
- }
- exports.increment = function() {
- this.counter++;
- }
- exports.allowedHosterMovie = function(h) {
- var _hoster = {
- "filenuke": 174,
- "wholecloud": 176,
- "nowvideo": 186,
- "vid": 234,
- "sharesix": 199,
- "streamcloud": 178,
- "bitvid": 182,
- "openload":235,
- "vidzi": 233,
- "streamin": 240
- };
- if (typeof _hoster[h] == "undefined") {
- return false;
- }
- return _hoster[h];
- };
- exports.allowedHosterSeries = function(h) {
- var _hoster = {
- "filenuke": 174,
- "wholecloud": 176,
- "nowvideo": 186,
- "vid": 234,
- "sharesix": 199,
- "streamcloud": 178,
- "bitvid": 182,
- "vidzi": 233
- };
- console.log( _hoster[h] );
- if (typeof _hoster[h] == "undefined") {
- return false;
- }
- return _hoster[h];
- };
- exports.setDefault = function() {
- var that = this;
- this.cJ = this.req.jar();
- this.req = this.req.defaults({
- jar: true,
- headers: {
- "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
- "Accept-Encoding": "gzip,deflate,sdch",
- "Accept-Language": "de-DE,de;q=0.8,en-US;q=0.6,en;q=0.4,nl;q=0.2",
- "Cache-Control": "max-age=0",
- "Connection": "keep-alive",
- "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36"
- },
- gzip: true,
- followRedirect: true,
- followAllRedirects: true
- });
- };
- exports.setCredentials = function($user, $pass) {
- this.userName = $user;
- this.password = $pass;
- }
- exports.loggedIn = false;
- exports.login = function(obj, movieCallback) {
- this.setDefault();
- var that = this;
- if (this.loggedIn) {
- return this.sendTo(obj, movieCallback);
- }
- this.req.get({
- url: this.url
- }, function(a, b, c) {
- that.req(that.url + "login.php", function(a, b, c) {
- var _form = {
- username: that.userName,
- password: that.password,
- };
- console.log(_form);
- that.req.post({
- url: that.url + "login.php?ua=login",
- form: _form,
- jar: true,
- followRedirect: true,
- headers: {
- "referrer" : "http://movie4k.tv/login.php",
- }
- }, function(a, b, c) {
- that.loggedIn = true;
- return that.sendTo(obj, movieCallback);
- });
- });
- });
- };
- exports.scrap = function(rlsName, callback) {
- this.setDefault();
- var that = this;
- if (this.loggedIn) {
- return that.myFiles(rlsName, callback);
- }
- this.req.get({
- url: this.url
- }, function(a, b, c) {
- that.req(that.url + "login.php", function(a, b, c) {
- that.req.post({
- url: that.url + "login.php?ua=login",
- form: {
- username: that.userName,
- password: that.password,
- },
- jar: true,
- followRedirect: true
- }, function(a, b, c) {
- that.loggedIn = true;
- return that.myFiles(rlsName, callback);
- });
- });
- });
- };
- exports.myFiles = function(rlsName, callback){
- console.log("WE WANT SCRAPPING");
- var _title = rlsName.title;
- if(rlsName.isSeries) {
- if(rlsName.episode < 10)
- rlsName.episode = "0"+rlsName.episode;
- if(rlsName.season < 10)
- rlsName.season = "0"+rlsName.season;
- _title = rlsName.title+" S"+rlsName.season+"E"+rlsName.episode;
- }
- this.setDefault();
- var self = this;
- var returnObj = [];
- this.req(self.url +"ui.php?ua=myuploads", function(a,b,c){
- var $ = self.cheerio.load(c);
- $('div#maincontent4 table tr').each(function(){
- var firstRow = ($(this).children().first().text());
- if(firstRow == _title) {
- var hoster = $(this).children().eq(1).text().trim().toLowerCase().replace("movshare","wholecloud").replace("videoweed", "bitvid");
- var delUrl = ($(this).children().last().children("a").attr("href"));
- try {
- var id = delUrl.match(/edit\=(.*)/)[1];
- returnObj.push([hoster.split(".")[0]+"|"+id]);
- } catch(e) {
- console.log("OFF FILE");
- }
- }
- });
- console.log(returnObj);
- return callback(returnObj);
- });
- }
- exports.sendTo = function(obj, movieCallback) {
- if (obj.mainData.isSeries) {
- this.postSeries(obj, movieCallback);
- } else {
- this.postMovie(obj, movieCallback);
- }
- }
- exports.postSeries = function(obj, movieCallback) {
- var data = obj.mainData;
- var link = obj.chunk[obj.currentPos];
- var linkLength = link.length;
- var __HOSTER = [];
- var __LINK = [];
- var that = this;
- for ($i = 0; $i < linkLength; $i++) {
- var LINK = this.getHostName(link[$i]);
- var allowed = this.allowedHosterMovie(LINK);
- if (allowed) {
- __HOSTER.push(allowed);
- if (link[$i].indexOf("https://openload.co") > -1) {
- var _url = link[$i].split("/");
- delete _url[_url.length - 1];
- var _url = _url.join("/");
- link[$i] = (_url.substr(0, _url.length - 1))
- }
- __LINK.push(link[$i].replace("nowvideo.sx", "nowvideo.tv"));
- }
- }
- var postObj = {
- title: data.title,
- soundquality: data.soundQuality,
- picturequality: data.quality,
- imdb_id: data.imdb,
- hoster: __HOSTER,
- link: __LINK,
- episode: data.episode,
- season: data.season
- };
- this.req(this.url + "ui.php?ua=tvshow", function(a, b, c) {
- if(b.req.path.indexOf("ui.php?ua=tvshow")) {
- console.log("SIND EINGELOGGT");
- } else {
- console.log("SIND NICHT EINGELOGGT");
- that.loggedIn = false;
- return that.login(obj, movieCallback);
- }
- that.req.post({
- url: that.url + "ui.php?ua=tvshow&do=add",
- formData: generatePostHosterSERIES(postObj)
- }, function(a, b, c) {
- var $ = require("cheerio").load( c );
- console.log($("#maincontent4 strong").html());
- return movieCallback(obj);
- });
- });
- }
- exports.postMovie = function(obj, movieCallback) {
- var data = obj.mainData;
- var link = obj.chunk[obj.currentPos];
- var linkLength = link.length;
- var __HOSTER = [];
- var __LINK = [];
- var that = this;
- for ($i = 0; $i < linkLength; $i++) {
- if(link[$i] != null) {
- var LINK = this.getHostName(link[$i]);
- var allowed = this.allowedHosterMovie(LINK);
- if (allowed) {
- __HOSTER.push(allowed);
- if (link[$i].indexOf("https://openload.co") > -1) {
- var _url = link[$i].split("/");
- delete _url[_url.length - 1];
- var _url = _url.join("/");
- link[$i] = (_url.substr(0, _url.length - 1))
- }
- __LINK.push(link[$i].replace("nowvideo.sx", "nowvideo.tv"));
- }
- }
- }
- if(__LINK.length <= 0) {
- return movieCallback(obj);
- }
- var postObj = {
- title: data.title,
- soundquality: data.soundQuality,
- picturequality: data.quality,
- imdb_id: data.imdb,
- hoster: __HOSTER,
- link: __LINK
- };
- this.req(this.url + "ui.php?ua=movie", function(a, b, c) {
- if(b.req.path.indexOf("ui.php?ua=movie")) {
- console.log("SIND EINGELOGGT");
- } else {
- console.log("SIND NICHT EINGELOGGT");
- that.loggedIn = false;
- return that.login(obj, movieCallback);
- }
- that.req.post({
- url: that.url + "ui.php?ua=movie&do=add",
- form: generatePostHosterMOVIE(postObj)
- }, function(a, b, c) {
- console.log(a);
- console.log(b.statusCode);
- var $ = that.cheerio.load(c);
- var txt = ($("#maincontent4 strong").text());
- console.log(txt + " " + postObj.title);
- if(txt.length <= 0) {
- that.loggedIn = false;
- return that.login(obj, movieCallback);
- }
- // var $ = that.cheerio.load( c );
- // $log = ( $('#maincontent4 strong').text() );
- return movieCallback(obj);
- /* if($log.length <= 0) {
- console.log("NO RESPONSE");
- return that.postMovie(data,link, callback, currentReq, maxReq, _doneCB);
- }
- console.log("angekommen "+ currentReq+" / "+maxReq);
- /* that.increment();
- callback(that.name+" => "+$log);
- if(that.counter == maxReq) {
- that.resetCounter();
- return _doneCB("movie4k");
- }
- */
- });
- });
- };
- exports.sleep = function(sec) {
- var milliseconds = sec * 1000;
- var start = new Date().getTime();
- while (true) {
- if ((new Date().getTime() - start) > milliseconds) {
- break;
- }
- }
- }
- function generatePostHosterMOVIE(obj) {
- var _ = {};
- _['title'] = obj.title;
- _['language'] = "2";
- _['picturequality'] = obj.picturequality;
- _['soundquality'] = obj.soundquality;
- _['imdbuser'] = "http://www.imdb.com/title/" + obj.imdb_id;
- _['genre1'] = "";
- _['genre2'] = "";
- _['genre3'] = "";
- _['genre4'] = "";
- _['genre5'] = "";
- _['genre1'] = "";
- _['genre2'] = "";
- _['genre3'] = "";
- _['genre4'] = "";
- _['genre5'] = "";
- _['thumbnail'] = "upload";
- _['thumbnaillink'] = "";
- _['description'] = "";
- _['duration'] = "";
- _['fsk'] = "";
- _['countryyear'] = "";
- _['director'] = "";
- _['actors'] = "";
- _['hoster'] = obj.hoster[0] || "";
- _['part[1]'] = obj.link[0] || "";
- _['part[2]'] = "";
- _['part[3]'] = "";
- for ($i = 0; $i <= 10; $i++) {
- _['hoster2[' + $i + ']'] = obj.hoster[$i + 1] || "";
- for (i = 0; i < 3; i++) {
- _LINK = obj.link[$i + 1] || "";
- _['part2[' + $i + '][' + i + ']'] = (i == 0) ? _LINK : "";
- }
- }
- for ($x = 1; $x < 10; $x++) {
- _['detail[' + $x + ']'] = "";
- _['detailtext[' + $x + ']'] = "";
- }
- return _;
- }
- function generatePostHosterSERIES(obj) {
- var _ = {};
- _['title'] = obj.title;
- _['language'] = "2";
- _['season'] = obj.season;
- _['episode[1]'] = obj.episode;
- _['imdbuser'] = "http://www.imdb.com/title/" + obj.imdb_id;
- _['genre1'] = "";
- _['genre2'] = "";
- _['genre3'] = "";
- _['genre4'] = "";
- _['genre5'] = "";
- _['thumbnail'] = "upload";
- _['thumbnailfile'] = "",
- _['thumbnaillink'] = "";
- _['description'] = "";
- _['duration'] = "";
- _['fsk'] = "";
- _['countryyear'] = "";
- _['director'] = "";
- _['actors'] = "";
- for ($i = 0; $i < 10; $i++) {
- _['hoster2[' + $i + ']'] = obj.hoster[$i] || "";
- _LINK = obj.link[$i] || "";
- _['link2[' + $i + ']'] = _LINK ;
- }
- for ($x = 1; $x < 10; $x++) {
- _['detail[' + $x + ']'] = "";
- _['detailtext[' + $x + ']'] = "";
- }
- return _;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement