-
Notifications
You must be signed in to change notification settings - Fork 15
/
vplayBrowser.py
312 lines (265 loc) · 10.5 KB
/
vplayBrowser.py
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
import vplayCommon, login, vplayScraper, search
import res
import xbmc
import sys
import random
import simplejson as json
import codecs
import os
class ListResources:
__settings__ = sys.modules[ "__main__" ].__settings__
__language__ = sys.modules[ "__main__" ].__language__
__plugin__ = sys.modules[ "__main__" ].__plugin__
__dbg__ = sys.modules[ "__main__" ].__dbg__
__login__ = sys.modules[ "__main__" ].__login__
__search__ = sys.modules[ "__main__" ].__search__
def get_thumb(self, name):
THUMBNAIL_PATH = os.path.join( self.__settings__.getAddonInfo('path'), "thumbnails" )
p = os.path.join(THUMBNAIL_PATH, str(name) + '.png')
if os.path.isfile(p):
return p
return ""
def __init__(self):
self.http_lib = vplayCommon.Http()
self.session = None
if not self.__settings__.getSetting( "username" ) or not self.__settings__.getSetting( "pwd" ):
self.__login__.login()
self.scrap = vplayScraper.Scrap()
def getLastPage(self):
last_page = 110;
# p = self.http_lib._get(res.urls['serials'])
# print "PAGE ==>" + str(p['httpcode'])
# if p['httpcode'] == 200:
# last_page = self.scrap.scrapLastPage(p['httpmsg'])
# print "PAGE ==> " + str(last_page)
# else:
# last_page = 1
# if len(last_page) > 0:
# try:
# last_page = int(last_page[0][0])
# except:
# last_page = 1
return last_page
def _get_session(self):
val = self.__settings__.getSetting('session')
val = val+"; promo_shown=1"
xbmc.log("using session "+val)
return val;
def getSerials(self, page=None, type=None, search=None):
self.session = self._get_session()
if not self.session:
self.__login__.login()
self.session = self._get_session()
if page == None:
url = res.urls['serials']
else:
try:
int(page)
url = res.urls['serials'] + "/" + str(page) + "/"
except:
url = res.urls['serials']
if type == "Search":
url = res.urls['search'] + search
cookie = str(self.session)
lst = [];
ret = self.http_lib._get(url, cookie)
if ret['httpcode'] == 200:
if type == None or type == "Categorii":
lst = self.scrap.scrapSerials(ret['httpmsg'])
elif type == "Favorite":
lst = self.scrap.scrapFavorite(ret['httpmsg'])
elif type == "Search":
lst = self.scrap.scrapSearch(ret['httpmsg'])
if len(lst) < 1 and int(page) == 1:
self.__search__.noResult();
else:
lst = self.scrap.scrapSerials(ret['httpmsg'])
elif ret['httpcode'] == 301:
self.__login__.login()
else:
raise IOError('Could not get serial list: %s --> %s' % (ret['httpcode'], ret['httpmsg']))
return lst
def getSesons(self, url):
self.session = self._get_session()
xbmc.log("getting sessons "+self.session);
if not self.session:
self.__login__.login()
self.session = self._get_session()
cookie = str(self.session)
ret = self.http_lib._get(url, cookie)
lst = [];
if ret['httpcode'] == 200:
lst = self.scrap.scrapSeasons(ret['httpmsg'])
elif ret['httpcode'] == 301:
self.__login__.login()
else:
raise IOError('Could not get serial list: %s --> %s' % (ret['httpcode'], ret['httpmsg']))
return lst
def getEpisodes(self, url):
self.session = self._get_session()
if not self.session:
self.__login__.login()
self.session = self._get_session()
cookie = str(self.session)
ret = self.http_lib._get(url, cookie)
lst = [];
if ret['httpcode'] == 200:
lst = self.scrap.scrapEpisodes(ret['httpmsg'])
elif ret['httpcode'] == 301:
self.__login__.login()
else:
raise IOError('Could not get serial list: %s --> %s' % (ret['httpcode'], ret['httpmsg']))
return lst
def getFavorites(self, url):
self.session = self._get_session()
if not self.session:
self.__login__.login()
self.session = self._get_session()
cookie = str(self.session)
ret = self.http_lib._get(url, cookie)
lst = [];
if ret['httpcode'] == 200:
lst = self.scrap.scrapFavorites(ret['httpmsg'])
elif ret['httpcode'] == 301:
self.__login__.login()
else:
raise IOError('Could not get serial list: %s --> %s' % (ret['httpcode'], ret['httpmsg']))
return lst
class linkResolution:
__settings__ = sys.modules[ "__main__" ].__settings__
__language__ = sys.modules[ "__main__" ].__language__
__plugin__ = sys.modules[ "__main__" ].__plugin__
__dbg__ = sys.modules[ "__main__" ].__dbg__
__login__ = sys.modules[ "__main__" ].__login__
def __init__(self):
self.http_lib = vplayCommon.Http()
self.scrap = vplayScraper.Scrap()
self.random = random.random()
#try:
# cur_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'resources')
# cur_dir = os.path.join(cur_dir, 'subtitles')
# if os.path.isdir(cur_dir) is False:
# os.makedirs(cur_dir)
# self.subs_dir = cur_dir
#except:
tmp_dir = xbmc.translatePath( "special://temp")
subs = os.path.join(tmp_dir, 'plugin.video.vplay_subtitles')
if os.path.isdir(subs) is False:
os.makedirs(subs)
self.subs_dir = subs
def _get_session(self):
val = self.__settings__.getSetting('session')
val = val+"; promo_shown=1"
xbmc.log("using session "+val)
return val;
def convert_time_to_something(self, f):
f = int(f)
def min_and_sec(f):
if f > 60:
f_minute = f/60
f_secunde = f%60
else:
f_minute = "00"
f_secunde = f
if f_minute < 10:
f_minute = "0" + str(f_minute)
if f_secunde < 10:
f_secunde = "0" + str(f_secunde)
return str(f_minute) + ":" + str(f_secunde) + ",0"
if f > 3600:
hours = f/3600
f = f%3600
if hours < 10:
hours = "0" + str(hours)
else:
hours = str(hours)
else:
hours = "00"
final = hours + ":" + min_and_sec(f)
return final
def getSubs(self, key, subs):
url = res.urls['sub'] + '?' + str(self.random)
ret = {}
sub_dir = os.path.join(self.subs_dir, str(key))
if os.path.isdir(sub_dir) is False:
try:
os.makedirs(sub_dir)
except Exception, err:
return ret
for i in subs:
print "SUBS: Processing " + str(i)
sub_file_name = os.path.join(sub_dir, str(i) + '.sub')
if os.path.isfile(sub_file_name) is True:
ret[str(i).lower()] = sub_file_name
continue
postData = {"key": str(key), "lang": str(i)}
url_ret = self.http_lib._post(url, postData)
if url_ret['httpcode'] != 200:
print "SUBS: got code " + str(url_ret['httpcode'])
continue
data = url_ret['httpmsg'].strip('&subsData=').rstrip('\n')
try:
data = data.expandtabs(2);
obj = json.loads(data)
fisier = codecs.open(sub_file_name, 'w', 'utf-8')
count = 1
for j in obj:
sub_line = str(count) + '\n'
f = int(j['f'])
t = int(j['t'])
sub_line = sub_line + self.convert_time_to_something(f) + " --> " + self.convert_time_to_something(t) + '\n'
sub_line = sub_line + j['s'] + '\n\n'
fisier.write(sub_line)
count = count + 1
fisier.close()
except Exception, err:
print "SUBS: Got exception " + str(err)
continue
ret[str(i).lower()] = sub_file_name
return ret
def processDinosaur(self, key):
url = res.urls['dino']
#+ '?key=' + str(key) + "&rand=" + str(self.random)
postData = {"key": str(key)}
ret = self.http_lib._post(url, postData)
print 'DINO URL: ' + str(url)
print "DINO: ", ret
if ret['httpcode'] != 200:
raise Exception('Could not get movie link')
#print "XXXXXX ==> " + str(ret)
vals = ret['httpmsg'].split('&')
attrs = {}
for i in vals:
if len(i) == 0:
continue
value = i.split('=')
attrs[value[0]] = value[1]
return attrs
def getRealLink(self, url):
self.session = self._get_session()
if not self.session:
self.__login__.login()
self.session = self._get_session()
cookie = str(self.session)
ret = self.http_lib._get(url, cookie)
if ret['httpcode'] == 301 or ret['httpcode'] == 302:
__login__.login()
self._get_session()
ret = self.http_lib._get(url, cookie)
if ret['httpcode'] != 200:
raise Exception('failed to get episode: %s' % (ret['httpcode']))
ep_id = self.scrap.scrapEpisodeId(url)
if len(ep_id) != 1:
raise ValueError('Could not get episode ID')
values = self.processDinosaur(ep_id[0])
if len(values) == 0:
raise IOError('Could not get movie link')
try:
s = json.loads(values['subs'])
except Exception, err:
print "SUBS: Got exception in json " + str(err)
s = []
print "SUBS: ---> " + str(s)
subs = self.getSubs(ep_id[0], s)
ret = {'url': values['nqURL'], 'subs': subs}
return ret