Advertisement
Guest User

Untitled

a guest
Jan 18th, 2017
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.15 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. if (this.loggedIn) {
  39. return this.sendTo(obj, movieCallback);
  40. }
  41. this.req.get({
  42. url: this.url+"/auth/login",
  43. headers: {
  44. "x-requested-with":"XMLHttpRequest"
  45. }
  46. }, function(a, b, c) {
  47. that.req.post({
  48. url: that.url+"/auth/login",
  49. headers: {
  50. "x-requested-with":"XMLHttpRequest"
  51. },
  52. formData: {
  53. referer: that.url+"/auth/login",
  54. "login[login]": that.username,
  55. "login[password]" :that.password
  56. }
  57. }, function(a, b, c) {
  58. that.req(that.url, function(a,b,c){
  59. if(c.indexOf("https://www.m2k.to/u/"+that.username) > -1) {
  60. that.loggedIn = true;
  61. return that.addMovie(obj, movieCallback);
  62. }
  63. });
  64. });
  65. });
  66. }
  67. exports.addMovie = function(obj, callback) {
  68. this.setDefault();
  69. var self = this;
  70. self.req.get(self.url+"/u/"+self.username+"/add_link", function(err, head, dom){
  71. var uploadLinks = [];
  72. obj.chunk.forEach(function(chunkArr){
  73. chunkArr.forEach(function(link){
  74. uploadLinks.push(link);
  75. });
  76. });
  77. var postData = {
  78. imdb: obj.mainData.imdb,
  79. rtitle: obj.mainData.rlsTitle,
  80. quid: self.getQuality(obj.mainData.quality, obj.mainData.rlsTitle),
  81. language: "de",
  82. link: uploadLinks.join("\r\n")
  83. }
  84. self.req.post({
  85. url: self.url+"/u/"+self.username+"/add_link",
  86. form: postData
  87. }, function(err, head, body){
  88. var $ = cheerio.load(body);
  89. return callback($("#panel_userinfo h2").html());
  90. });
  91. });
  92. }
  93.  
  94. exports.getQuality = function(currentQuality, rlstitle) {
  95. if(rlstitle.toLowerCase().indexOf("dvdrip") > -1) {
  96. return 4;
  97. }
  98. switch(currentQuality) {
  99. //Cam rip to cam rip
  100. case 1 :
  101. return 2;
  102. //HDTV etc to DVDRip
  103. case 5 :
  104. return 5;
  105.  
  106. }
  107. return 0;
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement