def convertSubtitles(self, code=127, encoding=""):
        encoding = MapUcharEncoding(encoding)
        if 0 != code or 'unknown' in encoding:
            encoding = 'utf-8'
        else:
            encoding = encoding.strip()
        try:
            with codecs.open(self.downloader.getFullFileName(), 'r', encoding,
                             'replace') as fp:
                subText = fp.read().encode('utf-8').strip()

            ext = self.currItem.get('format', '')
            if ext == '':
                ext = self.currItem.get('url',
                                        '').split('?')[-1].split('.')[-1]
            filePath = '{0}_{1}_{2}'.format(self.params['movie_title'],
                                            self.currItem.get('title', ''),
                                            self.currItem.get('lang', ''))
            filePath = RemoveDisallowedFilenameChars(filePath)
            filePath += '.' + ext

            with open(GetSubtitlesDir(filePath), 'w') as fp:
                fp.write(subText)

            self.downloadedSubFilePath = GetSubtitlesDir(filePath)
            self.showButtons(['green'])
            tmpList = self.params.get('sub_list', [])
            if len(tmpList) == 1:
                self.acceptSub()
        except Exception:
            printExc()
            self["console"].setText(_('Subtitles conversion to UTF-8 failed.'))
示例#2
0
    def _getFileName(self, title, lang, subId, imdbid):
        title = RemoveDisallowedFilenameChars(title).replace('_', '.')
        match = re.search(r'[^.]', title)
        if match: title = title[match.start():]

        fileName = "{0}_{1}_0_{2}_{3}".format(title, lang, subId, imdbid)
        fileName = fileName + '.srt'
        return fileName
 def _getSubtitleNapisy24Title(self, item):
     title = '[Napisy24.pl] %s.%s.%s.' % (item.get('title', ''), item.get('altTitle', ''), item.get('year', ''))
     title += item.get('resolution', '')
     
     cd = item.get('cd', '1')
     title += ' CD[{0}]'.format(cd)
     
     time = item.get('time', '')
     if '' != time: title += ' [{0}]'.format(time)
     
     return RemoveDisallowedFilenameChars(title)
示例#4
0
 def __init__(self, host="", title="", filePath=""):
     printDBG(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>... [%s]\n" % self.META_DATA)
     localPrintDBG("IPTVMovieMetaDataHandler.__init__ host[%s], title[%s], filePath[%s]" % (host, title, filePath))
     if "" != host:
         fileName = "{0}_{1}.{2}".format(host, title, self.EXTENSION)
     else:
         fileName = filePath.split('/')[-1]+'.' + self.EXTENSION
     
     self.filePath = GetMovieMetaDataDir( RemoveDisallowedFilenameChars( fileName ) )
     self.data = deepcopy( self.META_DATA )
     self.data.update( {"host":host, "title":title, "file_path":filePath} )
     self.isModified = False
示例#5
0
    def _getSubtitleTitle(self, item):
        title = item.get('MovieReleaseName', '')
        if '' == title: title = item.get('SubFileName', '')
        if '' == title: title = item.get('MovieName', '')

        cdMax = item.get('SubSumCD', '1')
        cd = item.get('SubActualCD', '1')
        if cdMax != '1': title += ' CD[{0}/{1}]'.format(cdMax, cd)

        lastTime = item.get('SubLastTS', '')
        if '' != lastTime: title += ' [{0}]'.format(lastTime)

        return RemoveDisallowedFilenameChars(title)