def listSubtitlesProviders(self): printDBG("IPTVSubDownloaderWidget.listSubtitlesProviders") subProvidersList = [] napisy24pl = {'title': _("Napisy24.pl"), 'sub_provider': 'napisy24pl'} openSubtitles = { 'title': _("OpenSubtitles.org"), 'sub_provider': 'opensubtitlesorg' } napiprojektpl = { 'title': _("Napiprojekt.pl"), 'sub_provider': 'napiprojektpl' } titlovi = {'title': _("Titlovi.com"), 'sub_provider': 'titlovicom'} subscene = {'title': _("Subscene.com"), 'sub_provider': 'subscenecom'} youtube = {'title': _("Youtube.com"), 'sub_provider': 'youtubecom'} if 'youtube_id' in self.params['url_params'] and '' != self.params[ 'url_params']['youtube_id']: subProvidersList.append(youtube) if 'pl' == GetDefaultLang(): subProvidersList.append(napisy24pl) if IsSubtitlesParserExtensionCanBeUsed(): subProvidersList.append(napiprojektpl) subProvidersList.append(openSubtitles) subProvidersList.append(titlovi) subProvidersList.append(subscene) if 'pl' != GetDefaultLang(): subProvidersList.append(napisy24pl) if IsSubtitlesParserExtensionCanBeUsed(): subProvidersList.append(napiprojektpl) self.currList = [] for item in subProvidersList: params = CDisplayListItem(item['title'], item.get('desc', ''), CDisplayListItem.TYPE_SUB_PROVIDER) params.privateData = {'sub_provider': item['sub_provider']} self.currList.append(params) idx = 0 selIndex = 0 for idx in range(len(self.currList)): if self.hostName == self.currList[idx].privateData['sub_provider']: selIndex = idx break self["list"].setList([(x, ) for x in self.currList]) #restor previus selection if len(self.currList) > selIndex: self["list"].moveToIndex(selIndex) self.changeBottomPanel() self["headertext"].setText(self.getCategoryPath()) self["statustext"].setText("") self["list"].show()
def getSupportedFormats(): printDBG("getSupportedFormats") if IsSubtitlesParserExtensionCanBeUsed(): printDBG("getSupportedFormats after import") return ['srt', 'vtt', 'mpl', 'ssa', 'smi', 'rt', 'txt', 'sub', 'dks', 'jss', 'psb', 'ttml'] printDBG("getSupportedFormats end") return IPTVSubtitlesHandler.SUPPORTED_FORMATS
def loadSubtitles(self, filePath, encoding='utf-8', fps=0): printDBG("OpenSubOrg.loadSubtitles filePath[%s]" % filePath) # try load subtitles using C-library try: if IsSubtitlesParserExtensionCanBeUsed(): try: if fps <= 0: filename, file_extension = os_path.splitext(filePath) tmp = CParsingHelper.getSearchGroups( filename.upper() + '_', '_FPS([0-9.]+)_')[0] if '' != tmp: fps = float(tmp) except Exception: printExc() from Plugins.Extensions.IPTVPlayer.libs.iptvsubparser import _subparser as subparser with codecs.open(filePath, 'r', encoding, 'replace') as fp: subText = fp.read().encode('utf-8') # if in subtitles will be line {1}{1}f_fps # for example {1}{1}23.976 and we set microsecperframe = 0 # then microsecperframe will be calculated as follow: llroundf(1000000.f / f_fps) if fps > 0: microsecperframe = int(1000000.0 / fps) else: microsecperframe = 0 # calc end time if needed - optional, default True setEndTime = True # characters per second - optional, default 12, can not be set to 0 CPS = 12 # words per minute - optional, default 138, can not be set to 0 WPM = 138 # remove format tags, like <i> - optional, default True removeTags = True subsObj = subparser.parse(subText, microsecperframe, removeTags, setEndTime, CPS, WPM) if 'type' in subsObj: self.subAtoms = subsObj['list'] # Workaround start try: printDBG( 'Workaround for subtitles from Das Erste: %s' % self.subAtoms[0]['start']) if len(self.subAtoms ) and self.subAtoms[0]['start'] >= 36000000: for idx in range(len(self.subAtoms)): for key in ['start', 'end']: if key not in self.subAtoms[idx]: continue if self.subAtoms[idx][key] >= 36000000: self.subAtoms[idx][key] -= 36000000 except Exception: printExc() # workaround end self._fillPailsOfAtoms() return True else: return False except Exception: printExc() return self._loadSubtitles(filePath, encoding)
def downloadSubtitleFile(self, cItem): printDBG("NapiProjektProvider.downloadSubtitleFile") retData = {} title = cItem['title'] lang = cItem.get('lang', 'pl') subId = cItem['sub_id'] imdbid = cItem['imdbid'] fps = cItem.get('fps', 0) post_data = { "mode": "32770", "client": "pynapi", "client_ver": "0.1", "VideoFileInfoID": subId } url = self.getFullUrl('api/api-napiprojekt3.php') sts, data = self.cm.getPage(url, self.defaultParams, post_data) if not sts: return retData fps = self.cm.ph.getDataBeetwenMarkers(data, '<fps>', '</fps>', False)[1] try: fps = float(fps.strip()) except Exception: fps = 0 post_data = { "downloaded_subtitles_id": subId, "mode": "1", "client": "pynapi", "client_ver": "0.1", "downloaded_subtitles_lang": lang.upper(), "downloaded_subtitles_txt": "1" } url = self.getFullUrl('api/api-napiprojekt3.php') sts, data = self.cm.getPage(url, self.defaultParams, post_data) if not sts: return retData data = self.cm.ph.getDataBeetwenMarkers(data, '<content><![CDATA[', ']]></content>', False)[1] try: data = base64.b64decode(data) if IsSubtitlesParserExtensionCanBeUsed(): from Plugins.Extensions.IPTVPlayer.libs.iptvsubparser import _subparser as subparser subsObj = subparser.parse(data, 0, False, False) typeExtMap = { 'microdvd': 'sub', 'subrip': 'srt', 'subviewer': 'sub', 'ssa1': 'ssa', 'ssa2-4': 'ssa', 'ass': 'ssa', 'vplayer': 'txt', 'sami': 'smi', 'mpl2': 'mpl', 'aqt': 'aqt', 'pjs': 'pjs', 'mpsub': 'sub', 'jacosub': 'jss', 'psb': 'psb', 'realtext': 'rt', 'dks': 'dks', 'subviewer1': 'sub', 'text/vtt': 'vtt', 'sbv': 'sbv' } ext = typeExtMap.get(subsObj['type'], '') if ext == '': SetIPTVPlayerLastHostError( _('Unknown subtitle parser for format "%s".') % subsObj['type']) return retData tmpFile = GetTmpDir(self.TMP_FILE_NAME) if not self.writeFile(tmpFile, data): return retData fileName = self._getFileName(title, lang, subId, imdbid, fps, ext) fileName = GetSubtitlesDir(fileName) if not self.converFileToUtf8(tmpFile, fileName): rm(tmpFile) return retData retData = { 'title': title, 'path': fileName, 'lang': lang, 'imdbid': imdbid, 'sub_id': subId } except Exception: printExc() return retData return retData
def listSubtitlesProviders(self): printDBG("IPTVSubDownloaderWidget.listSubtitlesProviders") subProvidersList = [] napisy24pl = {'title': "Napisy24.pl", 'sub_provider': 'napisy24pl'} openSubtitles = {'title': "OpenSubtitles.org API", 'sub_provider': 'opensubtitlesorg'} openSubtitles2 = {'title': "OpenSubtitles.org WWW", 'sub_provider': 'opensubtitlesorg2'} openSubtitles3 = {'title': "OpenSubtitles.org REST", 'sub_provider': 'opensubtitlesorg3'} napiprojektpl = {'title': "Napiprojekt.pl", 'sub_provider': 'napiprojektpl'} podnapisinet = {'title': "Podnapisi.net", 'sub_provider': 'podnapisinet'} titlovi = {'title': "Titlovi.com", 'sub_provider': 'titlovicom'} subscene = {'title': "Subscene.com", 'sub_provider': 'subscenecom'} youtube = {'title': "Youtube.com", 'sub_provider': 'youtubecom'} popcornsubtitles = {'title': "PopcornSubtitles.com", 'sub_provider': 'popcornsubtitles'} subtitlesgr = {'title': "Subtitles.gr", 'sub_provider': 'subtitlesgr'} prijevodi = {'title': "Prijevodi-Online.org", 'sub_provider': 'prijevodi'} subsro = {'title': "Subs.ro", 'sub_provider': 'subsro'} defaultLang = GetDefaultLang() if 'youtube_id' in self.params['url_params'] and '' != self.params['url_params']['youtube_id']: subProvidersList.append(youtube) if 'popcornsubtitles_url' in self.params['url_params'] and '' != self.params['url_params']['popcornsubtitles_url']: subProvidersList.append(popcornsubtitles) if 'hr' == defaultLang: subProvidersList.append(prijevodi) if 'el' == defaultLang: subProvidersList.append(subtitlesgr) if 'ro' == defaultLang: subProvidersList.append(subsro) if 'pl' == defaultLang: subProvidersList.append(napisy24pl) if IsSubtitlesParserExtensionCanBeUsed(): subProvidersList.append(napiprojektpl) subProvidersList.append(openSubtitles2) subProvidersList.append(openSubtitles3) subProvidersList.append(openSubtitles) subProvidersList.append(podnapisinet) subProvidersList.append(titlovi) subProvidersList.append(subscene) if 'pl' != defaultLang: subProvidersList.append(napisy24pl) if IsSubtitlesParserExtensionCanBeUsed(): subProvidersList.append(napiprojektpl) if 'el' != defaultLang: subProvidersList.append(subtitlesgr) if 'hr' != defaultLang: subProvidersList.append(prijevodi) if 'ro' != defaultLang: subProvidersList.append(subsro) self.currList = [] for item in subProvidersList: params = CDisplayListItem(item['title'], item.get('desc', ''), CDisplayListItem.TYPE_SUB_PROVIDER) params.privateData = {'sub_provider': item['sub_provider']} self.currList.append(params) idx = 0 selIndex = 0 for idx in range(len(self.currList)): if self.hostName == self.currList[idx].privateData['sub_provider']: selIndex = idx break self["list"].setList([(x,) for x in self.currList]) #restor previus selection if len(self.currList) > selIndex: self["list"].moveToIndex(selIndex) self.changeBottomPanel() self["headertext"].setText(self.getCategoryPath()) self["statustext"].setText("") self["list"].show()