예제 #1
0
    def scan(self):
        """Scan and return associated subtitles

        :return: associated subtitles
        :rtype: list of :class:`~subliminal.subtitles.Subtitle`

        """
        if not self.exists:
            return []
        basepath = os.path.splitext(self.path)[0]
        results = []
        video_infos = None
        try:
            video_infos = enzyme.parse(self.path)
            logger.debug(u"Succeeded parsing %s with enzyme: %r" % (self.path, video_infos))
        except:
            logger.debug(u"Failed parsing %s with enzyme" % self.path)
        if isinstance(video_infos, enzyme.core.AVContainer):
            results.extend([subtitles.EmbeddedSubtitle.from_enzyme(self.path, s) for s in video_infos.subtitles])
        for l in list_languages(1):
            for e in subtitles.EXTENSIONS:
                single_path = basepath + "%s" % e
                if os.path.exists(single_path):
                    results.append(subtitles.ExternalSubtitle(single_path, None))
                multi_path = basepath + ".%s%s" % (l, e)
                if os.path.exists(multi_path):
                    results.append(subtitles.ExternalSubtitle(multi_path, l))
        return results
예제 #2
0
    def getMeta(self, filename):

        try:
            p = enzyme.parse(filename)

            # Video codec
            vc = ('h264'
                  if p.video[0].codec == 'AVC1' else p.video[0].codec).lower()

            # Audio codec
            ac = p.audio[0].codec
            try:
                ac = self.audio_codec_map.get(p.audio[0].codec)
            except:
                pass

            return {
                'video': vc,
                'audio': ac,
                'resolution_width': tryInt(p.video[0].width),
                'resolution_height': tryInt(p.video[0].height),
            }
        except ParseError:
            log.debug('Failed to parse meta for %s', filename)
        except NoParserError:
            log.debug('No parser found for %s', filename)
        except:
            log.debug('Failed parsing %s', filename)

        return {}
예제 #3
0
    def getMeta(self, filename):

        try:
            p = enzyme.parse(filename)

            # Video codec
            vc = ("h264" if p.video[0].codec == "AVC1" else p.video[0].codec).lower()

            # Audio codec
            ac = p.audio[0].codec
            try:
                ac = self.audio_codec_map.get(p.audio[0].codec)
            except:
                pass

            return {
                "video": vc,
                "audio": ac,
                "resolution_width": tryInt(p.video[0].width),
                "resolution_height": tryInt(p.video[0].height),
                "audio_channels": p.audio[0].channels,
            }
        except ParseError:
            log.debug("Failed to parse meta for %s", filename)
        except NoParserError:
            log.debug("No parser found for %s", filename)
        except:
            log.debug("Failed parsing %s", filename)

        return {}
예제 #4
0
    def getMeta(self, filename):

        try:
            p = enzyme.parse(filename)

            # Video codec
            vc = ('h264' if p.video[0].codec == 'AVC1' else p.video[0].codec).lower()

            # Audio codec
            ac = p.audio[0].codec
            try: ac = self.audio_codec_map.get(p.audio[0].codec)
            except: pass

            return {
                'video': vc,
                'audio': ac,
                'resolution_width': tryInt(p.video[0].width),
                'resolution_height': tryInt(p.video[0].height),
            }
        except ParseError:
            log.debug('Failed to parse meta for %s', filename)
        except NoParserError:
            log.debug('No parser found for %s', filename)
        except:
            log.debug('Failed parsing %s', filename)

        return {}
예제 #5
0
    def scan(self):
        """Scan and return associated subtitles

        :return: associated subtitles
        :rtype: list of :class:`~subliminal.subtitles.Subtitle`

        """
        if not self.exists:
            return []
        basepath = os.path.splitext(self.path)[0]
        results = []
        video_infos = None
        try:
            video_infos = enzyme.parse(self.path)
            logger.debug(u'Succeeded parsing %s with enzyme: %r' % (self.path, video_infos))
        except:
            logger.debug(u'Failed parsing %s with enzyme' % self.path)
        if isinstance(video_infos, enzyme.core.AVContainer):
            results.extend([subtitles.EmbeddedSubtitle.from_enzyme(self.path, s) for s in video_infos.subtitles])
        # cannot use glob here because it chokes if there are any square
        # brackets inside the filename, so we have to use basic string
        # startswith/endswith comparisons
        folder, basename = os.path.split(basepath)
        if folder == '':                                                                                                                                                                       
            folder = '.'  
        existing = [f for f in os.listdir(folder) if f.startswith(basename)]
        for path in existing:
            for ext in subtitles.EXTENSIONS:
                if path.endswith(ext):
                    language = Language(path[len(basename) + 1:-len(ext)], strict=False)
                    results.append(subtitles.ExternalSubtitle(path, language))
        return results
예제 #6
0
 def setUp(self):
     self.p1 = enzyme.parse(os.path.join(matroska_test_path, u'test1.mkv'))
     self.p2 = enzyme.parse(os.path.join(matroska_test_path, u'test2.mkv'))
     self.p3 = enzyme.parse(os.path.join(matroska_test_path, u'test3.mkv'))
     self.p4 = enzyme.parse(os.path.join(matroska_test_path, u'test4.mkv'))
     self.p5 = enzyme.parse(os.path.join(matroska_test_path, u'test5.mkv'))
     self.p6 = enzyme.parse(os.path.join(matroska_test_path, u'test6.mkv'))
     self.p7 = enzyme.parse(os.path.join(matroska_test_path, u'test7.mkv'))
     self.p8 = enzyme.parse(os.path.join(matroska_test_path, u'test8.mkv'))
예제 #7
0
    def _load(self, filename):
        log.debug("Loading file %r", filename)
        metadata = Metadata()
        self._add_path_to_metadata(metadata)

        try:
            parser = enzyme.parse(filename)
            log.debug("Metadata for %s:\n%s", filename, unicode(parser))
            self._convertMetadata(parser, metadata)
        except Exception, err:
            log.error("Could not parse file %r: %r", filename, err)
예제 #8
0
def getFileMetadata(filename):
    import enzyme

    try:
        p = enzyme.parse(filename)

        # Video codec
        vc = ('H264' if p.video[0].codec == 'AVC1' else
              'x265' if p.video[0].codec == 'HEVC' else p.video[0].codec)

        # Audio codec
        ac = p.audio[0].codec
        try:
            ac = audio_codec_map.get(p.audio[0].codec)
        except:
            pass

        # Find title in video headers
        titles = []

        try:
            if p.title:
                titles.append(p.title)
        except:
            sickrage.srCore.srLogger.error(
                'Failed getting title from meta: %s', traceback.format_exc())

        for video in p.video:
            try:
                if video.title:
                    titles.append(video.title)
            except:
                sickrage.srCore.srLogger.error(
                    'Failed getting title from meta: %s',
                    traceback.format_exc())

        return {
            'titles': list(set(titles)),
            'video': vc,
            'audio': ac,
            'resolution_width': tryInt(p.video[0].width),
            'resolution_height': tryInt(p.video[0].height),
            'audio_channels': p.audio[0].channels,
        }
    except enzyme.exceptions.ParseError:
        sickrage.srCore.srLogger.debug('Failed to parse meta for %s', filename)
    except enzyme.exceptions.NoParserError:
        sickrage.srCore.srLogger.debug('No parser found for %s', filename)
    except:
        sickrage.srCore.srLogger.debug('Failed parsing %s', filename)

    return {}
예제 #9
0
 def __init__(self, reference):
     self.reference = None
     self.logger = tvdb_logger('brewer')
     if isinstance(reference, dict):
         self.reference = reference
     else:
         try:
             self.log('parse', "parsing metadata for %s" % reference)
             self.complete_infos = enzyme.parse(reference).convert()
             self.info = self.cleanup(self.complete_infos)
         except:
             self.complete_infos = {}
             self.info = {}
             self.error('parse', "error parsing metadata for %s" % reference)
예제 #10
0
 def __init__(self, reference):
     self.reference = None
     self.logger = tvdb_logger('brewer')
     if isinstance(reference, dict):
         self.reference = reference
     else:
         try:
             self.log('parse', "parsing metadata for %s" % reference)
             self.complete_infos = enzyme.parse(reference).convert()
             self.info = self.cleanup(self.complete_infos)
         except:
             self.complete_infos = {}
             self.info = {}
             self.error('parse', "error parsing metadata for %s" % reference)
예제 #11
0
    def getMeta(self, filename):

        try:
            p = enzyme.parse(filename)

            # Video codec
            vc = ('H264' if p.video[0].codec == 'AVC1' else p.video[0].codec)

            # Audio codec
            ac = p.audio[0].codec
            try:
                ac = self.audio_codec_map.get(p.audio[0].codec)
            except:
                pass

            # Find title in video headers
            titles = []

            try:
                if p.title and self.findYear(p.title):
                    titles.append(ss(p.title))
            except:
                log.error('Failed getting title from meta: %s',
                          traceback.format_exc())

            for video in p.video:
                try:
                    if video.title and self.findYear(video.title):
                        titles.append(ss(video.title))
                except:
                    log.error('Failed getting title from meta: %s',
                              traceback.format_exc())

            return {
                'titles': list(set(titles)),
                'video': vc,
                'audio': ac,
                'resolution_width': tryInt(p.video[0].width),
                'resolution_height': tryInt(p.video[0].height),
                'audio_channels': p.audio[0].channels,
            }
        except enzyme.exceptions.ParseError:
            log.debug('Failed to parse meta for %s', filename)
        except enzyme.exceptions.NoParserError:
            log.debug('No parser found for %s', filename)
        except:
            log.debug('Failed parsing %s', filename)

        return {}
예제 #12
0
def get_video_data(path):
    video = enzyme.parse(path)
    vidtrack = video.video[0]
    audtrack = video.audio[0]
    yield ('a', 'Video')
    yield ('title', video.title)
    yield ('mime_type', video.mime)
    yield ('vid_type', video.type)
    yield ('vid_timestamp', datetime.datetime.fromtimestamp(video.timestamp))
    yield ('length', video.length)
    yield ('width', vidtrack.width)
    yield ('height', vidtrack.height)
    #yield ('dimensions', (vidtrack.width, vidtrack.height))
    yield ('vid_codec', vidtrack.codec)
    yield ('aud_codec', audtrack.codec)
    return
예제 #13
0
    def getMeta(self, filename):

        try:

            p = enzyme.parse(filename)
            return {
                'video': p.video[0].codec,
                'audio': p.audio[0].codec,
                'resolution_width': p.video[0].width,
                'resolution_height': p.video[0].height,
            }
        except ParseError:
            log.debug('Failed to parse meta for %s' % filename)
        except NoParserError:
            log.debug('No parser found for %s' % filename)

        return {}
예제 #14
0
def getFileMetadata(filename):
    import enzyme

    try:
        p = enzyme.parse(filename)

        # Video codec
        vc = ('H264' if p.video[0].codec == 'AVC1' else 'x265' if p.video[0].codec == 'HEVC' else p.video[0].codec)

        # Audio codec
        ac = p.audio[0].codec
        try: ac = audio_codec_map.get(p.audio[0].codec)
        except: pass

        # Find title in video headers
        titles = []

        try:
            if p.title:
                titles.append(p.title)
        except:
            sickrage.srLogger.error('Failed getting title from meta: %s', traceback.format_exc())

        for video in p.video:
            try:
                if video.title:
                    titles.append(video.title)
            except:
                sickrage.srLogger.error('Failed getting title from meta: %s', traceback.format_exc())

        return {
            'titles': list(set(titles)),
            'video': vc,
            'audio': ac,
            'resolution_width': tryInt(p.video[0].width),
            'resolution_height': tryInt(p.video[0].height),
            'audio_channels': p.audio[0].channels,
        }
    except enzyme.exceptions.ParseError:
        sickrage.srLogger.debug('Failed to parse meta for %s', filename)
    except enzyme.exceptions.NoParserError:
        sickrage.srLogger.debug('No parser found for %s', filename)
    except:
        sickrage.srLogger.debug('Failed parsing %s', filename)

    return {}
예제 #15
0
    def getMeta(self, filename):

        try:
            p = enzyme.parse(filename)

            # Video codec
            vc = ('H264' if p.video[0].codec == 'AVC1' else p.video[0].codec)

            # Audio codec
            ac = p.audio[0].codec
            try: ac = self.audio_codec_map.get(p.audio[0].codec)
            except: pass

            # Find title in video headers
            titles = []

            try:
                if p.title and self.findYear(p.title):
                    titles.append(ss(p.title))
            except:
                log.error('Failed getting title from meta: %s', traceback.format_exc())

            for video in p.video:
                try:
                    if video.title and self.findYear(video.title):
                        titles.append(ss(video.title))
                except:
                    log.error('Failed getting title from meta: %s', traceback.format_exc())

            return {
                'titles': list(set(titles)),
                'video': vc,
                'audio': ac,
                'resolution_width': tryInt(p.video[0].width),
                'resolution_height': tryInt(p.video[0].height),
                'audio_channels': p.audio[0].channels,
            }
        except enzyme.exceptions.ParseError:
            log.debug('Failed to parse meta for %s', filename)
        except enzyme.exceptions.NoParserError:
            log.debug('No parser found for %s', filename)
        except:
            log.debug('Failed parsing %s', filename)

        return {}
예제 #16
0
    def getMeta(self, filename):

        try:
            p = enzyme.parse(filename)
            return {
                "video": p.video[0].codec,
                "audio": p.audio[0].codec,
                "resolution_width": tryInt(p.video[0].width),
                "resolution_height": tryInt(p.video[0].height),
            }
        except ParseError:
            log.debug("Failed to parse meta for %s", filename)
        except NoParserError:
            log.debug("No parser found for %s", filename)
        except:
            log.debug("Failed parsing %s", filename)

        return {}
예제 #17
0
    def getMeta(self, filename):

        try:
            p = enzyme.parse(filename)
            return {
                'video': p.video[0].codec,
                'audio': p.audio[0].codec,
                'resolution_width': tryInt(p.video[0].width),
                'resolution_height': tryInt(p.video[0].height),
            }
        except ParseError:
            log.debug('Failed to parse meta for %s', filename)
        except NoParserError:
            log.debug('No parser found for %s', filename)
        except:
            log.debug('Failed parsing %s', filename)

        return {}
예제 #18
0
def streaminfo(file):
    try:
        info = enzyme.parse(file)
    except:
        logger.debug('Enzyme error')
    movieinfo = {
        'length':'',
        'vcodec':'',
        'acodec':'',
        'height':'',
        'width':'',
        'aspect':'',
        'samplerate':'',
        'channels':''}
    info = str(info)
    logger.debug('info: %s' % info)
    lines =  info.split('+--')
    head = lines[0].split('\n')
    video = lines[1].split('\n')
    if len(lines) == 3:
        audio = lines[2].split('\n')
    else:
        audio = []

    for line in head:
        if 'length' in line:
            movieinfo['length'] = line.split(':')[1].strip()
    for line in video:
        if 'codec' in line and not 'codec_' in line:
            movieinfo['vcodec'] = line.split(':')[1].strip()
        if 'width' in line:
            movieinfo['width'] = line.split(':')[1].strip()
        if 'height' in line:
            movieinfo['height'] = line.split(':')[1].strip()
        if 'aspect' in line:
            movieinfo['aspect'] = line.split(':')[1].strip()
    for line in audio:
        if 'codec' in line and not 'codec_' in line:
            movieinfo['acodec'] = line.split(':')[1].split()
        if 'channels' in line:
            movieinfo['channels'] = line.split(':')[1].strip()
        if 'samplerate' in line:
            movieinfo['samplerate'] = line.split(':')[1].strip()
    return movieinfo
예제 #19
0
def getFileMetadata(filename):
    try:
        import enzyme
        p = enzyme.parse(filename)

        # Video codec
        vc = ('H264' if p.video[0].codec == 'AVC1' else
              'x265' if p.video[0].codec == 'HEVC' else p.video[0].codec)

        # Audio codec
        ac = p.audio[0].codec
        try:
            ac = audio_codec_map.get(p.audio[0].codec)
        except:
            pass

        # Find title in video headers
        titles = []

        try:
            if hasattr(p, 'title') and p.title:
                titles.append(p.title)
        except:
            sickrage.app.log.error('Failed getting title from meta')

        for video in p.video:
            try:
                if video.title:
                    titles.append(video.title)
            except:
                sickrage.app.log.error('Failed getting title from meta')

        return {
            'titles': list(set(titles)),
            'video': vc,
            'audio': ac,
            'resolution_width': int(p.video[0].width or 0),
            'resolution_height': int(p.video[0].height or 0),
            'audio_channels': p.audio[0].channels,
        }
    except Exception:
        sickrage.app.log.debug('Failed to parse meta for %s', filename)

    return {}
예제 #20
0
 def extract(self, full_path):
     meta = {
         'audio':   [],
         'file':    {},
         'release': {},
         'video':   [],
     }
     try:
         raw_meta = None
         raw_meta = enzyme.parse(full_path)
     except enzyme.exceptions.ParseError:
         error('Failed to parse %s' % full_path)
         return {}
     except enzyme.exceptions.NoParserError:
         error('No parser found for %s' % full_path)
         return {}
     except ValueError, errmsg:
         error('Failed to parse %s: %s' % (full_path, errmsg))
         return {}
예제 #21
0
def getFileMetadata(filename):
    try:
        import enzyme
        p = enzyme.parse(filename)

        # Video codec
        vc = ('H264' if p.video[0].codec == 'AVC1' else 'x265' if p.video[0].codec == 'HEVC' else p.video[0].codec)

        # Audio codec
        ac = p.audio[0].codec
        try:
            ac = audio_codec_map.get(p.audio[0].codec)
        except:
            pass

        # Find title in video headers
        titles = []

        try:
            if hasattr(p, 'title') and p.title:
                titles.append(p.title)
        except:
            sickrage.app.log.error('Failed getting title from meta')

        for video in p.video:
            try:
                if video.title:
                    titles.append(video.title)
            except:
                sickrage.app.log.error('Failed getting title from meta')

        return {
            'titles': list(set(titles)),
            'video': vc,
            'audio': ac,
            'resolution_width': int(p.video[0].width or 0),
            'resolution_height': int(p.video[0].height or 0),
            'audio_channels': p.audio[0].channels,
        }
    except Exception:
        sickrage.app.log.debug('Failed to parse meta for %s', filename)

    return {}
예제 #22
0
 def scan(self):
     """Scan and return associated Subtitles"""
     if not self.exists:
         return []
     basepath = os.path.splitext(self.path)[0]
     results = []
     video_infos = None
     try:
         video_infos = enzyme.parse(self.path)
     except enzyme.ParseError:
         pass
     if isinstance(video_infos, enzyme.core.AVContainer):
         results.extend([subtitles.EmbeddedSubtitle.fromEnzyme(self.path, s) for s in video_infos.subtitles])
     for l in list_languages(1):
         for e in subtitles.EXTENSIONS:
             single_path = basepath + "%s" % e
             if os.path.exists(single_path):
                 results.append(subtitles.ExternalSubtitle(single_path, None))
             multi_path = basepath + ".%s%s" % (l, e)
             if os.path.exists(multi_path):
                 results.append(subtitles.ExternalSubtitle(multi_path, l))
     return results
예제 #23
0
def get_video_time(filename):
    """Get file data from video metadata using ``enzyme`` package.

    This one is tricky, as
    (at least in the MP4 headers of files shot with cell phones)
    the time is stored as seconds since epoch **in UTC**.
    Thus the information on the timezone where the shot happened is needed.
    For now, it is assumed that it is the same timezone as the system
    currently running this code.
    Also, as I've met cell phones that put
    very erroneous capture file time in the header,
    I have restricted the recognized capture time to *after* the epoch.

    """
    try:
        mdata = enzyme.parse(filename)
    except enzyme.exceptions.NoParserError:
        return get_file_time(filename)
    tmepoch = mdata.timestamp
    # here is the place where too old (erroneous) date is not supported
    if tmepoch and tmepoch > 0:
        return datetime.datetime.fromtimestamp(tmepoch)
    else:
        return get_file_time(filename)
예제 #24
0
 def setUp(self):
     self.p1 = enzyme.parse(os.path.join(mp4_test_path, u'niceday.asf'))
예제 #25
0
    def __init__(self, filepath = None):
        """
        constructor.

        takes the complete movie file path, or nothing if you want to create
        a movie example
        """

        # create a movie example
        if filepath == None:
            # file path (only directory)
            self.path_ = 'C:\\'
            # original movie title, before renaming
            self.original_name_ = '[DivX ITA] A really cool movie (2012)'
            # file extension
            self.extension_ = '.avi'
            # movie new title (after renaming)
            self.new_name_ = ''
            # current state
            # states are used to show a proper panel in GUI
            self.state_ = self.STATE_BEFORE_RENAMING
            self.guessed_info_ = {
                                  self.SUBTITLES: ['Italian', 'ITA'],
                                  self.PART: '1'}
            info = {
                    self.TITLE: 'Un film molto figo',
                    self.ORIGINAL_TITLE: 'A really cool movie',
                    self.YEAR: '2012',
                    self.DIRECTOR: 'A. Director',
                    self.DURATION: ['100m', '1h40m'],
                    self.LANGUAGE: ['Italian', 'ITA'],
                    self.SCORE: 1}
            self.others_info_ = [info]
            self.info_ = info

        else:
            path, name = os.path.split(filepath)
            name, extension = os.path.splitext(name)
            # file path (only directory)
            self.path_ = os.path.normpath(unicode(path))
            # original movie title, before renaming
            self.original_name_ = unicode(name)
            # file extension
            self.extension_ = unicode(extension)
            # movie new title (after renaming)
            self.new_name_ = ''
            # current state
            # states are used to show a proper panel in GUI
            self.state_ = self.STATE_BEFORE_RENAMING
            # error occurred during renaming operation
            self.renaming_error_ = ''
            # used to store guessed information from file name
            self.guessed_info_ = None
            # imdb search for a given movie, return some results, which are 
            # transformed in a better formed and stored into this attribute
            self.others_info_ = None
            # currently associated movie, returned from imdb search, is stored here
            self.info_ = None
            # get video duration
            self.video_duration_ = None
            try:
                video_info = enzyme.parse(self.abs_original_file_name())
            except Exception:
                import traceback
                import exceptionhandler
                exceptionhandler.save_exception()
                traceback.print_exc()
            else:
                if video_info.length != None:
                    self.video_duration_ = int(video_info.length / 60)
                elif video_info.video[0].length != None:
                    self.video_duration_ = int(video_info.video[0].length / 60)
            # guess info from file name
            self.guessed_info_ = guess_info(name)
            # get other movie info
            self.get_info_()
예제 #26
0
def getVideoMetadata(file):
	return enzyme.parse(file).convert()
예제 #27
0
 def getTypes(self, path):
     try:
         parseFile = enzyme.parse(path)
         return parseFile
     except ValueError:
         return None 
예제 #28
0
 def setUp(self):
     self.p1 = enzyme.parse(os.path.join(mp4_test_path, u'20051210-w50s.flv'))
 def __init__(self, filePath):
     self.info = enzyme.parse(filePath)
     self.video = cv2.VideoCapture(filePath)
예제 #30
0
 def __init__(self, filePath):
     self.info = enzyme.parse(filePath)
     self.video = cv2.VideoCapture(filePath)
예제 #31
0
 def setUp(self):
     self.p1 = enzyme.parse(os.path.join(mp4_test_path, u'sample_mpeg4.mp4'))
     self.p2 = enzyme.parse(os.path.join(mp4_test_path, u'Quality Sample.mp4'))
     self.p3 = enzyme.parse(os.path.join(mp4_test_path, u'sample.3gp'))
     self.p4 = enzyme.parse(os.path.join(mp4_test_path, u'sample_3GPP2.3g2'))