Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- exports.url = "https://www.m2k.to";
- exports.req = require("request");
- var cheerio = require("cheerio");
- exports.name = "movie2k";
- var jar = exports.req.jar();
- exports.setDefault = function() {
- this.req = this.req.defaults({
- jar: jar,
- headers: {
- "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.trim();
- this.password = pass.trim();
- }
- exports.counter = 0;
- exports.resetCounter = function() {
- this.counter = 0;
- }
- exports.increment = function() {
- this.counter++;
- }
- exports.login = function(obj, movieCallback) {
- if(obj.mainData.isSeries) {
- return movieCallback("No Series allowed");
- }
- this.setDefault();
- var that = this;
- if (this.loggedIn) {
- return this.sendTo(obj, movieCallback);
- }
- this.req.get({
- url: this.url+"/auth/login",
- headers: {
- "x-requested-with":"XMLHttpRequest"
- }
- }, function(a, b, c) {
- that.req.post({
- url: that.url+"/auth/login",
- headers: {
- "x-requested-with":"XMLHttpRequest"
- },
- formData: {
- referer: that.url+"/auth/login",
- "login[login]": that.username,
- "login[password]" :that.password
- }
- }, function(a, b, c) {
- that.req(that.url, function(a,b,c){
- if(c.indexOf("https://www.m2k.to/u/"+that.username) > -1) {
- that.loggedIn = true;
- return that.addMovie(obj, movieCallback);
- }
- });
- });
- });
- }
- exports.addMovie = function(obj, callback) {
- this.setDefault();
- var self = this;
- self.req.get(self.url+"/u/"+self.username+"/add_link", function(err, head, dom){
- var uploadLinks = [];
- obj.chunk.forEach(function(chunkArr){
- chunkArr.forEach(function(link){
- uploadLinks.push(link);
- });
- });
- var postData = {
- imdb: obj.mainData.imdb,
- rtitle: obj.mainData.rlsTitle,
- quid: self.getQuality(obj.mainData.quality, obj.mainData.rlsTitle),
- language: "de",
- link: uploadLinks.join("\r\n")
- }
- self.req.post({
- url: self.url+"/u/"+self.username+"/add_link",
- form: postData
- }, function(err, head, body){
- var $ = cheerio.load(body);
- return callback($("#panel_userinfo h2").html());
- });
- });
- }
- exports.getQuality = function(currentQuality, rlstitle) {
- if(rlstitle.toLowerCase().indexOf("dvdrip") > -1) {
- return 4;
- }
- switch(currentQuality) {
- //Cam rip to cam rip
- case 1 :
- return 2;
- //HDTV etc to DVDRip
- case 5 :
- return 5;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement