Esempio n. 1
0
def Download(link, filename):
    subtitle_list = []
    exts = [".srt", ".sub", ".txt", ".smi", ".ssa", ".ass"]

    if link:
        log(__name__, "Downloadlink %s" % link)

        class MyOpener(urllib.FancyURLopener):
            version = "User-Agent=Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36"

            def __init__(self, *args):
                urllib.FancyURLopener.__init__(self, *args)

        if settings.getSetting('PROXY') == 'true':
            proxy = {
                settings.getSetting('PROXY_PROTOCOL'):
                settings.getSetting('PROXY_PROTOCOL') + '://' +
                settings.getSetting('PROXY_HOST') + ':' +
                settings.getSetting('PROXY_PORT')
            }
            my_urlopener = MyOpener(proxy)
        else:
            my_urlopener = MyOpener()

        my_urlopener.addheader('Referer', link)
        log(
            __name__,
            "Fetching subtitles using url '%s' with referer header '%s'" %
            (link, link))
        response = my_urlopener.open(link)

        local_tmp_file = os.path.join(__temp__, "sub.srt")

        if xbmcvfs.exists(__temp__):
            shutil.rmtree(__temp__)
        xbmcvfs.mkdirs(__temp__)
        try:
            log(__name__, "Saving subtitles to '%s'" % local_tmp_file)
            local_file_handle = open(local_tmp_file, "wb")
            local_file_handle.write(response.read())
            local_file_handle.close()

            subtitle_list.append(local_tmp_file)
            log(__name__, "=== returning subtitle file %s" % file)

        except:
            log(__name__, "Failed to save subtitle to %s" % local_tmp_file)

    return subtitle_list
def Download(link, filename):
  subtitle_list = []
  exts = [".srt", ".sub", ".txt", ".smi", ".ssa", ".ass"]

  if link:
    log(__name__, "Downloadlink %s" % link)

    class MyOpener(urllib.FancyURLopener):
      version = "User-Agent=Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.86 Safari/537.36"
      def __init__(self, *args):
        urllib.FancyURLopener.__init__(self, *args)

    if settings.getSetting('PROXY') == 'true':
      proxy = {settings.getSetting('PROXY_PROTOCOL') : settings.getSetting('PROXY_PROTOCOL') + '://' + settings.getSetting('PROXY_HOST') + ':' + settings.getSetting('PROXY_PORT')}
      my_urlopener = MyOpener(proxy)
    else:
      my_urlopener = MyOpener()

    my_urlopener.addheader('Referer', link)
    log(__name__, "Fetching subtitles using url '%s' with referer header '%s'" % (link, link))
    response = my_urlopener.open(link)

    local_tmp_file = os.path.join(__temp__, "sub.srt")
    
    if xbmcvfs.exists(__temp__):
      shutil.rmtree(__temp__)
    xbmcvfs.mkdirs(__temp__)
    try:
      log(__name__, "Saving subtitles to '%s'" % local_tmp_file)
      local_file_handle = open(local_tmp_file, "wb")
      local_file_handle.write(response.read())
      local_file_handle.close()
      
      subtitle_list.append(local_tmp_file)
      log(__name__, "=== returning subtitle file %s" % file)

    except:
      log(__name__, "Failed to save subtitle to %s" % local_tmp_file)

  return subtitle_list
    item['episode'] = item['episode'][-1:]

  if ( item['file_original_path'].find("http") > -1 ):
    item['temp'] = True

  elif ( item['file_original_path'].find("rar://") > -1 ):
    item['rar']  = True
    item['file_original_path'] = os.path.dirname(item['file_original_path'][6:])

  elif ( item['file_original_path'].find("stack://") > -1 ):
    stackPath = item['file_original_path'].split(" , ")
    item['file_original_path'] = stackPath[0][8:]

  # required if tvshow is not indexed/recognized in library
  if item['tvshow'] == "":  
    log(__name__, "item %s" % item)
    # replace dots with spaces in title
    titulo = re.sub(r'\.', ' ', item['title'])
    log(__name__, "title no dots: %s" % titulo)
    mo = re.search(r'(.*)[sS](\d+)[eE](\d+)', titulo) #S01E02 like
    if not mo:
      mo = re.search(r'(.*)(\d\d)[xX](\d+)', titulo) # old 10x02 style
    if not mo:
      mo = re.search(r'(.*)(\d)[xX](\d+)', titulo) # old 1x02 style
    if not mo:
      mo = re.search(r'(.*) (\d+)(\d\d)', titulo) # 102 style 
    # split title in tvshow, season and episode
    if mo:
      item['tvshow'] = mo.group(1)
      item['season'] = mo.group(2)
      item['episode'] = mo.group(3)
Esempio n. 4
0
    if (item['file_original_path'].find("http") > -1):
        item['temp'] = True

    elif (item['file_original_path'].find("rar://") > -1):
        item['rar'] = True
        item['file_original_path'] = os.path.dirname(
            item['file_original_path'][6:])

    elif (item['file_original_path'].find("stack://") > -1):
        stackPath = item['file_original_path'].split(" , ")
        item['file_original_path'] = stackPath[0][8:]

    # required if tvshow is not indexed/recognized in library
    if item['tvshow'] == "":
        log(__name__, "item %s" % item)
        # replace dots with spaces in title
        titulo = re.sub(r'\.', ' ', item['title'])
        log(__name__, "title no dots: %s" % titulo)
        mo = re.search(r'(.*)[sS](\d+)[eE](\d+)', titulo)  #S01E02 like
        if not mo:
            mo = re.search(r'(.*)(\d\d)[xX](\d+)', titulo)  # old 10x02 style
        if not mo:
            mo = re.search(r'(.*)(\d)[xX](\d+)', titulo)  # old 1x02 style
        if not mo:
            mo = re.search(r'(.*) (\d+)(\d\d)', titulo)  # 102 style
        # split title in tvshow, season and episode
        if mo:
            item['tvshow'] = mo.group(1)
            item['season'] = mo.group(2)
            item['episode'] = mo.group(3)