def delete(dbfile=control.cacheFile, withyes=True): if withyes: yes = control.yesnoDialog(control.lang(30401).encode('utf-8'), '', '') if not yes: return else: pass control.deleteFile(dbfile) control.infoDialog(control.lang(30402).encode('utf-8'))
def download(self, path, url): try: result = client.request(url) # f = os.path.splitext(urlparse(url).path)[1][1:] f = os.path.join(path, url.rpartition('/')[2]) with open(f, 'wb') as subFile: subFile.write(result) dirs, files = control.listDir(path) if len(files) == 0: return if not f.lower().endswith('.rar'): control.execute('Extract("%s","%s")' % (f, path)) if control.infoLabel('System.Platform.Windows'): conversion = quote else: conversion = quote_plus if f.lower().endswith('.rar'): uri = "rar://{0}/".format(conversion(f)) dirs, files = control.listDir(uri) else: for i in range(0, 10): try: dirs, files = control.listDir(path) if len(files) > 1: break if control.aborted is True: break control.wait(1) except BaseException: pass filename = [ i for i in files if any( i.endswith(x) for x in ['.srt', '.sub']) ][0].decode('utf-8') subtitle = os.path.join(path, filename) if f.lower().endswith('.rar'): content = control.openFile(uri + filename).read() with open(subtitle, 'wb') as subFile: subFile.write(content) control.deleteFile(f) return subtitle else: control.deleteFile(f) return subtitle except BaseException: pass
def download(self, path, url): try: url, php= url.split('|') if 'subs4series' in url: headers = { 'User-Agent': 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3', 'Referer': url, 'Origin': 'https://www.subs4series.com/'} cj = {'PHPSESSID': php} r = requests.get(url, headers=headers, cookies=cj).content # r = re.sub(r'[^\x00-\x7F]+', ' ', r) if six.PY2: r = re.sub(r'[^\x00-\x7F]+', ' ', r) # try: # r = r.decode('utf-8', errors='replace') # except AttributeError: # pass # xbmc.log('@@HTML:%s' % r) pos = re.findall(r'''href=["'](/getSub-.+?)["']''', r, re.I | re.DOTALL)[0] # xbmc.log('@@POSSSSS:%s' % pos) post_url = urljoin(self.base_TVlink, pos) # xbmc.log('@@POStttt:%s' % post_url) r = requests.get(post_url, headers=headers, cookies=cj) surl = r.url result = client.request(surl) else: headers = { 'User-Agent': 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3', 'Referer': url, 'Origin': 'https://www.sf4-industry.com'} cj = {'PHPSESSID': php} post_url = 'https://www.sf4-industry.com/getSub.php' r = requests.get(url, headers=headers, cookies=cj).text if six.PY2: r = re.sub(r'[^\x00-\x7F]+', ' ', r) # try: # r = r.decode('utf-8', errors='replace') # except AttributeError: # pass # xbmc.log('@@HTMLLL:%s' % r) pos = client.parseDOM(r, 'div', attrs={'class': 'download-btn'})[0] pos = client.parseDOM(pos, 'input', ret='value', attrs={'name': 'id'})[0] # pos = re.findall(r'getSub-(\w+)\.html', r, re.I | re.DOTALL)[0] post = {'id': pos, 'x': '107', 'y': '35'} r = requests.post(post_url, headers=headers, data=post, cookies=cj) # surl = r.headers['Location'] surl = r.url result = client.request(surl) # surl = self.base_link + surl if surl.startswith('/') else surl # path = 'special://userdata/addon_data/service.subtitles.greeksubs/temp/' f = os.path.join(path, surl.rpartition('/')[2]) # if f.lower().endswith('.rar') and not control.condVisibility('system.platform.osx'): # return control.okDialog('GreekSubs', 'Το αρχείο υποτίτλου είναι σε μορφή rar\n και δεν μπορεί να ληφθεί.\n' # 'Δοκιμάστε άλλον υπότιτλο!') with open(f, 'wb') as subFile: subFile.write(result) dirs, files = control.listDir(path) if len(files) == 0: return if not f.lower().endswith('.rar'): control.execute('Extract("{}","{}")'.format(f, path)) if control.condVisibility('system.platform.windows'): conversion = quote else: conversion = quote_plus if f.lower().endswith('.rar'): import xbmcvfs # if control.condVisibility('system.platform.osx'): # uri = "rar://{}/".format(conversion(f)) uri = 'rar://%(archive_file)s' % {'archive_file': conversion(control.transPath(f))} dirs, files = control.listDir(uri) # else: # return else: for i in range(0, 10): try: dirs, files = control.listDir(path) if len(files) > 1: break if control.aborted is True: break control.wait(1) except BaseException: pass filenames = [i for i in files if any(i.endswith(x) for x in ['.srt', '.sub'])] if len(filenames) == 1: filename = filenames[0] else: filename = multichoice(filenames) try: filename = filename.decode('utf-8') except BaseException: pass subtitle = os.path.join(path, filename) if f.lower().endswith('.rar'): content = control.openFile(path + filename).read() with open(subtitle, 'w') as subFile: subFile.write(content) control.deleteFile(f) return subtitle else: return subtitle except BaseException: pass