-
Notifications
You must be signed in to change notification settings - Fork 16
/
fmovies.py
370 lines (311 loc) · 11.9 KB
/
fmovies.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
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
#
# Coder Alpha
# https://github.com/coder-alpha
#
# Adapted from lambda's Kodi plugin
# https://github.com/lambda81
# and modified for use with Plex Media Server
#
#########################################################################################################
import urllib, urlparse, json, time, re, datetime, calendar
import common
from __builtin__ import ord, format
BASE_URL = "https://fmovies.to"
HASH_PATH_MENU = "/user/ajax/menu-bar"
HASH_PATH_INFO = "/ajax/episode/info"
TOKEN_PATH = "/token"
SEARCH_PATH = "/search"
FILTER_PATH = "/filter"
KEYWORD_PATH = "/tag/"
STAR_PATH = "/star/"
oldmarketgidstorage = 'MarketGidStorage=%7B%220%22%3A%7B%22svspr%22%3A%22%22%2C%22svsds%22%3A3%2C%22TejndEEDj%22%3A%22MTQ4MTM2ODE0NzM0NzQ4NTMyOTAx%22%7D%2C%22C48532%22%3A%7B%22page%22%3A1%2C%22time%22%3A1481368147359%7D%2C%22C77945%22%3A%7B%22page%22%3A1%2C%22time%22%3A1481368147998%7D%2C%22C77947%22%3A%7B%22page%22%3A1%2C%22time%22%3A1481368148109%7D%7D'
newmarketgidstorage = 'MarketGidStorage=%7B%220%22%3A%7B%22svspr%22%3A%22%22%2C%22svsds%22%3A15%2C%22TejndEEDj%22%3A%22MTQ5MzIxMTc0OTQ0NDExMDAxNDc3NDE%3D%22%7D%2C%22C110014%22%3A%7B%22page%22%3A3%2C%22time%22%3A1493215038742%7D%2C%22C110025%22%3A%7B%22page%22%3A3%2C%22time%22%3A1493216772437%7D%2C%22C110023%22%3A%7B%22page%22%3A3%2C%22time%22%3A1493216771928%7D%7D; reqkey='
####################################################################################################
# Get FMovies-API
#@route(PREFIX + '/getapiurl')
def GetApiUrl(url, key, serverts=0, use_debug=True, use_https_alt=False, use_web_proxy=False, cache_expiry_time=60, reqCookie='', **kwargs):
try:
use_debug = Prefs["use_debug"]
use_https_alt = Prefs["use_https_alt"]
use_web_proxy = Prefs["use_web_proxy"]
cache_expiry_time = int(Prefs["cache_expiry_time"])
user_defined_reqkey_cookie = Prefs['reqkey_cookie']
reqCookie = common.CACHE_COOKIE[0]['reqkey']
if user_defined_reqkey_cookie != None and user_defined_reqkey_cookie != '':
reqCookie = user_defined_reqkey_cookie
except:
pass
res = None
error = ''
myts = time.time()
try:
CACHE_EXPIRY = 60 * cache_expiry_time
except:
CACHE_EXPIRY = common.CACHE_EXPIRY_TIME
if key in common.CACHE and 'myts' in common.CACHE[key] and (myts - int(common.CACHE[key]['myts']) < common.CACHE_EXPIRY):
if use_debug:
Log("Using Movie Link from Cache")
res = common.CACHE[key]['res']
isOpenLoad = common.CACHE[key]['isOpenLoad']
if isOpenLoad == 'True':
isOpenLoad = True
#surl = common.host_openload.resolve(url=res, embedpage=True)
surl = res
if use_debug:
Log("Openload Stream URL %s from %s" % (surl,res))
res = surl
else:
if res == 'Unavailable':
res = None
isOpenLoad = False
else:
if use_debug:
Log("Retrieving Fresh Movie Link")
ret, isOpenLoad, error = get_sources(url=url, key=key, use_debug=use_debug, serverts=serverts, myts=myts, use_https_alt=use_https_alt, use_web_proxy=use_web_proxy, reqCookie=reqCookie)
if use_debug:
Log("get_sources url: %s, key: %s" % (url,key))
Log("get_sources ret: %s" % ret)
if common.USE_SECOND_REQUEST == True and ret == None: # if the request ever fails - clear CACHE right away and make 2nd attempt
common.CACHE.clear()
if use_debug:
Log("CACHE cleared due to null response from API - maybe cookie issue for %s" % url)
time.sleep(1.0)
ret, isOpenLoad, error = get_sources(url=url, key=key, use_debug=use_debug, serverts=serverts, myts=myts, use_https_alt=use_https_alt, use_web_proxy=use_web_proxy, reqCookie=reqCookie)
if use_debug:
Log("API - attempt 2nd")
Log("get_sources url: %s, key: %s" % (url,key))
Log("get_sources ret: %s" % ret)
if ret == None:
if use_debug:
Log("null response from API (possible file deleted) - for %s" % url)
return res, isOpenLoad, error
else:
if isOpenLoad:
res = ret
common.CACHE[key] = {}
common.CACHE[key]['res'] = res
common.CACHE[key]['serverts'] = serverts
common.CACHE[key]['myts'] = myts
common.CACHE[key]['isOpenLoad'] = str(isOpenLoad)
if use_debug:
Log("Added " + key + " to CACHE")
#surl = common.host_openload.resolve(url=res, embedpage=True)
surl = ret
if use_debug:
Log("Openload Stream URL %s from %s" % (surl,ret))
res = surl
else:
# fix api url to https
ret = ret.replace('http://','https://')
data = None
headersS = {'X-Requested-With': 'XMLHttpRequest'}
headersS['Referer'] = '%s/%s' % (url, key)
headersS['Cookie'] = common.CACHE_COOKIE[0]['cookie']
try:
time.sleep(1.0)
data = common.interface.request_via_proxy_as_backup(ret, limit='0', headers=headersS, httpsskip=use_https_alt)
data = json.loads(data)
except Exception as e:
Log('ERROR fmovies.py>GetApiUrl-1: ARGS:%s, URL:%s' % (e,ret))
pass
if data == None:
return None, isOpenLoad, error
if data['error'] == None:
res = JSON.StringFromObject(data['data'])
common.CACHE[key] = {}
common.CACHE[key]['res'] = res
common.CACHE[key]['serverts'] = serverts
common.CACHE[key]['myts'] = myts
common.CACHE[key]['isOpenLoad'] = str(isOpenLoad)
if use_debug:
Log("Added " + key + " to CACHE")
Log("Added " + res + " to " + key)
elif data['error'] != None:
error = data['error']
else:
error = 'Unknown error'
return res, isOpenLoad, error
def setTokenCookie(serverts=None, use_debug=False, reset=False, dump=False):
try:
CACHE_EXPIRY = 60 * int(Prefs["cache_expiry_time"])
except:
CACHE_EXPIRY = common.CACHE_EXPIRY_TIME
use_https_alt = Prefs['use_https_alt']
if reset:
cookie_dict_Str = None
Dict['CACHE_COOKIE'] = None
else:
cookie_dict_Str = Dict['CACHE_COOKIE']
cookie_dict = {'ts':0, 'cookie': '', 'UA': '', 'reqkey':''}
if cookie_dict_Str != None:
try:
cookie_dict = JSON.ObjectFromString(D(cookie_dict_Str))
except:
pass
if time.time() - cookie_dict['ts'] < CACHE_EXPIRY:
try:
cookie = cookie_dict['cookie']
reqkey_cookie = cookie_dict['reqkey']
except:
setTokenCookie(use_debug=use_debug, reset=True)
if dump or use_debug:
Log("=====================TOKEN START============================")
Log("USING SAVED COOKIE TOKEN - TO DUMP TOKEN PERFORM RESET COOKIE UNDER OPTIONS MENU")
Log("Retrieved Saved Cookie: %s" % cookie)
Log("Retrieved Saved reqkey Cookie: %s" % reqkey_cookie)
Log("=====================TOKEN END============================")
else:
if serverts == None:
serverts = str(((int(time.time())/3600)*3600))
UA = common.client.randomagent()
headersS = {'X-Requested-With': 'XMLHttpRequest'}
headersS['Referer'] = BASE_URL
headersS['User-Agent'] = UA
result, headers, content, cookie1 = common.interface.request_via_proxy_as_backup(BASE_URL, headers=headersS, limit='0', output='extended', httpsskip=use_https_alt)
headersS['Cookie'] = cookie1
time.sleep(0.1)
token_url = urlparse.urljoin(BASE_URL, TOKEN_PATH)
r1 = common.interface.request_via_proxy_as_backup(token_url, headers=headersS, httpsskip=use_https_alt)
time.sleep(0.1)
del common.TOKEN_CODE[:]
token_enc = common.client.b64encode(r1)
common.TOKEN_CODE.append(token_enc)
try:
reqkey_cookie = decodeAndParse(token_enc)
except:
reqkey_cookie = ''
if dump or use_debug:
Log("=====================TOKEN START============================")
Log(common.TOKEN_CODE[0])
Log("=====================TOKEN END============================")
query = {'ts': serverts}
tk = get_token(query)
query.update(tk)
hash_url = urlparse.urljoin(BASE_URL, HASH_PATH_MENU)
hash_url = hash_url + '?' + urllib.urlencode(query)
r1, headers, content, cookie2 = common.interface.request_via_proxy_as_backup(hash_url, headers=headersS, limit='0', output='extended', httpsskip=use_https_alt)
common.CACHE['cookie'] = {}
common.CACHE['cookie']['cookie1'] = cookie1
common.CACHE['cookie']['cookie2'] = cookie2
common.CACHE['cookie']['myts'] = time.time()
common.CACHE['cookie']['UA'] = UA
common.CACHE['cookie']['reqkey'] = reqkey_cookie
cookie = cookie1 + '; ' + cookie2 + '; user-info=null; ' + newmarketgidstorage
cookie_dict = {'ts':time.time(), 'cookie': cookie, 'UA': UA, 'reqkey':reqkey_cookie}
if dump or use_debug:
Log("Storing Cookie: %s" % cookie)
Log("Storing reqkey Cookie: %s" % reqkey_cookie)
Dict['CACHE_COOKIE'] = E(JSON.StringFromObject(cookie_dict))
Dict.Save()
del common.CACHE_COOKIE[:]
common.CACHE_COOKIE.append(cookie_dict)
return cookie
def decodeAndParse(token):
dec = common.jsfdecoder.JSFDecoder(common.client.b64decode(token)).ca_decode()
dec = dec.split('reqkey=')
dec = dec[1].split(';')
dec = dec[0]
return dec
def get_sources(url, key, use_debug=True, serverts=0, myts=0, use_https_alt=False, use_web_proxy=False, reqCookie='', **kwargs):
if serverts == 0:
#serverts = ((int(time.time())/3600)*3600)
# 1485273600
# 1485324000
# 1485327600
# 1485324000
# 1485352800
utc = datetime.datetime.utcnow()
if utc.hour < 6:
past = utc - datetime.timedelta(hours=13) # 1485273600
elif utc.hour >= 6 and utc.hour < 16:
past = utc # 1485324000, 1485327600, 1485352800
else:
past = utc - datetime.timedelta(hours=12) # 1485324000, 1485334800
past_fixed = datetime.datetime(past.year, past.month, past.day, past.hour, 0, 0, 0)
serverts = calendar.timegm(past_fixed.timetuple())
try:
error = None
magic_url = None
isOpenLoad = False
if url == None: return magic_url
referer = url
serverts = str(serverts)
T_BASE_URL = BASE_URL
#T_BASE_URL = "https://fmovies.unlockpro.top"
time.sleep(0.5)
if common.USE_COOKIES == True:
if len(common.CACHE_COOKIE) > 0:
pass
else:
setTokenCookie(serverts=serverts, use_debug=use_debug)
user_defined_reqkey_cookie = Prefs['reqkey_cookie']
reqCookie = common.CACHE_COOKIE[0]['reqkey']
if user_defined_reqkey_cookie != None and user_defined_reqkey_cookie != '':
reqCookie = user_defined_reqkey_cookie
cookie = common.CACHE_COOKIE[0]['cookie'] + reqCookie
else:
cookie = ''
try:
headers = {'X-Requested-With': 'XMLHttpRequest'}
headers['User-Agent'] = common.CACHE_COOKIE[0]['UA']
hash_url = urlparse.urljoin(T_BASE_URL, HASH_PATH_INFO)
query = {'ts': serverts, 'id': key, 'update':'0'}
tk = get_token(query)
query.update(tk)
hash_url = hash_url + '?' + urllib.urlencode(query)
headers['Referer'] = '%s/%s' % (url, key)
headers['Cookie'] = cookie
if use_debug:
Log("Using cookies : %s" % headers['Cookie'])
#print hash_url
if use_debug:
Log("get_sources Request-3: %s" % hash_url)
result = common.interface.request_via_proxy_as_backup(hash_url, headers=headers, httpsskip=use_https_alt)
Log("Request-3 result: %s" % result)
#print result
result = json.loads(result)
if 'error' in result:
grabber = None
error = result['error']
elif result['target'] != "":
grabber = result['target']
isOpenLoad = True
else:
query = {'id':result['params']['id'], 'token':result['params']['token']}
grabber = result['grabber'] + '?' + urllib.urlencode(query)
if grabber!=None and not grabber.startswith('http'):
grabber = 'http:'+grabber
magic_url = grabber
except Exception as e:
Log('ERROR fmovies.py>get_sources-1 %s, %s' % (e.args,url))
pass
return magic_url, isOpenLoad, error
except Exception as e:
error = e
Log('ERROR fmovies.py>get_sources-2 %s, %s' % (e.args,url))
return magic_url, isOpenLoad, error
def r01(t, e):
i = 0
n = 0
for i in range(0, max(len(t), len(e))):
if i < len(e):
n += ord(e[i])
if i < len(t):
n += ord(t[i])
h = format(int(hex(n),16),'x')
return h
def a01(t):
i = 0
for e in range(0, len(t)):
i += ord(t[e])
return i
def get_token(n, **kwargs):
try:
d = D("YjgyNmFlMDQ=")
s = a01(d)
for i in n:
s += a01(r01(d + i, n[i]))
return {'_': str(s)}
except Exception as e:
Log("fmovies.py > get_token > %s" % e)
#########################################################################################################