Advertisement
Guest User

Untitled

a guest
Feb 8th, 2017
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.17 KB | None | 0 0
  1. exports.url = "https://www.m2k.to";
  2. exports.req = require("request");
  3. var cheerio = require("cheerio");
  4. exports.name = "movie2k";
  5. var jar = exports.req.jar();
  6. exports.setDefault = function() {
  7. this.req = this.req.defaults({
  8. jar: jar,
  9. headers: {
  10. "Accept-Encoding": "gzip,deflate,sdch",
  11. "Accept-Language": "de-DE,de;q=0.8,en-US;q=0.6,en;q=0.4,nl;q=0.2",
  12. "Cache-Control": "max-age=0",
  13. "Connection": "keep-alive",
  14. "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"
  15. },
  16. gzip: true,
  17. followRedirect: true,
  18. followAllRedirects: true
  19. });
  20. };
  21. exports.setCredentials = function(user, pass) {
  22. this.username = user.trim();
  23. this.password = pass.trim();
  24. }
  25. exports.counter = 0;
  26. exports.resetCounter = function() {
  27. this.counter = 0;
  28. }
  29. exports.increment = function() {
  30. this.counter++;
  31. }
  32. exports.login = function(obj, movieCallback) {
  33. if(obj.mainData.isSeries) {
  34. return movieCallback("No Series allowed");
  35. }
  36. this.setDefault();
  37. var that = this;
  38. this.req.get({
  39. url: this.url
  40. }, function(a,b,c) {
  41. if (c.indexOf("https://www.m2k.to/u/"+that.username) > -1) {
  42. return that.addMovie(obj, movieCallback);
  43. }
  44. that.req({
  45. url: this.url+"/auth/login",
  46. headers: {
  47. "x-requested-with":"XMLHttpRequest"
  48. }
  49. }, function(a, b, c) {
  50. that.req.post({
  51. url: that.url+"/auth/login",
  52. headers: {
  53. "x-requested-with":"XMLHttpRequest"
  54. },
  55. formData: {
  56. referer: that.url+"/auth/login",
  57. "login[login]": that.username,
  58. "login[password]" :that.password
  59. }
  60. }, function(a, b, c) {
  61. that.req(that.url, function(a,b,c){
  62. if(c.indexOf("https://www.m2k.to/u/"+that.username) > -1) {
  63. that.loggedIn = true;
  64. return that.addMovie(obj, movieCallback);
  65. }
  66. });
  67. });
  68. });
  69. });
  70.  
  71. }
  72. exports.addMovie = function(obj, callback) {
  73. this.setDefault();
  74. var self = this;
  75. self.req.get(self.url+"/u/"+self.username+"/add_link", function(err, head, dom){
  76. var postData = {
  77. imdb: obj.mainData.imdb,
  78. rtitle: obj.mainData.rlsTitle,
  79. qid: self.getQuality(obj.mainData.quality, obj.mainData.rlsTitle),
  80. language: "de",
  81. link: obj.chunk[obj.currentPos].join("\r\n")
  82. }
  83. self.req.post({
  84. url: self.url+"/u/"+self.username+"/add_link",
  85. form: postData
  86. }, function(err, head, body){
  87. var $ = cheerio.load(body);
  88. return callback($("#panel_userinfo h2").html());
  89. });
  90. });
  91. }
  92.  
  93. exports.getQuality = function(currentQuality, rlstitle) {
  94. if(rlstitle.toLowerCase().indexOf("dvdrip") > -1) {
  95. return 4;
  96. }
  97. switch(currentQuality) {
  98. //Cam rip to cam rip
  99. case 1 :
  100. return 2;
  101. //HDTV etc to DVDRip
  102. case 5 :
  103. return 4;
  104.  
  105. }
  106. return 0;
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement