def copy(file, path): try: # Post Dharma import xbmcvfs size_file, hash_file = xbmc.subHashAndFileSize(file) try: size_dest, hash_dest = xbmc.subHashAndFileSize(os.path.join(path, os.path.basename(file))) except: size_dest = 0 hash_dest = "" if hash_file != hash_dest: xbmcvfs.copy(file, os.path.join(path, os.path.basename(file))) if __settings__.getSetting( "delete" ) == "true": size_dest, hash_dest = xbmc.subHashAndFileSize(os.path.join(path, os.path.basename(file))) if hash_file == hash_dest: xbmcvfs.delete(file) log("Deleted %s" % file) except: # Dharma import shutil, filecmp if not os.path.exists(os.path.join(path, os.path.basename(file))): shutil.copy(file,os.path.join(path, os.path.basename(file))) if filecmp.cmp(file, os.path.join(path, os.path.basename(file))) and __settings__.getSetting( "delete" ) == "true": os.remove(file) log("Deleted %s" % file)
def search_subtitles( file_original_path, title, tvshow, year, season, episode, set_temp, rar, lang1, lang2, lang3, stack ): #standard input ok = False msg = "" osdb_server = OSDBServer() osdb_server.create() subtitles_list = [] file_size = "" hashTry = "" language1 = languageTranslate(lang1,0,1) language2 = languageTranslate(lang2,0,1) language3 = languageTranslate(lang3,0,1) if set_temp : hash_search = False file_size = "000000000" SubHash = "000000000000" else: try: file_size, SubHash = xbmc.subHashAndFileSize(file_original_path) log( __name__ ,"xbmc module hash and size") hash_search = True except: file_size = "" SubHash = "" hash_search = False if file_size != "" and SubHash != "": log( __name__ ,"File Size [%s]" % file_size ) log( __name__ ,"File Hash [%s]" % SubHash) if hash_search : log( __name__ ,"Search for [%s] by hash" % (os.path.basename( file_original_path ),)) subtitles_list, session_id = osdb_server.searchsubtitles_pod( SubHash ,language1, language2, language3, stack) if not subtitles_list: log( __name__ ,"Search for [%s] by name" % (os.path.basename( file_original_path ),)) subtitles_list = osdb_server.searchsubtitlesbyname_pod( title, tvshow, season, episode, language1, language2, language3, year, stack ) return subtitles_list, "", "" #standard output
def search_subtitles(file_original_path, title, tvshow, year, season, episode, set_temp, rar, lang1, lang2, lang3, stack): #standard input ok = False msg = "" hash_search = False osdb_server = OSDBServer() subtitles_list = [] if len(tvshow) > 0: # TvShow OS_search_string = ("%s S%.2dE%.2d" % ( tvshow, int(season), int(episode), )).replace(" ", "+") else: # Movie or not in Library if str(year) == "": # Not in Library title, year = xbmc.getCleanMovieTitle(title) else: # Movie in Library year = year title = title OS_search_string = title.replace(" ", "+") log(__name__, "Search String [ %s ]" % (OS_search_string, )) if set_temp: hash_search = False file_size = "000000000" hashTry = "000000000000" else: try: try: file_size, hashTry = xbmc.subHashAndFileSize( file_original_path) log(__name__, "xbmc module hash and size") except: hashTry = timeout(set_filehash, args=(file_original_path, rar), timeout_duration=5) file_size = str(os.path.getsize(file_original_path)) hash_search = True except: file_size = "" hashTry = "" hash_search = False log(__name__, "File Size [%s]" % file_size) log(__name__, "File Hash [%s]" % hashTry) log( __name__, "Search by hash and name %s" % (os.path.basename(file_original_path), )) subtitles_list, msg = osdb_server.searchsubtitles(OS_search_string, lang1, lang2, lang3, hash_search, hashTry, file_size) return subtitles_list, "", msg #standard output
def search_subtitles( file_original_path, title, tvshow, year, season, episode, set_temp, rar, lang1, lang2, lang3, stack ): #standard input ok = False msg = "" osdb_server = OSDBServer() osdb_server.create() subtitles_list = [] file_size = "" hashTry = "" language1 = twotoone(toOpenSubtitles_two(lang1)) language2 = twotoone(toOpenSubtitles_two(lang2)) language3 = twotoone(toOpenSubtitles_two(lang3)) if set_temp : hash_search = False else: try: try: file_size, hashTry = xbmc.subHashAndFileSize(file_original_path) log( __name__ ,"xbmc module hash and size") except: hashTry = timeout(set_filehash, args=(file_original_path, rar), timeout_duration=5) file_size = str(os.path.getsize( file_original_path )) hash_search = True except: hash_search = False if file_size != "": log( __name__ ,"File Size [%s]" % file_size ) if hashTry != "": log( __name__ ,"File Hash [%s]" % hashTry) if hash_search : log( __name__ ,"Search for [%s] by hash" % (os.path.basename( file_original_path ),)) subtitles_list, session_id = osdb_server.searchsubtitles_pod( hashTry ,language1, language2, language3, stack) if not subtitles_list: log( __name__ ,"Search for [%s] by name" % (os.path.basename( file_original_path ),)) subtitles_list = osdb_server.searchsubtitlesbyname_pod( title, tvshow, season, episode, language1, language2, language3, year, stack ) return subtitles_list, "", "" #standard output
def search_subtitles(file_original_path, title, tvshow, year, season, episode, set_temp, rar, lang1, lang2, lang3, stack): #standard input ok = False msg = "" osdb_server = OSDBServer() osdb_server.create() subtitles_list = [] file_size = "" hashTry = "" language1 = twotoone(toOpenSubtitles_two(lang1)) language2 = twotoone(toOpenSubtitles_two(lang2)) language3 = twotoone(toOpenSubtitles_two(lang3)) if set_temp: hash_search = False else: try: try: file_size, hashTry = xbmc.subHashAndFileSize( file_original_path) log(__name__, "xbmc module hash and size") except: hashTry = timeout(set_filehash, args=(file_original_path, rar), timeout_duration=5) file_size = str(os.path.getsize(file_original_path)) hash_search = True except: hash_search = False if file_size != "": log(__name__, "File Size [%s]" % file_size) if hashTry != "": log(__name__, "File Hash [%s]" % hashTry) if hash_search: log( __name__, "Search for [%s] by hash" % (os.path.basename(file_original_path), )) subtitles_list, session_id = osdb_server.searchsubtitles_pod( hashTry, language1, language2, language3, stack) if not subtitles_list: log( __name__, "Search for [%s] by name" % (os.path.basename(file_original_path), )) subtitles_list = osdb_server.searchsubtitlesbyname_pod( title, tvshow, season, episode, language1, language2, language3, year, stack) return subtitles_list, "", "" #standard output
def search_subtitles( file_original_path, title, tvshow, year, season, episode, set_temp, rar, lang1, lang2, lang3, stack ): #standard input ok = False msg = "" hash_search = False osdb_server = OSDBServer() subtitles_list = [] if len(tvshow) > 0: # TvShow OS_search_string = ("%s S%.2dE%.2d" % (tvshow, int(season), int(episode),)).replace(" ","+") else: # Movie or not in Library if str(year) == "": # Not in Library title, year = xbmc.getCleanMovieTitle( title ) else: # Movie in Library year = year title = title OS_search_string = title.replace(" ","+") log( __name__ , "Search String [ %s ]" % (OS_search_string,)) if set_temp : hash_search = False file_size = "000000000" hashTry = "000000000000" else: try: try: file_size, hashTry = xbmc.subHashAndFileSize(file_original_path) log( __name__ ,"xbmc module hash and size") except: hashTry = timeout(set_filehash, args=(file_original_path, rar), timeout_duration=5) file_size = str(os.path.getsize( file_original_path )) hash_search = True except: file_size = "" hashTry = "" hash_search = False log( __name__ ,"File Size [%s]" % file_size) log( __name__ ,"File Hash [%s]" % hashTry) log( __name__ ,"Search by hash and name %s" % (os.path.basename( file_original_path ),)) subtitles_list, msg = osdb_server.searchsubtitles( OS_search_string, lang1, lang2, lang3, hash_search, hashTry, file_size ) return subtitles_list, "", msg #standard output
def search_subtitles(self, file_original_path, title, tvshow, year, season, episode, set_temp, rar, lang1, lang2, lang3 ): url = self.server_url+'/index.php?'+urllib.urlencode({'Fulltext':title,'FindUser':''}) if not (tvshow == None or tvshow == ''): title2 = tvshow+' '+get_episode_season(episode,season) url = self.server_url+'/index.php?'+urllib.urlencode({'Fulltext':title2,'FindUser':''}) req = urllib2.Request(url) try: size, SubHash = xbmc.subHashAndFileSize(file_original_path) file_size='%.2f' % (float(size)/(1024*1024)) except: file_size='-1' log(__name__,'Opening %s' % (url)) response = urllib2.urlopen(req) content = response.read() response.close() log(__name__,'Done') subtitles_list = [] max_downloads=1 log(__name__,'Searching for subtitles') for row in re.finditer('<tr class=\"r(.+?)</tr>', content, re.IGNORECASE | re.DOTALL): item = {} log(__name__,'New subtitle found') try: item['ID'] = re.search('[^<]+<td[^<]+<a href=\"[\w-]+-(?P<data>\d+).htm\"',row.group(1),re.IGNORECASE | re.DOTALL ).group('data') item['title'] = re.search('[^<]+<td[^<]+<a[^>]+>(<div[^>]+>)?(?P<data>[^<]+)',row.group(1),re.IGNORECASE | re.DOTALL ).group('data') item['sync'] = '' sync_found = re.search('((.+?)</td>)[^>]+>[^<]*<a(.+?)title=\"(?P<data>[^\"]+)',row.group(1),re.IGNORECASE | re.DOTALL ) if sync_found: item['sync'] = sync_found.group('data') item['tvshow'] = re.search('((.+?)</td>){2}[^>]+>(?P<data>[^<]+)',row.group(1),re.IGNORECASE | re.DOTALL ).group('data') item['year'] = re.search('((.+?)</td>){3}[^>]+>(?P<data>[^<]+)',row.group(1),re.IGNORECASE | re.DOTALL ).group('data') item['downloads'] = re.search('((.+?)</td>){5}[^>]+>(?P<data>[^<]+)',row.group(1),re.IGNORECASE | re.DOTALL ).group('data') item['lang'] = re.search('((.+?)</td>){6}[^>]+><img alt=\"(?P<data>\w{2})\"',row.group(1),re.IGNORECASE | re.DOTALL ).group('data') item['numberOfDiscs'] = re.search('((.+?)</td>){7}[^>]+>(?P<data>[^<]+)',row.group(1),re.IGNORECASE | re.DOTALL ).group('data') item['size'] = re.search('((.+?)</td>){8}[^>]+>(?P<data>[\d\.]+)',row.group(1),re.IGNORECASE | re.DOTALL ).group('data') except: log(__name__,'Exception when parsing subtitle, all I got is %s' % str(item)) continue if item['sync'] == '': # if no sync info is found, just use title instead of None item['filename'] = item['title'] else: item['filename'] = item['sync'] item['language_flag'] = "flags/%s.gif" % (lang2_opensubtitles(item['lang'])) sync = False if not item['sync'] == '' and file_original_path.find(item['sync']) > -1: log(__name__,'found sync : filename match') sync = True if file_size==item['size']: log(__name__,'found sync : size match') sync = True item['sync'] = sync try: downloads = int(item['downloads']) if downloads>max_downloads: max_downloads=downloads except: downloads=0 item['downloads'] = downloads if not year == '': if not item['year'] == year: log(__name__,'year does not match, ignoring %s' % str(item)) continue lang = lang_titulky2xbmclang(item['lang']) item['language_name'] = lang item['mediaType'] = 'mediaType' item['rating'] = '0' if lang in [lang1,lang2,lang3]: subtitles_list.append(item) else: log(__name__,'language does not match, ignoring %s' % str(item)) # computing ratings is based on downloads for subtitle in subtitles_list: subtitle['rating'] = str((subtitle['downloads']*10/max_downloads)) return subtitles_list
def search_subtitles(self, file_original_path, title, tvshow, year, season, episode, set_temp, rar, lang1, lang2, lang3): url = self.server_url + '/index.php?' + urllib.urlencode({ 'Fulltext': title, 'FindUser': '' }) if not (tvshow == None or tvshow == ''): title2 = tvshow + ' ' + get_episode_season(episode, season) url = self.server_url + '/index.php?' + urllib.urlencode( { 'Fulltext': title2, 'FindUser': '' }) req = urllib2.Request(url) try: size, SubHash = xbmc.subHashAndFileSize(file_original_path) file_size = '%.2f' % (float(size) / (1024 * 1024)) except: file_size = '-1' log(__name__, 'Opening %s' % (url)) response = urllib2.urlopen(req) content = response.read() response.close() log(__name__, 'Done') subtitles_list = [] max_downloads = 1 log(__name__, 'Searching for subtitles') for row in re.finditer('<tr class=\"r(.+?)</tr>', content, re.IGNORECASE | re.DOTALL): item = {} log(__name__, 'New subtitle found') try: item['ID'] = re.search( '[^<]+<td[^<]+<a href=\"[\w-]+-(?P<data>\d+).htm\"', row.group(1), re.IGNORECASE | re.DOTALL).group('data') item['title'] = re.search( '[^<]+<td[^<]+<a[^>]+>(<div[^>]+>)?(?P<data>[^<]+)', row.group(1), re.IGNORECASE | re.DOTALL).group('data') item['sync'] = '' sync_found = re.search( '((.+?)</td>)[^>]+>[^<]*<a(.+?)title=\"(?P<data>[^\"]+)', row.group(1), re.IGNORECASE | re.DOTALL) if sync_found: item['sync'] = sync_found.group('data') item['tvshow'] = re.search( '((.+?)</td>){2}[^>]+>(?P<data>[^<]+)', row.group(1), re.IGNORECASE | re.DOTALL).group('data') item['year'] = re.search( '((.+?)</td>){3}[^>]+>(?P<data>[^<]+)', row.group(1), re.IGNORECASE | re.DOTALL).group('data') item['downloads'] = re.search( '((.+?)</td>){4}[^>]+>(?P<data>[^<]+)', row.group(1), re.IGNORECASE | re.DOTALL).group('data') item['lang'] = re.search( '((.+?)</td>){5}[^>]+><img alt=\"(?P<data>\w{2})\"', row.group(1), re.IGNORECASE | re.DOTALL).group('data') item['numberOfDiscs'] = re.search( '((.+?)</td>){6}[^>]+>(?P<data>[^<]+)', row.group(1), re.IGNORECASE | re.DOTALL).group('data') item['size'] = re.search( '((.+?)</td>){7}[^>]+>(?P<data>[\d\.]+)', row.group(1), re.IGNORECASE | re.DOTALL).group('data') except: log( __name__, 'Exception when parsing subtitle, all I got is %s' % str(item)) continue if item['sync'] == '': # if no sync info is found, just use title instead of None item['filename'] = item['title'] else: item['filename'] = item['sync'] item['language_flag'] = "flags/%s.gif" % (lang2_opensubtitles( item['lang'])) sync = False if not item['sync'] == '' and file_original_path.find( item['sync']) > -1: log(__name__, 'found sync : filename match') sync = True if file_size == item['size']: log(__name__, 'found sync : size match') sync = True item['sync'] = sync try: downloads = int(item['downloads']) if downloads > max_downloads: max_downloads = downloads except: downloads = 0 item['downloads'] = downloads if not year == '': if not item['year'] == year: log(__name__, 'year does not match, ignoring %s' % str(item)) continue lang = lang_titulky2xbmclang(item['lang']) item['language_name'] = lang item['mediaType'] = 'mediaType' item['rating'] = '0' if lang in [lang1, lang2, lang3]: subtitles_list.append(item) else: log(__name__, 'language does not match, ignoring %s' % str(item)) # computing ratings is based on downloads for subtitle in subtitles_list: subtitle['rating'] = str( (subtitle['downloads'] * 10 / max_downloads)) return subtitles_list
def getallsubs(content, title, subtitles_list, file_original_path, stack, lang1, lang2, lang3): soup = BeautifulSoup(content) subs = soup("tr") sub_str = str(subs[1:]) first_row = True for row in subs[1:]: sub_number_re = 'a href=\"/download/(\d+)/\"><strong>' title_re = '<a href="/download/\d+?/"><strong>(.+?)</strong></a>' release_re = '<td>(.+?)<br />|<td.+?>(.+?)<br />' rating_re = 'rednia ocena: (\d\,\d\d)<br />' lang_re = '<img src="images/ico_flag_(..)_2.png" alt="' disc_amount_re = '<td.+?style="text-align: center;">[\r\n\t ]+?(\d)[\r\n\t ]+?</td>' video_file_size_re = 'Rozmiar pliku: <strong>(\d+?)</strong>' video_file_size_re_multi = 'Rozmiar pliku:<br />- CD1: <strong>(\d+?)</strong>' archive_re = '<a href="/download/archiwum/(\d+?)/">' row_str = str(row) archive = re.findall(archive_re, row_str) if len(archive) == 0: if first_row == True: sub_number = re.findall(sub_number_re, row_str) subtitle = re.findall(title_re, row_str) release = re.findall(release_re, row_str) disc_amount = re.findall(disc_amount_re, row_str) first_row = False else: file_size, SubHash = xbmc.subHashAndFileSize(file_original_path) if disc_amount[0] > '1': video_file_size = re.findall(video_file_size_re_multi, row_str) else: video_file_size = re.findall(video_file_size_re, row_str) if len(video_file_size) == 0: video_file_size.append('0') sync_value = False else: video_file_size = unicode(video_file_size[0], "UTF-8") video_file_size = video_file_size.replace(u"\u00A0", "") if file_size == video_file_size: sync_value = True else: sync_value = False rating = re.findall(rating_re, row_str) language = re.findall(lang_re, row_str) if len(language) > 0: first_row = True link = "%s%s/" % (down_url, sub_number[0]) log( __name__ ,"Subtitles found: %s %s (link=%s)" % (subtitle[0], release, link)) flag_pic = "flags/%s.gif" % (language[0]) lang = languageTranslate(language[0],2,0) if lang == lang1 or lang == lang2 or lang == lang3: for rel in re.findall("\'(.*?)\'", str(release)): rel = rel.replace(",",":").replace(" ","") if len(rel) > 1: rel_semicolon = "%s;" % (rel) for rel_sync in re.findall('(.+?);', rel_semicolon): if rel_sync.upper() in file_original_path.upper(): sync_value = True filename_release = "%s - %s" % (subtitle[0], rel_semicolon) rating_dot = rating[0].replace(",",".") if rating_dot == '0.00': sub_rating = '0' else: sub_rating = int(round(float(rating_dot) * 1.666,0)) if stack == False: if disc_amount[0] > '1': log( __name__ ,"Nonstacked video file - stacked subs") else: subtitles_list.append({'filename': filename_release, 'sync': sync_value, 'link': link, 'language_flag': flag_pic, 'language_name': lang,'rating': '%s' % (sub_rating)}) else: if disc_amount[0] > '1': subtitles_list.append({'filename': filename_release, 'sync': sync_value, 'link': link, 'language_flag': flag_pic, 'language_name': lang,'rating': '%s' % (sub_rating)}) else: log( __name__ ,"Stacked video file - nonstacked subs") else: continue else: continue