def convertSubIdxToSrt(vobsubData,idxData,language='en'): vobsubPath = apppath.vobsub2srt() if vobsubPath is None: return None tmpSubFile = os.path.join(apppath.pathTemporary('caption'),'subtitle.sub') tmpIdxFile = os.path.join(apppath.pathTemporary('caption'),'subtitle.idx') tmpSrtFile = os.path.join(apppath.pathTemporary('caption'),'subtitle.srt') if os.path.exists(tmpSubFile): os.remove(tmpSubFile) if os.path.exists(tmpIdxFile): os.remove(tmpIdxFile) if os.path.exists(tmpSrtFile): os.remove(tmpSrtFile) fSub = open(tmpSubFile,'w') fSub.write(vobsubData) fSub.close() if idxData is not None: fIdx = open(tmpIdxFile,'w') fIdx.write(idxData) fIdx.close() #TODO vobsub2srt complains about language codes language = 'en' cmdargs = [vobsubPath,'--lang',language,tmpSubFile.split('.')[0]] logging.debug('Running command: ' + ' '.join(cmdargs)) cmd = subprocess.Popen(cmdargs,stdout=subprocess.PIPE, stderr=subprocess.PIPE) cmd.wait() response = cmd.communicate() srtData = None if os.path.exists(tmpSrtFile): fSrt = open(tmpSrtFile) srtData = fSrt.read() fSrt.close() logging.debug('Succesfully converted to srt file: ' + str(tmpSrtFile) + ', size(' + str(len(srtData)) +')') os.remove(tmpSrtFile) else: logging.warn('Failed to convert sub file to srt file: ' + str(response)) if os.path.exists(tmpSubFile): os.remove(tmpSubFile) if os.path.exists(tmpIdxFile): os.remove(tmpIdxFile) return srtData
def convertSup2SubIdx(pgsData): if pgsData is None: logging.error('No PGS data given') return None pgsPath = apppath.BDSup2Sub() assert (pgsPath) tmpSupFile = os.path.join(apppath.pathTemporary('caption'), 'subtitle.sup') tmpSubFile = os.path.join(apppath.pathTemporary('caption'), 'subtitle.sub') tmpIdxFile = os.path.join(apppath.pathTemporary('caption'), 'subtitle.idx') if os.path.exists(tmpSupFile): os.remove(tmpSupFile) fSup = open(tmpSupFile, 'w') fSup.write(pgsData) fSup.close() if os.path.exists(tmpSubFile): os.remove(tmpSubFile) if os.path.exists(tmpIdxFile): os.remove(tmpIdxFile) cmdargs = [pgsPath, '-o', tmpSubFile, tmpSupFile] logging.debug('Running command: ' + ' '.join(cmdargs)) cmd = subprocess.Popen(cmdargs, stdout=subprocess.PIPE, stderr=subprocess.PIPE) response = cmd.communicate() subData = None idxData = None if os.path.exists(tmpSubFile): logging.debug('Succesfully converted to sub file: ' + tmpSubFile) fSub = open(tmpSubFile) subData = fSub.read() fSub.close() os.remove(tmpSubFile) if os.path.exists(tmpIdxFile): logging.debug('Succesfully converted to idx file: ' + tmpIdxFile) fIdx = open(tmpIdxFile) idxData = fIdx.read() fIdx.close() os.remove(tmpIdxFile) if os.path.exists(tmpSupFile): os.remove(tmpSupFile) return [subData, idxData]
def convertSup2SubIdx(pgsData): if pgsData is None: logging.error('No PGS data given') return None pgsPath = apppath.BDSup2Sub() assert(pgsPath) tmpSupFile = os.path.join(apppath.pathTemporary('caption'),'subtitle.sup') tmpSubFile = os.path.join(apppath.pathTemporary('caption'),'subtitle.sub') tmpIdxFile = os.path.join(apppath.pathTemporary('caption'),'subtitle.idx') if os.path.exists(tmpSupFile): os.remove(tmpSupFile) fSup = open(tmpSupFile,'w') fSup.write(pgsData) fSup.close() if os.path.exists(tmpSubFile): os.remove(tmpSubFile) if os.path.exists(tmpIdxFile): os.remove(tmpIdxFile) cmdargs = [pgsPath,'-o',tmpSubFile,tmpSupFile] logging.debug('Running command: ' + ' '.join(cmdargs)) cmd = subprocess.Popen(cmdargs,stdout=subprocess.PIPE, stderr=subprocess.PIPE) response = cmd.communicate() subData = None idxData = None if os.path.exists(tmpSubFile): logging.debug('Succesfully converted to sub file: ' + tmpSubFile) fSub = open(tmpSubFile) subData = fSub.read() fSub.close() os.remove(tmpSubFile) if os.path.exists(tmpIdxFile): logging.debug('Succesfully converted to idx file: ' + tmpIdxFile) fIdx = open(tmpIdxFile) idxData = fIdx.read() fIdx.close() os.remove(tmpIdxFile) if os.path.exists(tmpSupFile): os.remove(tmpSupFile) return [subData,idxData]
def pgsDataForTrackNumber(self,trackNumber): tmpDir = apppath.pathTemporary('disk_track') pgsFile = os.path.join(tmpDir,'tmpFile.sup') if os.path.exists(pgsFile): os.remove(pgsFile) cmdargs = [apppath.mkvextract(),'tracks',self.filepath,str(trackNumber)+':'+pgsFile] logging.debug('Running command ' + ' '.join(cmdargs)) cmd = subprocess.Popen(cmdargs,stdout=subprocess.PIPE, stderr=subprocess.PIPE) response = cmd.communicate() pgsdata = None if os.path.exists(pgsFile): logging.debug('Found pgs file ' + pgsFile) fPgs = open(pgsFile,'r') pgsdata = fPgs.read() assert(len(pgsdata)>0) fPgs.close() else: logging.error('Failed to find PGS file ' + str(pgsFile)) return pgsdata
def vobsubDataForTrackNumber(self,trackNumber): tmpDir = apppath.pathTemporary('disk_track') vobsubFile = os.path.join(tmpDir,'tmpFile.sub') if os.path.exists(vobsubFile): os.remove(vobsubFile) idxFile = os.path.join(tmpDir,'tmpFile.idx') if os.path.exists(idxFile): os.remove(idxFile) cmdargs = [apppath.mkvextract(),'tracks',self.filepath,str(trackNumber)+':'+vobsubFile] logging.debug('Running command ' + ' '.join(cmdargs)) cmd = subprocess.Popen(cmdargs,stdout=subprocess.PIPE, stderr=subprocess.PIPE) # cmd.wait() response = cmd.communicate() vobsubdata = None idxdata = None if os.path.exists(vobsubFile) and os.path.exists(idxFile): logging.debug('Found vob sub file ' + vobsubFile) fSub = open(vobsubFile,'r') vobsubdata = fSub.read() fSub.close() fIdx = open(idxFile,'r') idxdata = fIdx.read() fIdx.close() else: logging.error('Failed to find vobsub file ' + str(vobsubFile)) return [vobsubdata,idxdata]
def __init__(self, params): self.temporaryDirectory = apppath.pathTemporary('audionotify') self.pathSoundClipBackupStarted = None if params['audionotify_url_backupstarted']: url = params['audionotify_url_backupstarted'] self.pathSoundClipBackupStarted = os.path.join( self.temporaryDirectory, 'audionotify_url_backupstarted') if not os.path.isfile(self.pathSoundClipBackupStarted): AudioNotify._loadSoundUrlToFile( url, self.pathSoundClipBackupStarted) self.pathSoundClipBackupFinished = None if params['audionotify_url_backupfinished']: url = params['audionotify_url_backupfinished'] self.pathSoundClipBackupFinished = os.path.join( self.temporaryDirectory, 'audionotify_url_backupfinished') if not os.path.isfile(self.pathSoundClipBackupFinished): AudioNotify._loadSoundUrlToFile( url, self.pathSoundClipBackupFinished) self.pathSoundClipRipStarted = None if params['audionotify_url_ripstarted']: url = params['audionotify_url_ripstarted'] self.pathSoundClipRipStarted = os.path.join( self.temporaryDirectory, 'audionotify_url_ripstarted') if not os.path.isfile(self.pathSoundClipRipStarted): AudioNotify._loadSoundUrlToFile(url, self.pathSoundClipRipStarted) self.pathSoundClipRipFinished = None if params['audionotify_url_ripfinished']: url = params['audionotify_url_ripfinished'] self.pathSoundClipRipFinished = os.path.join( self.temporaryDirectory, 'audionotify_url_ripfinished') if not os.path.isfile(self.pathSoundClipRipFinished): AudioNotify._loadSoundUrlToFile(url, self.pathSoundClipRipFinished) if params['audionotify_url_error']: url = params['audionotify_url_error'] self.pathSoundClipError = os.path.join(self.temporaryDirectory, 'audionotify_url_error') if not os.path.isfile(self.pathSoundClipError): AudioNotify._loadSoundUrlToFile(url, self.pathSoundClipError) logging.debug('AudioNotify initialized with config: ' + str(params))
def ripPathCompleteForContentType(config,contentType): if str(contentType) == 'movie': ripPathComplete = config['ripper']['movie_complete_save_path'] elif str(contentType) == 'tvshow' or str(contentType) == 'tvepisode': ripPathComplete = config['ripper']['tv_complete_save_path'] else: if not contentType: contentType = 'Unknown' ripPathComplete = os.path.join(apppath.pathTemporary(),contentType) return ripPathComplete
def ripPathCompleteForContentType(config, contentType): if str(contentType) == 'movie': ripPathComplete = config['ripper']['movie_complete_save_path'] elif str(contentType) == 'tvshow' or str(contentType) == 'tvepisode': ripPathComplete = config['ripper']['tv_complete_save_path'] else: if not contentType: contentType = 'Unknown' ripPathComplete = os.path.join(apppath.pathTemporary(), contentType) return ripPathComplete
def ripPathCompleteForContentType(config, contentType): if str(contentType) == "movie": ripPathComplete = config["ripper"]["movie_complete_save_path"] elif str(contentType) == "tvshow" or str(contentType) == "tvepisode": ripPathComplete = config["ripper"]["tv_complete_save_path"] else: if not contentType: contentType = "Unknown" ripPathComplete = os.path.join(apppath.pathTemporary(), contentType) return ripPathComplete
def __init__(self,params): self.temporaryDirectory = apppath.pathTemporary('audionotify') self.pathSoundClipBackupStarted = None if params['audionotify_url_backupstarted']: url = params['audionotify_url_backupstarted'] self.pathSoundClipBackupStarted = os.path.join(self.temporaryDirectory,'audionotify_url_backupstarted') if not os.path.isfile(self.pathSoundClipBackupStarted): AudioNotify._loadSoundUrlToFile(url,self.pathSoundClipBackupStarted) self.pathSoundClipBackupFinished = None if params['audionotify_url_backupfinished']: url = params['audionotify_url_backupfinished'] self.pathSoundClipBackupFinished = os.path.join(self.temporaryDirectory,'audionotify_url_backupfinished') if not os.path.isfile(self.pathSoundClipBackupFinished): AudioNotify._loadSoundUrlToFile(url,self.pathSoundClipBackupFinished) self.pathSoundClipRipStarted = None if params['audionotify_url_ripstarted']: url = params['audionotify_url_ripstarted'] self.pathSoundClipRipStarted = os.path.join(self.temporaryDirectory,'audionotify_url_ripstarted') if not os.path.isfile(self.pathSoundClipRipStarted): AudioNotify._loadSoundUrlToFile(url,self.pathSoundClipRipStarted) self.pathSoundClipRipFinished = None if params['audionotify_url_ripfinished']: url = params['audionotify_url_ripfinished'] self.pathSoundClipRipFinished = os.path.join(self.temporaryDirectory,'audionotify_url_ripfinished') if not os.path.isfile(self.pathSoundClipRipFinished): AudioNotify._loadSoundUrlToFile(url,self.pathSoundClipRipFinished) if params['audionotify_url_error']: url = params['audionotify_url_error'] self.pathSoundClipError = os.path.join(self.temporaryDirectory,'audionotify_url_error') if not os.path.isfile(self.pathSoundClipError): AudioNotify._loadSoundUrlToFile(url,self.pathSoundClipError) logging.debug('AudioNotify initialized with config: ' + str(params))
def _downloadZippedCaptionAndExtract(self, downloadLink, language): captionObj = None logging.debug('Downloading link: ' + str(downloadLink)) zipData = None try: zipData = urllib2.urlopen(downloadLink).read() except Exception as e: logging.error('Failed to fetch download link: ' + str(downloadLink) + ', err:' + str(e)) if zipData is None: logging.error('Failed to download: ' + str(downloadLink)) return None tmpZip = os.path.join(apppath.pathTemporary('opensubtitles'), 'sub.zip') fTmp = open(tmpZip, 'w') fTmp.write(zipData) fTmp.close() archive = zipfile.ZipFile(tmpZip) if archive is None: logging.error('Failed to extract zip: ' + str(downloadLink)) for zipName in archive.namelist(): extension = zipName.split('.')[-1] if extension == 'xml' or extension == 'html' or extension == 'txt' or extension == 'nfo': logging.info('Ignoring file ' + zipName) elif extension == 'srt': srtData = archive.open(zipName, 'r').read() captionObj = caption.SRTCaption(srtData, language) else: logging.error('Unrecognised file:' + str(zipName)) os.remove(tmpZip) return captionObj
def _downloadZippedCaptionAndExtract(self,downloadLink,language): captionObj = None logging.debug('Downloading link: ' + str(downloadLink)) zipData = None try: zipData = urllib2.urlopen(downloadLink).read() except Exception as e: logging.error('Failed to fetch download link: ' + str(downloadLink) + ', err:' + str(e)) if zipData is None: logging.error('Failed to download: ' + str(downloadLink)) return None tmpZip = os.path.join(apppath.pathTemporary('opensubtitles'),'sub.zip') fTmp = open(tmpZip,'w') fTmp.write(zipData) fTmp.close() archive = zipfile.ZipFile(tmpZip) if archive is None: logging.error('Failed to extract zip: ' + str(downloadLink)) for zipName in archive.namelist(): extension = zipName.split('.')[-1] if extension == 'xml' or extension == 'html' or extension == 'txt' or extension == 'nfo': logging.info('Ignoring file ' + zipName) elif extension == 'srt': srtData = archive.open(zipName,'r').read() captionObj = caption.SRTCaption(srtData,language) else: logging.error('Unrecognised file:' + str(zipName)) os.remove(tmpZip) return captionObj
def convertSubIdxToSrt(vobsubData, idxData, language='en'): vobsubPath = apppath.vobsub2srt() if vobsubPath is None: return None tmpSubFile = os.path.join(apppath.pathTemporary('caption'), 'subtitle.sub') tmpIdxFile = os.path.join(apppath.pathTemporary('caption'), 'subtitle.idx') tmpSrtFile = os.path.join(apppath.pathTemporary('caption'), 'subtitle.srt') if os.path.exists(tmpSubFile): os.remove(tmpSubFile) if os.path.exists(tmpIdxFile): os.remove(tmpIdxFile) if os.path.exists(tmpSrtFile): os.remove(tmpSrtFile) fSub = open(tmpSubFile, 'w') fSub.write(vobsubData) fSub.close() if idxData is not None: fIdx = open(tmpIdxFile, 'w') fIdx.write(idxData) fIdx.close() #TODO vobsub2srt complains about language codes language = 'en' cmdargs = [vobsubPath, '--lang', language, tmpSubFile.split('.')[0]] logging.debug('Running command: ' + ' '.join(cmdargs)) cmd = subprocess.Popen(cmdargs, stdout=subprocess.PIPE, stderr=subprocess.PIPE) cmd.wait() response = cmd.communicate() srtData = None if os.path.exists(tmpSrtFile): fSrt = open(tmpSrtFile) srtData = fSrt.read() fSrt.close() logging.debug('Succesfully converted to srt file: ' + str(tmpSrtFile) + ', size(' + str(len(srtData)) + ')') os.remove(tmpSrtFile) else: logging.warn('Failed to convert sub file to srt file: ' + str(response)) if os.path.exists(tmpSubFile): os.remove(tmpSubFile) if os.path.exists(tmpIdxFile): os.remove(tmpIdxFile) return srtData