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
예제 #2
0
def Search(item):
    pn_server = PNServer()
    pn_server.Create()
    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: %s, SLhash:%s" %
            (item['OShash'], item['SLhash']))

    log(
        __scriptid__, "Search for [%s] by name" %
        (os.path.basename(item['file_original_path']), ))
    subtitles_list = pn_server.SearchSubtitlesWeb(item)
    return subtitles_list
예제 #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"])
            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)
예제 #4
0
def Download(params):
    pn_server = PNServer()
    pn_server.Create()
    url = pn_server.Download(params)
    return url