-
Notifications
You must be signed in to change notification settings - Fork 0
/
SearchZamunda.js
161 lines (136 loc) · 3.8 KB
/
SearchZamunda.js
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
var Promise = require("bluebird");
var request = require('request-promise');
var iconv = require('iconv-lite');
var jsdom = require("jsdom").JSDOM;
var fs = require("fs");
var _ = require("underscore");
var j = request.jar();
function setCookie(cookieVal) {
var cookie = request.cookie(cookieVal.name + "=" + cookieVal.value);
j.setCookie(cookie, "http://zamunda.net");
}
var cookies = [
{
name: "PHPSESSID",
value: "udproa2kdvbiiertl51i9v7ga7"
},
{
name: "_ddn_intercept_2_",
value: "fb72da232e44d3e97efc38fdf9e4950d"
},
{
name: "russian_lang",
value: "no",
},
{
name: "uid",
value: "561759",
},
{
name: "pass",
value: "934b462acdd06a77ca8d91dbcff2a81c"
},
{
name: "cats",
value: "7",
},
{
name: "periods",
value: "7",
},
{
name: "statuses",
value: "1",
}];
cookies.forEach(function (cookieVal) {
setCookie(cookieVal);
});
var staticOptions = {
url: 'http://zamunda.net/bananas', //browse.php',
// proxy: "http://localhost:8888",
headers: {
"Accept": "text/html, application/xhtml+xml, */*",
"Accept-Language": "en-US,en;q=0.7,bg;q=0.3",
"User-Agent": "Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; Touch; MALNJS; rv:11.0) like Gecko",
"Accept-Encoding": "gzip, deflate"
//Connection: Keep-Alive
//Pragma: no-cache
},
jar: j,
gzip: true,
encoding: null,
qs: {
"search": null,
"field": "name"
}
};
var zamundaCategories = {
"7": "Сериали",
"33": "Сериали/HD"
};
function parseSearchResults($, columns) {
//columns[0]
var catLink = $(columns[0]).find("a")[0];
var catLinkHref = catLink.getAttribute("href");
var cat = /list\?cat=(\d+)/g.exec(catLinkHref)[1];
//columns[1] - name, download links
var name, downloadLink;
$(columns[1]).find("a").each(function (index, value) {
var href = value.getAttribute("href");
if (/^banan/.test(href)) {
//name
name = value.textContent;
}
if (/^\/download.php\/(\d+)\//.test(href)) {
//name
downloadLink = href;
}
/*
if (/^banan/.test(href)) {
//name
name = value.textContent;
} else {
var downloadUrlMatch = (/^\/download_go.php\?id=(\d+)/.exec(href));
if (downloadUrlMatch != null) {
//download link
var torrentId = downloadUrlMatch[1];
downloadLink = "download.php/" + torrentId + "/";
}
}
*/
});
//columns[4] - date added
var nobrElement = $(columns[4]).find("nobr")[0];
var date = nobrElement.childNodes[0].nodeValue;
var time = nobrElement.childNodes[2].nodeValue;
var dateAdded = new Date(date + " " + time);
return {
name: name,
downloadLink: "http://zamunda.net" + downloadLink,
dateAdded: dateAdded,
cat: zamundaCategories[cat]
};
}
function searchZamunda(searchString) {
var options = _.extend({}, staticOptions);
options.qs.search = searchString;
return request.get(options)
.then(function (body) {
var strBody = iconv.decode(body, 'win1251');
return strBody;
})
.then(function (strBody) {
var window = (new jsdom(strBody)).window;
return window;
})
.then(function (window) {
var $ = require("jquery")(window);
return Promise
.resolve($("table.bottom table.test tr:gt(0)").toArray())
.map(function (element) {
var columns = $(element).find("td");
return parseSearchResults($, columns);
});
});
}
module.exports = searchZamunda;