def Download(params):
    if xbmcvfs.exists(__temp__):
        shutil.rmtree(__temp__)
    xbmcvfs.mkdirs(__temp__)

    subtitle_list = []
    pn_server = PNServer()
    pn_server.Create()
    url = pn_server.Download(params)

    try:
        log(__scriptid__, "Extract using 'ZipFile' method")
        response = urllib2.urlopen(url)
        raw = response.read()
        archive = ZipFile(StringIO(raw), 'r')
        files = archive.namelist()
        files.sort()
        index = 1

        for file in files:
            contents = archive.read(file)
            extension = file[file.rfind('.') + 1:]

            if len(files) == 1:
                dest = os.path.join(__temp__,
                                    "%s.%s" % (str(uuid.uuid4()), extension))
            else:
                dest = os.path.join(
                    __temp__,
                    "%s.%d.%s" % (str(uuid.uuid4()), index, extension))

            f = open(dest, 'wb')
            f.write(contents)
            f.close()
            subtitle_list.append(dest)
            index += 1
    except:
        log(__scriptid__, "Extract using 'XBMC.Extract' method")
        exts = [".srt", ".sub", ".txt", ".smi", ".ssa", ".ass"]
        zip = os.path.join(__temp__, "PN.zip")
        ctx = ssl.SSLContext(ssl.PROTOCOL_TLS)
        ctx.set_ciphers('ALL:@SECLEVEL=1')
        f = urllib.urlopen(url, context=ctx)
        with open(zip, "wb") as subFile:
            subFile.write(f.read())
        subFile.close()
        xbmc.sleep(500)
        xbmc.executebuiltin(('XBMC.Extract("%s","%s")' % (
            zip,
            __temp__,
        )).encode('utf-8'), True)
        for subfile in xbmcvfs.listdir(zip)[1]:
            file = os.path.join(__temp__, subfile.decode('utf-8'))
            if (os.path.splitext(file)[1] in exts):
                subtitle_list.append(file)

    return subtitle_list
Exemplo n.º 2
0
def Download(params):
  if xbmcvfs.exists(__temp__):
    shutil.rmtree(__temp__)
  xbmcvfs.mkdirs(__temp__)

  subtitle_list = []
  pn_server = PNServer()
  pn_server.Create()
  url = pn_server.Download(params)

  try:
    log( __scriptid__ ,"Extract using 'ZipFile' method")
    response = urllib2.urlopen(url)
    raw = response.read()      
    archive = ZipFile(StringIO(raw), 'r')
    files = archive.namelist()
    files.sort()
    index = 1
    
    for file in files:
      contents = archive.read(file)
      extension = file[file.rfind('.') + 1:]

      if len(files) == 1:
        dest = os.path.join(__temp__, "%s.%s" %(str(uuid.uuid4()), extension))
      else:
        dest = os.path.join(__temp__, "%s.%d.%s" %(str(uuid.uuid4()), index, extension))
      
      f = open(dest, 'wb')
      f.write(contents)
      f.close()
      subtitle_list.append(dest)
      index += 1
  except:
    log( __scriptid__ ,"Extract using 'XBMC.Extract' method")
    exts = [".srt", ".sub", ".txt", ".smi", ".ssa", ".ass" ]
    zip = os.path.join( __temp__, "PN.zip")
    f = urllib.urlopen(url)
    with open(zip, "wb") as subFile:
      subFile.write(f.read())
    subFile.close()
    xbmc.sleep(500)
    xbmc.executebuiltin(('XBMC.Extract("%s","%s")' % (zip,__temp__,)).encode('utf-8'), True)
    for subfile in xbmcvfs.listdir(zip)[1]:
      file = os.path.join(__temp__, subfile.decode('utf-8'))
      if (os.path.splitext( file )[1] in exts):
        subtitle_list.append(file)

  return subtitle_list
Exemplo n.º 3
0
def Search( item ):

  pn_server = PNServer()
  pn_server.Create()  
  subtitles_list = []
  if item['temp'] : 
    item['OShash'] = "000000000000"
    item['SLhash'] = "000000000000"
  else:
    item['OShash'] = OpensubtitlesHash(item)
    item['SLhash'] = calculateSublightHash(item['file_original_path'])
    log( __scriptid__ ,"xbmc module OShash")

  log( __scriptid__ ,"Search for [%s] by name" % (os.path.basename( item['file_original_path'] ),))
  subtitles_list = pn_server.SearchSubtitlesWeb(item)
  if subtitles_list:
    for it in subtitles_list:
      listitem = xbmcgui.ListItem(label=it["language_name"],
                                  label2=it["filename"],
                                  iconImage=it["rating"],
                                  thumbnailImage=it["language_flag"]
                                  )

      listitem.setProperty( "sync", ("false", "true")[it["sync"]] )
      listitem.setProperty( "hearing_imp", ("false", "true")[it["hearing_imp"]] )
      
      url = "plugin://%s/?action=download&link=%s&filename=%s&movie_id=%s&season=%s&episode=%s&hash=%s&match=%s" %(__scriptid__,
                                                                                                                  it["link"],
                                                                                                                  it["filename"],
                                                                                                                  it["movie_id"],
                                                                                                                  it["season"],
                                                                                                                  it["episode"],
                                                                                                                  item['OShash'],
                                                                                                                  it["sync"]
                                                                                                                  )
      
      xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=url,listitem=listitem,isFolder=False)
Exemplo n.º 4
0
def Search(item):

    pn_server = PNServer()
    pn_server.Create()
    subtitles_list = []
    if item['temp']:
        item['OShash'] = "000000000000"
        item['SLhash'] = "000000000000"
    else:
        item['OShash'] = OpensubtitlesHash(item)
        item['SLhash'] = calculateSublightHash(item['file_original_path'])
        log(__scriptid__, "xbmc module OShash")

    log(
        __scriptid__, "Search for [%s] by name" %
        (os.path.basename(item['file_original_path']), ))
    subtitles_list = pn_server.SearchSubtitlesWeb(item)
    if subtitles_list:
        for it in subtitles_list:
            listitem = xbmcgui.ListItem(label=it["language_name"],
                                        label2=it["filename"])
            listitem.setArt({
                "icon": it["rating"],
                "thumb": it["language_flag"]
            })
            listitem.setProperty("sync", ("false", "true")[it["sync"]])
            listitem.setProperty("hearing_imp",
                                 ("false", "true")[it["hearing_imp"]])

            url = "plugin://%s/?action=download&link=%s&filename=%s&movie_id=%s&season=%s&episode=%s&hash=%s&match=%s" % (
                __scriptid__, it["link"], it["filename"], it["movie_id"],
                it["season"], it["episode"], item['OShash'], it["sync"])

            xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),
                                        url=url,
                                        listitem=listitem,
                                        isFolder=False)
Exemplo n.º 5
0
    if (params[len(params)-1]=='/'):
      params=params[0:len(params)-2]
    pairsofparams=cleanedparams.split('&')
    param={}
    for i in range(len(pairsofparams)):
      splitparams={}
      splitparams=pairsofparams[i].split('=')
      if (len(splitparams))==2:
        param[splitparams[0]]=splitparams[1]
                                
  return param

params = get_params()

if params['action'] == 'search':
  log( __scriptid__, "action 'search' called")
  item = {}
  item['temp']               = False
  item['rar']                = False
  item['year']               = xbmc.getInfoLabel("VideoPlayer.Year")                         # Year
  item['season']             = str(xbmc.getInfoLabel("VideoPlayer.Season"))                  # Season
  item['episode']            = str(xbmc.getInfoLabel("VideoPlayer.Episode"))                 # Episode
  item['tvshow']             = normalizeString(xbmc.getInfoLabel("VideoPlayer.TVshowtitle"))  # Show
  item['title']              = normalizeString(xbmc.getInfoLabel("VideoPlayer.OriginalTitle"))# try to get original title
  item['file_original_path'] = urllib.unquote(xbmc.Player().getPlayingFile().decode('utf-8'))# Full path of a playing file
  item['3let_language']      = [] #['scc','eng']
  
  for lang in urllib.unquote(params['languages']).decode('utf-8').split(","):
    item['3let_language'].append(languageTranslate(lang,0,1))
  
  if item['title'] == "":
Exemplo n.º 6
0
            params = params[0:len(params) - 2]
        pairsofparams = cleanedparams.split('&')
        param = {}
        for i in range(len(pairsofparams)):
            splitparams = {}
            splitparams = pairsofparams[i].split('=')
            if (len(splitparams)) == 2:
                param[splitparams[0]] = splitparams[1]

    return param


params = get_params()

if params['action'] == 'search':
    log(__scriptid__, "action 'search' called")
    item = {}
    item['temp'] = False
    item['rar'] = False
    item['year'] = xbmc.getInfoLabel("VideoPlayer.Premiered")  # Year
    item['season'] = str(xbmc.getInfoLabel("VideoPlayer.Season"))  # Season
    item['episode'] = str(xbmc.getInfoLabel("VideoPlayer.Episode"))  # Episode
    item['tvshow'] = normalizeString(
        xbmc.getInfoLabel("VideoPlayer.TVshowtitle"))  # Show
    item['title'] = normalizeString(
        xbmc.getInfoLabel(
            "VideoPlayer.OriginalTitle"))  # try to get original title
    item['file_original_path'] = urllib.unquote(
        xbmc.Player().getPlayingFile().decode(
            'utf-8'))  # Full path of a playing file
    item['3let_language'] = []  #['scc','eng']