Advertisement
Guest User

Untitled

a guest
May 19th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.06 KB | None | 0 0
  1. exports.url = "http://www.movie4k.tv/";
  2. exports.req = require("request");
  3. exports.cheerio = require("cheerio");
  4. exports.parse = require("url");
  5. var fs = require("fs");
  6. exports.name = "movie4k";
  7. exports.hasSleep = true;
  8. exports.scrapping = true;
  9. exports.getHostName = function($url) {
  10. console.log($url);
  11. var _h = this.parse.parse($url);
  12. __h = _h.hostname.split('.');
  13. var _l = __h.length;
  14.  
  15. if (_l < 3) {
  16. return __h[0];
  17. }
  18. return __h[1];
  19. }
  20.  
  21. exports.counter = 0;
  22. exports.resetCounter = function() {
  23. this.counter = 0;
  24. }
  25. exports.increment = function() {
  26. this.counter++;
  27. }
  28.  
  29. exports.allowedHosterMovie = function(h) {
  30. var _hoster = {
  31. "filenuke": 174,
  32. "wholecloud": 176,
  33. "nowvideo": 186,
  34. "vid": 234,
  35. "sharesix": 199,
  36. "streamcloud": 178,
  37. "bitvid": 182,
  38. "openload":235,
  39. "vidzi": 233,
  40. "streamin": 240
  41. };
  42. if (typeof _hoster[h] == "undefined") {
  43. return false;
  44. }
  45. return _hoster[h];
  46. };
  47. exports.allowedHosterSeries = function(h) {
  48. var _hoster = {
  49. "filenuke": 174,
  50. "wholecloud": 176,
  51. "nowvideo": 186,
  52. "vid": 234,
  53. "sharesix": 199,
  54. "streamcloud": 178,
  55. "bitvid": 182,
  56. "vidzi": 233
  57. };
  58. console.log( _hoster[h] );
  59.  
  60. if (typeof _hoster[h] == "undefined") {
  61. return false;
  62. }
  63. return _hoster[h];
  64. };
  65. exports.setDefault = function() {
  66. var that = this;
  67. this.cJ = this.req.jar();
  68.  
  69. this.req = this.req.defaults({
  70. jar: true,
  71. headers: {
  72. "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
  73. "Accept-Encoding": "gzip,deflate,sdch",
  74. "Accept-Language": "de-DE,de;q=0.8,en-US;q=0.6,en;q=0.4,nl;q=0.2",
  75. "Cache-Control": "max-age=0",
  76. "Connection": "keep-alive",
  77. "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"
  78. },
  79. gzip: true,
  80. followRedirect: true,
  81. followAllRedirects: true
  82. });
  83. };
  84. exports.setCredentials = function($user, $pass) {
  85. this.userName = $user;
  86. this.password = $pass;
  87. }
  88. exports.loggedIn = false;
  89.  
  90. exports.login = function(obj, movieCallback) {
  91. this.setDefault();
  92. var that = this;
  93. if (this.loggedIn) {
  94. return this.sendTo(obj, movieCallback);
  95. }
  96. this.req.get({
  97. url: this.url
  98. }, function(a, b, c) {
  99. that.req(that.url + "login.php", function(a, b, c) {
  100. var _form = {
  101. username: that.userName,
  102. password: that.password,
  103. };
  104. console.log(_form);
  105. that.req.post({
  106. url: that.url + "login.php?ua=login",
  107. form: _form,
  108. jar: true,
  109. followRedirect: true,
  110. headers: {
  111. "referrer" : "http://movie4k.tv/login.php",
  112. }
  113. }, function(a, b, c) {
  114. that.loggedIn = true;
  115. return that.sendTo(obj, movieCallback);
  116. });
  117. });
  118.  
  119. });
  120. };
  121. exports.scrap = function(rlsName, callback) {
  122. this.setDefault();
  123. var that = this;
  124. if (this.loggedIn) {
  125. return that.myFiles(rlsName, callback);
  126. }
  127. this.req.get({
  128. url: this.url
  129. }, function(a, b, c) {
  130. that.req(that.url + "login.php", function(a, b, c) {
  131. that.req.post({
  132. url: that.url + "login.php?ua=login",
  133. form: {
  134. username: that.userName,
  135. password: that.password,
  136. },
  137. jar: true,
  138. followRedirect: true
  139. }, function(a, b, c) {
  140. that.loggedIn = true;
  141. return that.myFiles(rlsName, callback);
  142. });
  143. });
  144.  
  145. });
  146. };
  147. exports.myFiles = function(rlsName, callback){
  148. console.log("WE WANT SCRAPPING");
  149. var _title = rlsName.title;
  150. if(rlsName.isSeries) {
  151. if(rlsName.episode < 10)
  152. rlsName.episode = "0"+rlsName.episode;
  153.  
  154. if(rlsName.season < 10)
  155. rlsName.season = "0"+rlsName.season;
  156.  
  157. _title = rlsName.title+" S"+rlsName.season+"E"+rlsName.episode;
  158. }
  159. this.setDefault();
  160. var self = this;
  161. var returnObj = [];
  162. this.req(self.url +"ui.php?ua=myuploads", function(a,b,c){
  163. var $ = self.cheerio.load(c);
  164.  
  165. $('div#maincontent4 table tr').each(function(){
  166. var firstRow = ($(this).children().first().text());
  167. if(firstRow == _title) {
  168. var hoster = $(this).children().eq(1).text().trim().toLowerCase().replace("movshare","wholecloud").replace("videoweed", "bitvid");
  169. var delUrl = ($(this).children().last().children("a").attr("href"));
  170. try {
  171. var id = delUrl.match(/edit\=(.*)/)[1];
  172. returnObj.push([hoster.split(".")[0]+"|"+id]);
  173. } catch(e) {
  174. console.log("OFF FILE");
  175. }
  176. }
  177. });
  178.  
  179. console.log(returnObj);
  180. return callback(returnObj);
  181.  
  182. });
  183. }
  184. exports.sendTo = function(obj, movieCallback) {
  185. if (obj.mainData.isSeries) {
  186. this.postSeries(obj, movieCallback);
  187. } else {
  188. this.postMovie(obj, movieCallback);
  189. }
  190. }
  191.  
  192. exports.postSeries = function(obj, movieCallback) {
  193. var data = obj.mainData;
  194. var link = obj.chunk[obj.currentPos];
  195. var linkLength = link.length;
  196. var __HOSTER = [];
  197. var __LINK = [];
  198. var that = this;
  199.  
  200. for ($i = 0; $i < linkLength; $i++) {
  201. var LINK = this.getHostName(link[$i]);
  202. var allowed = this.allowedHosterMovie(LINK);
  203. if (allowed) {
  204. __HOSTER.push(allowed);
  205. if (link[$i].indexOf("https://openload.co") > -1) {
  206. var _url = link[$i].split("/");
  207. delete _url[_url.length - 1];
  208. var _url = _url.join("/");
  209. link[$i] = (_url.substr(0, _url.length - 1))
  210. }
  211. __LINK.push(link[$i].replace("nowvideo.sx", "nowvideo.tv"));
  212. }
  213. }
  214. var postObj = {
  215. title: data.title,
  216. soundquality: data.soundQuality,
  217. picturequality: data.quality,
  218. imdb_id: data.imdb,
  219. hoster: __HOSTER,
  220. link: __LINK,
  221. episode: data.episode,
  222. season: data.season
  223. };
  224. this.req(this.url + "ui.php?ua=tvshow", function(a, b, c) {
  225. if(b.req.path.indexOf("ui.php?ua=tvshow")) {
  226. console.log("SIND EINGELOGGT");
  227. } else {
  228. console.log("SIND NICHT EINGELOGGT");
  229. that.loggedIn = false;
  230. return that.login(obj, movieCallback);
  231. }
  232.  
  233. that.req.post({
  234. url: that.url + "ui.php?ua=tvshow&do=add",
  235. formData: generatePostHosterSERIES(postObj)
  236. }, function(a, b, c) {
  237. var $ = require("cheerio").load( c );
  238. console.log($("#maincontent4 strong").html());
  239. return movieCallback(obj);
  240.  
  241. });
  242. });
  243. }
  244.  
  245. exports.postMovie = function(obj, movieCallback) {
  246. var data = obj.mainData;
  247. var link = obj.chunk[obj.currentPos];
  248. var linkLength = link.length;
  249. var __HOSTER = [];
  250. var __LINK = [];
  251. var that = this;
  252. for ($i = 0; $i < linkLength; $i++) {
  253. if(link[$i] != null) {
  254. var LINK = this.getHostName(link[$i]);
  255. var allowed = this.allowedHosterMovie(LINK);
  256. if (allowed) {
  257. __HOSTER.push(allowed);
  258.  
  259. if (link[$i].indexOf("https://openload.co") > -1) {
  260. var _url = link[$i].split("/");
  261. delete _url[_url.length - 1];
  262. var _url = _url.join("/");
  263. link[$i] = (_url.substr(0, _url.length - 1))
  264. }
  265. __LINK.push(link[$i].replace("nowvideo.sx", "nowvideo.tv"));
  266. }
  267. }
  268. }
  269. if(__LINK.length <= 0) {
  270. return movieCallback(obj);
  271. }
  272. var postObj = {
  273. title: data.title,
  274. soundquality: data.soundQuality,
  275. picturequality: data.quality,
  276. imdb_id: data.imdb,
  277. hoster: __HOSTER,
  278. link: __LINK
  279. };
  280. this.req(this.url + "ui.php?ua=movie", function(a, b, c) {
  281. if(b.req.path.indexOf("ui.php?ua=movie")) {
  282. console.log("SIND EINGELOGGT");
  283. } else {
  284. console.log("SIND NICHT EINGELOGGT");
  285. that.loggedIn = false;
  286. return that.login(obj, movieCallback);
  287. }
  288. that.req.post({
  289. url: that.url + "ui.php?ua=movie&do=add",
  290. form: generatePostHosterMOVIE(postObj)
  291. }, function(a, b, c) {
  292. console.log(a);
  293. console.log(b.statusCode);
  294. var $ = that.cheerio.load(c);
  295. var txt = ($("#maincontent4 strong").text());
  296. console.log(txt + " " + postObj.title);
  297. if(txt.length <= 0) {
  298. that.loggedIn = false;
  299. return that.login(obj, movieCallback);
  300. }
  301. // var $ = that.cheerio.load( c );
  302. // $log = ( $('#maincontent4 strong').text() );
  303. return movieCallback(obj);
  304. /* if($log.length <= 0) {
  305. console.log("NO RESPONSE");
  306. return that.postMovie(data,link, callback, currentReq, maxReq, _doneCB);
  307. }
  308. console.log("angekommen "+ currentReq+" / "+maxReq);
  309.  
  310. /* that.increment();
  311. callback(that.name+" => "+$log);
  312. if(that.counter == maxReq) {
  313. that.resetCounter();
  314. return _doneCB("movie4k");
  315. }
  316. */
  317. });
  318. });
  319. };
  320.  
  321. exports.sleep = function(sec) {
  322. var milliseconds = sec * 1000;
  323. var start = new Date().getTime();
  324.  
  325. while (true) {
  326. if ((new Date().getTime() - start) > milliseconds) {
  327. break;
  328. }
  329. }
  330. }
  331.  
  332. function generatePostHosterMOVIE(obj) {
  333. var _ = {};
  334. _['title'] = obj.title;
  335. _['language'] = "2";
  336. _['picturequality'] = obj.picturequality;
  337. _['soundquality'] = obj.soundquality;
  338. _['imdbuser'] = "http://www.imdb.com/title/" + obj.imdb_id;
  339. _['genre1'] = "";
  340. _['genre2'] = "";
  341. _['genre3'] = "";
  342. _['genre4'] = "";
  343. _['genre5'] = "";
  344. _['genre1'] = "";
  345. _['genre2'] = "";
  346. _['genre3'] = "";
  347. _['genre4'] = "";
  348. _['genre5'] = "";
  349. _['thumbnail'] = "upload";
  350. _['thumbnaillink'] = "";
  351. _['description'] = "";
  352. _['duration'] = "";
  353. _['fsk'] = "";
  354. _['countryyear'] = "";
  355. _['director'] = "";
  356. _['actors'] = "";
  357. _['hoster'] = obj.hoster[0] || "";
  358. _['part[1]'] = obj.link[0] || "";
  359. _['part[2]'] = "";
  360. _['part[3]'] = "";
  361.  
  362. for ($i = 0; $i <= 10; $i++) {
  363. _['hoster2[' + $i + ']'] = obj.hoster[$i + 1] || "";
  364.  
  365. for (i = 0; i < 3; i++) {
  366. _LINK = obj.link[$i + 1] || "";
  367. _['part2[' + $i + '][' + i + ']'] = (i == 0) ? _LINK : "";
  368. }
  369.  
  370. }
  371. for ($x = 1; $x < 10; $x++) {
  372. _['detail[' + $x + ']'] = "";
  373. _['detailtext[' + $x + ']'] = "";
  374. }
  375. return _;
  376.  
  377. }
  378.  
  379. function generatePostHosterSERIES(obj) {
  380. var _ = {};
  381. _['title'] = obj.title;
  382. _['language'] = "2";
  383. _['season'] = obj.season;
  384. _['episode[1]'] = obj.episode;
  385. _['imdbuser'] = "http://www.imdb.com/title/" + obj.imdb_id;
  386. _['genre1'] = "";
  387. _['genre2'] = "";
  388. _['genre3'] = "";
  389. _['genre4'] = "";
  390. _['genre5'] = "";
  391. _['thumbnail'] = "upload";
  392. _['thumbnailfile'] = "",
  393. _['thumbnaillink'] = "";
  394. _['description'] = "";
  395. _['duration'] = "";
  396. _['fsk'] = "";
  397. _['countryyear'] = "";
  398. _['director'] = "";
  399. _['actors'] = "";
  400.  
  401.  
  402. for ($i = 0; $i < 10; $i++) {
  403. _['hoster2[' + $i + ']'] = obj.hoster[$i] || "";
  404.  
  405. _LINK = obj.link[$i] || "";
  406. _['link2[' + $i + ']'] = _LINK ;
  407.  
  408.  
  409. }
  410. for ($x = 1; $x < 10; $x++) {
  411. _['detail[' + $x + ']'] = "";
  412. _['detailtext[' + $x + ']'] = "";
  413. }
  414. return _;
  415. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement