Skip to content

Commit

Permalink
revised fixes
Browse files Browse the repository at this point in the history
Fixes:
- Reset Cookie
- Captcha support
- AutoPilot 'imdbid' error
  • Loading branch information
coder-alpha committed May 9, 2019
1 parent 0a05e80 commit 7789e61
Show file tree
Hide file tree
Showing 9 changed files with 403 additions and 79 deletions.
100 changes: 71 additions & 29 deletions Contents/Code/common.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
################################################################################
TITLE = "FMoviesPlus"
VERSION = '0.84' # Release notation (x.y - where x is major and y is minor)
VERSION = '0.85' # Release notation (x.y - where x is major and y is minor)
TAG = ''
GITHUB_REPOSITORY = 'coder-alpha/FMoviesPlus.bundle'
PREFIX = "/video/fmoviesplus"
Expand Down Expand Up @@ -323,6 +323,8 @@
RECAPTCHA_IMAGE_PREFIX = "recaptcha_img_"

FMOVIES_AVAILABLE = None
DO_NOT_MAKE_ADDITIONAL_REQUESTS = True
USE_CAPTCHA_AI = False

DEV_DEBUG = True if 'dev' in TAG else False

Expand Down Expand Up @@ -940,41 +942,50 @@ def GetPageElements(url, headers=None, referer=None, timeout=15):
return page_data_elems, error

####################################################################################################
def make_cookie_str():
def make_cookie_str(p_cookie=''):
try:
cookie_str = ''
p_cookie = ''
error = ''
if len(CACHE_COOKIE) > 0:
user_defined_reqkey_cookie = None
try:
user_defined_reqkey_cookie = Prefs['reqkey_cookie']
except:
pass
reqCookie = CACHE_COOKIE[0]['reqkey']
if user_defined_reqkey_cookie != None and user_defined_reqkey_cookie != '':
reqCookie = user_defined_reqkey_cookie

p_cookie = CACHE_COOKIE[0]['cookie'] + '; ' + reqCookie
p_cookie_s = []
if p_cookie == '':
if len(CACHE_COOKIE) > 0:
user_defined_reqkey_cookie = None
try:
user_defined_reqkey_cookie = Prefs['reqkey_cookie']
except:
pass
reqCookie = CACHE_COOKIE[0]['reqkey']
if user_defined_reqkey_cookie != None and user_defined_reqkey_cookie != '':
reqCookie = user_defined_reqkey_cookie

p_cookie = CACHE_COOKIE[0]['cookie'] + '; ' + reqCookie
p_cookie = p_cookie.replace(';;',';')
p_cookie_s = p_cookie.split(';')
elif p_cookie != '':
p_cookie = p_cookie.replace(';;',';')
p_cookie_s = p_cookie.split(';')
else:
#setTokenCookie(serverts=serverts, use_debug=use_debug)
error = "Cookie not set ! Please try Reset Cookies under the Options menu."
p_cookie_s = []
else:
p_cookie = p_cookie.replace(';;',';')
p_cookie_s = p_cookie.split(';')
cookie_string_arr = []
else:
#setTokenCookie(serverts=serverts, use_debug=use_debug)
error = "Cookie not set ! Please try Reset Cookies under the Options menu."
p_cookie_s = []

cookie_string_arr = []

for ps in p_cookie_s:
if '=' in ps:
try:
ps_s = ps.split('=')
k = ps_s[0].strip()
v = ps_s[1].strip()
if k == 'reqkey':
if len(v) > 5:
if 'expires' not in ps.lower() and 'max-age' not in ps.lower() and 'path' not in ps:
ps_s = ps.split('=')
k = ps_s[0].strip()
v = ps_s[1].strip()
if k == 'reqkey':
if len(v) > 5:
cookie_string_arr.append(k+'='+v)
else:
cookie_string_arr.append(k+'='+v)
else:
cookie_string_arr.append(k+'='+v)
except:
pass
try:
Expand Down Expand Up @@ -1042,6 +1053,19 @@ def GetPageAsString(url, headers=None, timeout=15, referer=None):
else:
Log.Error(error)
Log(cookies)
elif USE_COOKIES and ('9anime' in url):
cookies, error = make_cookie_str()
if error == '':
headers['Cookie'] = cookies
headers['User-Agent'] = CACHE_COOKIE[0]['UA']

if use_debug:
Log("Using Cookie retrieved at: %s" % time.ctime(CACHE_COOKIE[0]['ts']))
Log("Using Cookie: %s" % (cookies))
else:
Log.Error(error)
Log(cookies)

try:
if Prefs["use_https_alt"]:
if use_debug:
Expand Down Expand Up @@ -1395,7 +1419,7 @@ def SplitImageIntoChoices(filename, fil_dir):
c += 1
else:
prog = ""

try:
prog_t = Prefs["imagemagick_dir_path"]
if prog_t != None:
Expand All @@ -1414,16 +1438,34 @@ def SplitImageIntoChoices(filename, fil_dir):
wh = min(w,h)
cmd = "-crop"
c = 0

for y in range(3):
for x in range(3):
params = "%sx%s+%s+%s" % (w,h,x*wh,y*wh)
file_cmd = [Core.storage.join_path(prog, 'convert'), Core.storage.join_path(fil_dir, filename), cmd, params, Core.storage.join_path(fil_dir, '%s%s.jpg' % (RECAPTCHA_IMAGE_PREFIX,c))]
dest_file = '%s%s.jpg' % (RECAPTCHA_IMAGE_PREFIX,c)
file_cmd = [Core.storage.join_path(prog, 'convert'), Core.storage.join_path(fil_dir, filename), cmd, params, Core.storage.join_path(fil_dir, dest_file)]
process = subprocess.Popen(file_cmd, shell=False, cwd=fil_dir, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
ret = process.wait()
output = process.stdout.read()
c += 1

if Prefs["use_debug"]:
Log('%s - %s' % (file_cmd, output))

if USE_CAPTCHA_AI == True:
c2 = 0
for j in range(2):
for k in range(2):
w1 = w/2
h1 = w/2
wh1 = min(w1,h1)
params2 = "%sx%s+%s+%s" % (w1,h1,k*wh1,j*wh1)
file_cmd = [Core.storage.join_path(prog, 'convert'), Core.storage.join_path(fil_dir, dest_file), cmd, params2, Core.storage.join_path(fil_dir, '%s%s_%s.jpg' % (RECAPTCHA_IMAGE_PREFIX,c,c2))]
process = subprocess.Popen(file_cmd, shell=False, cwd=fil_dir, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
ret = process.wait()
output = process.stdout.read()
c2 += 1
c += 1

except Exception as e:
raise e
time.sleep(1)
Expand Down
7 changes: 6 additions & 1 deletion Contents/Code/downloadsmenu.py
Original file line number Diff line number Diff line change
Expand Up @@ -896,8 +896,13 @@ def AutoPilotDownloadThread2(item, sources):
#######################################################################################################
def AutoPilotDownloadThread3(item, s, fsBytes, fs):

imdbid = None
try:
return AddToDownloadsList(title=item['short_title'] if item['type']=='show' else item['title'], purl=item['purl'], url=s['url'], durl=s['durl'], summary=item['summary'], thumb=item['thumb'], year=item['year'], quality=s['quality'], source=s['source'], source_meta={}, file_meta={}, type=item['type'], vidtype=item['vidtype'], resumable=s['resumeDownload'], sub_url=s['sub_url'], fsBytes=fsBytes, fs=fs, file_ext=s['file_ext'], mode=common.DOWNLOAD_MODE[0], section_path=item['section_path'], section_title=item['section_title'], section_key=item['section_key'], session=item['session'], admin=item['admin'], params=s['params'], riptype=s['rip'], season=item['season'], episode=item['episode'], provider=s['provider'], page_url=s['page_url'], seq=s['seq'], imdbid=item['imdbid'], xitem=item['xitem'], viaCode=True)
imdbid=item['imdbid']
except:
pass
try:
return AddToDownloadsList(title=item['short_title'] if item['type']=='show' else item['title'], purl=item['purl'], url=s['url'], durl=s['durl'], summary=item['summary'], thumb=item['thumb'], year=item['year'], quality=s['quality'], source=s['source'], source_meta={}, file_meta={}, type=item['type'], vidtype=item['vidtype'], resumable=s['resumeDownload'], sub_url=s['sub_url'], fsBytes=fsBytes, fs=fs, file_ext=s['file_ext'], mode=common.DOWNLOAD_MODE[0], section_path=item['section_path'], section_title=item['section_title'], section_key=item['section_key'], session=item['session'], admin=item['admin'], params=s['params'], riptype=s['rip'], season=item['season'], episode=item['episode'], provider=s['provider'], page_url=s['page_url'], seq=s['seq'], imdbid=imdbid, xitem=item['xitem'], viaCode=True)
except Exception as e:
err = '{}'.format(e)
Log.Error('ERROR: downloadsmenu.py > AutoPilotDownloadThread3: %s' % err)
Expand Down
69 changes: 50 additions & 19 deletions Contents/Code/fmovies.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@
USE_PHANTOMJS2 = False
USE_DATAID = True

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'
newmarketgidstorage = ''
newmarketgidstorage2 = ';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'

####################################################################################################

Expand Down Expand Up @@ -331,6 +332,7 @@ def setTokenCookie(serverts=None, use_debug=False, reset=False, dump=False, quie
Log("Retrieved Saved Video-Token-Key: %s" % E(token_key))
Log("=====================TOKEN END============================")
else:
UA = common.client.randomagent()
reqkey_cookie = ''
cookie1 = ''
cookie2 = ''
Expand Down Expand Up @@ -379,6 +381,12 @@ def setTokenCookie(serverts=None, use_debug=False, reset=False, dump=False, quie
except Exception as e:
Log.Error(e)
Log("=====================SELENIUM END============================")
elif 'Your IP has been blocked' in result:
common.FMOVIES_AVAILABLE = False
if dump or use_debug:
Log("=====================TOKEN START============================")
Log('RE-CAPTCHA COOKIE TOKEN USED/REQUIRED - IP BLOCKED')
Log("=====================TOKEN END============================")
else:
common.FMOVIES_AVAILABLE = True
ALL_JS = None
Expand Down Expand Up @@ -550,14 +558,27 @@ def setTokenCookie(serverts=None, use_debug=False, reset=False, dump=False, quie
Log(unpacked_code)
except Exception as e:
Log('ERROR fmovies.py>Token-fetch-1: %s' % e)

try:
if len(TOKEN_KEY) == 0:
token_key = common.interface.request_via_proxy_as_backup(TOKEN_KEY_PASTEBIN_URL, httpsskip=use_https_alt, hideurl=True)
if token_key !=None and token_key != '':
#cookie_dict.update({'token_key':token_key})
TOKEN_KEY.append(token_key)
except Exception as e:
Log('ERROR fmovies.py>Token-fetch-2: %s' % e)

query = {'ts': serverts}
tk = get_token(query)
query.update(tk)
query = {'ts': serverts, '_': '634'}
# tk = get_token(query)
# if tk != None:
# 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, hideurl=True)
r1, headers, content, cookie2 = common.interface.request_via_proxy_as_backup(hash_url, headers=headersS, limit='0', output='extended', httpsskip=use_https_alt, hideurl=False)
ck, er = common.make_cookie_str(cookie2)
if er == '' and ck != '' and 'NotFound' not in ck and '__cfduid' in ck and ck != cookie2:
cookie2 = ck
#Log(cookie2)
try:
if '__cfduid' in cookie2:
Expand All @@ -578,15 +599,6 @@ def setTokenCookie(serverts=None, use_debug=False, reset=False, dump=False, quie
except:
pass

try:
if len(TOKEN_KEY) == 0:
token_key = common.interface.request_via_proxy_as_backup(TOKEN_KEY_PASTEBIN_URL, httpsskip=use_https_alt, hideurl=True)
if token_key !=None and token_key != '':
#cookie_dict.update({'token_key':token_key})
TOKEN_KEY.append(token_key)
except Exception as e:
Log('ERROR fmovies.py>Token-fetch-2: %s' % e)

if len(TOKEN_KEY) > 0:
cookie_dict.update({'token_key':TOKEN_KEY[0]})

Expand All @@ -611,13 +623,17 @@ def setTokenCookie(serverts=None, use_debug=False, reset=False, dump=False, quie

try:
if len(cookie2) > 0:
cookie = cookie1 + '; ' + cookie2 + '; user-info=null; ' + newmarketgidstorage
cookie = cookie1 + '; ' + cookie2 + newmarketgidstorage
else:
cookie = cookie1 + '; user-info=null; ' + newmarketgidstorage
cookie = cookie1 + newmarketgidstorage
except Exception as e:
Log.Error(e)
cookie = 'NotFound; %s; %s; user-info=null; %s' % (cookie1,cookie2,newmarketgidstorage)

cookie = 'NotFound; %s; %s%s' % (cookie1,cookie2,newmarketgidstorage)

ck, er = common.make_cookie_str(cookie)
if er == '' and ck != '' and 'NotFound' not in ck and '__cfduid' in ck and ck != cookie:
cookie = ck

cookie_dict.update({'ts':time.time(), 'cookie1': cookie1, 'cookie2': cookie2, 'cookie': cookie, 'UA': UA, 'reqkey':reqkey_cookie})

if dump or use_debug:
Expand All @@ -636,6 +652,15 @@ def setTokenCookie(serverts=None, use_debug=False, reset=False, dump=False, quie
del common.CACHE_COOKIE[:]
common.CACHE_COOKIE.append(cookie_dict)

ck, er = common.make_cookie_str()
if er == '' and ck != '' and 'NotFound' not in ck and '__cfduid' in ck and ck != cookie:
cookie = ck
cookie_dict.update({'cookie': 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, use_debug=False, use_https_alt=False, quiet=True):
Expand Down Expand Up @@ -1073,7 +1098,7 @@ def get_sources2(url, key, prev_error=None, use_debug=True, session=None, **kwar
ret_error = ''
Log(u'*PhantomJS* method is working: %s' % vx_url)
host_type = common.client.geturlhost(video_url)
except:
except Exception as e:
raise Exception('phantomjs (fmovies.js) not working')
else:
raise Exception('phantomjs is disabled')
Expand Down Expand Up @@ -1153,8 +1178,14 @@ def get_servers(serverts, page_url, is9Anime=False, use_https_alt=False):
T_BASE_URL = BASE_URL
T_BASE_URL = 'https://%s' % common.client.geturlhost(page_url)
page_id = page_url.rsplit('.', 1)[1]
#https://fmovies.taxi/ajax/film/servers/woxzo?ts=1557154800&_=634
#https://fmovies.taxi/ajax/film/servers/v8vv?ts=1557248400&_=634
#https://fmovies.taxi/ajax/film/servers/0r5yr?ts=1557248400&_=634
server_query = '/ajax/film/servers/%s' % page_id
server_url = urlparse.urljoin(T_BASE_URL, server_query)
query = {'ts':serverts, '_': '634'}
server_url += '?' + urllib.urlencode(query)

#result = common.interface.request_via_proxy_as_backup(server_url, httpsskip=use_https_alt)
result, error = common.GetPageAsString(url=server_url, headers=None, referer=page_url)
html = '<html><body><div id="servers-container">%s</div></body></html>' % json.loads(result)['html'].replace('\n','').replace('\\','')
Expand Down
14 changes: 8 additions & 6 deletions Contents/Code/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1552,7 +1552,6 @@ def IntHostTools(choice=None, myhost=None, mssg=None, session=None):
def IntProviderTools(choice=None, provider=None, mssg=None):

oc = ObjectContainer(title2='%s Tools' % provider.title())

if choice != None:
if choice == 'show_dump_log':
oc = ObjectContainer(title2='%s Log' % provider.title())
Expand Down Expand Up @@ -1722,8 +1721,6 @@ def ResetCookies(mode=None, **kwargs):
thumbIcon = R(common.ICON_NOTOK)
if lpl != None:
thumbIcon = R(Core.storage.join_path(common.RECAPTCHA_CACHE_DIR, '%s%s.jpg' % (common.RECAPTCHA_IMAGE_PREFIX,i)))

Log(thumbIcon)

common.FMOVIES_CAPTCHA_SELECTION[str(i)] = bool

Expand Down Expand Up @@ -1806,6 +1803,7 @@ def SolveCaptchaFMovies(resp, **kwargs):
cookies += '; user-info=null; ' + fmovies.newmarketgidstorage

cookie_dict.update({'ts':time.time(), 'cookie':cookies, 'cookie1':cookies1, 'cookie2':'', 'UA': ua})
common.control.set_setting(common.control.RECEPTCHA_FMOVIES_COOKIE, cookie_dict)
Dict['CACHE_COOKIE'] = E(JSON.StringFromObject(cookie_dict))
Dict.Save()

Expand All @@ -1818,7 +1816,6 @@ def SolveCaptchaFMovies(resp, **kwargs):

del common.CACHE_COOKIE[:]
common.CACHE_COOKIE.append(cookie_dict)

common.FMOVIES_AVAILABLE = True

return MC.message_container('Success', 'Captch Solved !')
Expand Down Expand Up @@ -5370,7 +5367,12 @@ def MoviesWithTag(tags, session, is9anime='False', **kwargs):
@route(PREFIX + "/getmovieinfo")
def GetMovieInfo(summary, urlPath, referer=None, session=None, is9anime='False', **kwargs):

if common.NO_MOVIE_INFO == True or urlPath == None and (summary == None or summary == '') or Prefs['use_web_proxy']:
if common.DO_NOT_MAKE_ADDITIONAL_REQUESTS == True:
if summary == None:
return 'Plot Summary on Item Page'
else:
return summary
elif common.NO_MOVIE_INFO == True or urlPath == None and (summary == None or summary == '') or Prefs['use_web_proxy']:
return 'Plot Summary on Item Page'
elif (is9anime == 'False' and common.UsingOption(common.DEVICE_OPTIONS[8], session=session) == True) or (is9anime == 'True' and common.UsingOption(common.DEVICE_OPTIONS[11], session=session) == True):
return 'Plot Summary on Item Page. Disabled via Device Options.'
Expand All @@ -5380,7 +5382,7 @@ def GetMovieInfo(summary, urlPath, referer=None, session=None, is9anime='False',
return summary
elif Prefs["dont_fetch_more_info"]:
return 'Plot Summary on Item Page'

try:
if is9anime == 'False':
url = urlparse.urljoin(fmovies.BASE_URL , urlPath)
Expand Down
2 changes: 2 additions & 0 deletions Contents/Libraries/Shared/phantomjs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ def decode(url, python_dir=None, debug=False, ssl=True, js='openload.js', cookie
#print "2: %s" % output
output = output.strip().replace('\n','').encode('utf8').decode('ascii')
#print "3: %s" % output
if output != None and len(output) > 0 and '\r' in output:
output = output.split('\r')[0]

PROCESSES[url_encode].update({'Completed':True})

Expand Down
Loading

0 comments on commit 7789e61

Please sign in to comment.