Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

[1efa53]: script.xbmc.subtitles / resources / lib / services / OpenSubtitles / service.py Maximize Restore History

Download this file

service.py    103 lines (73 with data), 3.2 kB

  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
import sys
import os
from utilities import hashFile, LOG, LOG_INFO
from os_utilities import OSDBServer
_ = sys.modules[ "__main__" ].__language__
__settings__ = sys.modules[ "__main__" ].__settings__
STATUS_LABEL = 100
LOADING_IMAGE = 110
SUBTITLES_LIST = 120
def timeout(func, args=(), kwargs={}, timeout_duration=10, default=None):
import threading
class InterruptableThread(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
self.result = "000000000000"
def run(self):
self.result = func(*args, **kwargs)
it = InterruptableThread()
it.start()
it.join(timeout_duration)
if it.isAlive():
return it.result
else:
return it.result
def set_filehash(path,rar):
if rar:
path = os.path.dirname( path )
file_hash = hashFile(path)
return file_hash
def search_subtitles( file_original_path, title, tvshow, year, season, episode, debug, set_temp, rar, lang1, lang2, lang3 ): #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) == "":
import xbmc # Not in Library
title, year = xbmc.getCleanMovieTitle( title )
else: # Movie in Library
year = year
title = title
OS_search_string = title.replace(" ","+")
if debug : LOG( LOG_INFO, "OpenSubtitles Search String [ %s ]" % OS_search_string )
if set_temp :
hash_search = False
file_size = "000000000"
hashTry = "000000000000"
else:
hashTry = timeout(set_filehash, args=(file_original_path, rar), timeout_duration=5)
try: file_size = os.path.getsize( file_original_path )
except: file_size = "000000000"
if file_size != "" and hashTry != "":
hash_search = True
if debug :
print "File Size [%s]" % file_size
print "File Hash [%s]" % hashTry
try:
if debug : LOG( LOG_INFO, "Search by hash and name %s" % os.path.basename( file_original_path ) )
subtitles_list = osdb_server.searchsubtitles( OS_search_string, lang1, lang2, lang3, hash_search, debug, hashTry, file_size )
return subtitles_list, "" #standard output
except :
return subtitles_list, "" #standard output
def download_subtitles (subtitles_list, pos, zip_subs, tmp_sub_dir, sub_folder, session_id): #standard input
import urllib
f = urllib.urlopen(subtitles_list[pos][ "link" ])
local_file = open(zip_subs, "w" + "b")
local_file.write(f.read())
local_file.close()
language = subtitles_list[pos][ "language_name" ]
return True,language, "" #standard output