Skip to content

Commit

Permalink
Merge pull request #28 from XBMCil/1.0.9_cr_comment
Browse files Browse the repository at this point in the history
removed retries altogether and now getting time waited dynamically
  • Loading branch information
morsela committed May 24, 2016
2 parents d2df255 + b1f5f0f commit 77595a8
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 24 deletions.
1 change: 0 additions & 1 deletion resources/lib/SubtitleHelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
__version__ = __addon__.getAddonInfo('version') # Module version
__scriptname__ = __addon__.getAddonInfo('name')


def log(module, msg):
xbmc.log((u"### [%s] - %s" % (module, msg,)).encode('utf-8'),
level=xbmc.LOGDEBUG)
Expand Down
33 changes: 12 additions & 21 deletions resources/lib/TorecSubtitlesDownloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,11 @@ def _build_default_cookie(self, sub_id):
"current_datetime": current_time
}

def _get_user_auth(self):
user_auth_text = self.opener.open(self.USER_AUTH_JS_URL).read()
return re.search(r"userAuth='(.*)';", user_auth_text).group(1)
def _get_user_auth(self, subw_text):
return re.search(r"userAuth='(.*)';", subw_text).group(1)

def _get_time_waited(self, subw_text):
return re.search(r"seconds\s+=\s+(\d+);", subw_text).group(1)

def _request_subtitle(self, sub_id):
params = {
Expand Down Expand Up @@ -177,30 +179,19 @@ def search_by_movie_name(self, movie_name):
subtitle_data = subtitle_data.read()
return SubtitlePage(id_, movie_name, sub_url, subtitle_data)

def get_download_link(self, sub_id, option_id, persist=True):
response = None
data = None

params = {
def get_download_link(self, sub_id, option_id):
subw_text = self.opener.open(self.USER_AUTH_JS_URL).read()
params = {
"sub_id": sub_id,
"code": option_id,
"sh": "yes",
"guest": self._request_subtitle(sub_id),
"timewaited": "11",
"userAuth": self._get_user_auth()
"timewaited": self._get_time_waited(subw_text),
"userAuth": self._get_user_auth(subw_text)
}

for i in xrange(16):
response = self.opener.open(
"%s/ajax/sub/downloadun.asp" % self.BASE_URL, urllib.urlencode(params),
)
data = response.read()
if len(data) != 0 or not persist:
break
time.sleep(1)
if data:
return data
return response
response = self.opener.open("%s/ajax/sub/downloadun.asp" % self.BASE_URL, urllib.urlencode(params))
return response.read()

def download(self, download_link):
response = self.opener.open(
Expand Down
2 changes: 1 addition & 1 deletion service.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def download(page_id, subtitle_id, filename, stack=False):

delete_old_subs()
try:
result = downloader.get_download_link(page_id, subtitle_id, False)
result = downloader.get_download_link(page_id, subtitle_id)
except Exception as e:
log(__name__,"failed to connect to service for subtitle download %s" % e)
return subtitle_list
Expand Down
2 changes: 1 addition & 1 deletion tests/basic_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def convert_to_utf(file):
page_id = search_data.id
subtitle_id = option.id

result = downloader.get_download_link(page_id, subtitle_id, False)
result = downloader.get_download_link(page_id, subtitle_id)
subtitleData, fileName = downloader.download(result)
extension = os.path.splitext(fileName)[1]

Expand Down

0 comments on commit 77595a8

Please sign in to comment.