1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
/*************************
** Modules **
**************************/
var request = require('request');
var cheerio = require('cheerio');
var moment = require('moment');
/*************************
** Variables **
**************************/
var BASE_URL = "https://eztv.it";
var SHOWLIST = "/showlist/";
var LATEST = "/sort/100/";
var SEARCH = "/search/";
var SHOWS = "/shows/";
var eztv_map = require('../config').map;
exports.getAllShows = function(cb) {
if(cb == null) return;
request(BASE_URL + SHOWLIST, function(err, res, html){
if(err) return (err, null);
var $ = cheerio.load(html);
var title, show;
var allShows = [];
$('.thread_link').each(function(){
var entry = $(this);
var show = entry.text();
var id = entry.attr('href').match(/\/shows\/(.*)\/(.*)\//)[1];
var slug = entry.attr('href').match(/\/shows\/(.*)\/(.*)\//)[2];
slug = slug in eztv_map ? eztv_map[slug]: slug;
allShows.push({show: show, id: id, slug: slug});
});
return cb(null, allShows);
});
}
exports.getAllEpisodes = function(data, cb) {
if(cb == null) return;
var episodes = {};
request.get(BASE_URL + SHOWS + data.id + "/"+ data.slug +"/", function (err, res, html) {
if(err) return cb(err, null);
var $ = cheerio.load(html);
var show_rows = $('tr.forum_header_border[name="hover"]').filter(function() {
episode_rows = $(this).children('.forum_thread_post');
if(episode_rows.length > 0) {
var title = $(this).children('td').eq(1).text();
if(title.indexOf("-CTU") > -1)
return false;
else
return true;
}
return false;
});
if(show_rows.length === 0) return cb("Show Not Found", null);
show_rows.each(function() {
var entry = $(this);
var title = entry.children('td').eq(1).text().replace('x264', ''); // temp fix
var magnet = entry.children('td').eq(2).children('a').first().attr('href');
var matcher = title.match(/S?0*(\d+)?[xE]0*(\d+)/);
var quality = title.match(/(\d{3,4})p/) ? title.match(/(\d{3,4})p/)[0] : "480p";
if(matcher) {
var season = parseInt(matcher[1], 10);
var episode = parseInt(matcher[2], 10);
var torrent = {};
torrent.url = magnet;
torrent.seeds = 0;
torrent.peers = 0;
if(!episodes[season]) episodes[season] = {};
if(!episodes[season][episode]) episodes[season][episode] = {};
if(!episodes[season][episode][quality] || title.toLowerCase().indexOf("repack") > -1)
episodes[season][episode][quality] = torrent;
episodes.dateBased = false;
}
else {
matcher = title.match(/(\d{4}) (\d{2} \d{2})/); // Date based TV Shows
var quality = title.match(/(\d{3,4})p/) ? title.match(/(\d{3,4})p/)[0] : "480p";
if(matcher) {
var season = matcher[1]; // Season : 2014
var episode = matcher[2].replace(" ", "/"); //Episode : 04/06
var torrent = {};
torrent.url = magnet;
torrent.seeds = 0;
torrent.peers = 0;
if(!episodes[season]) episodes[season] = {};
if(!episodes[season][episode]) episodes[season][episode] = {};
if(!episodes[season][episode][quality] || title.toLowerCase().indexOf("repack") > -1)
episodes[season][episode][quality] = torrent;
episodes.dateBased = true;
}
}
});
return cb(null, episodes);
});
}
|