コード例 #1
0
ファイル: test_enzyme.py プロジェクト: ratoaq2/knowit
def test_enzyme_provider_real_media(media, options):
    # Given
    options['provider'] = 'enzyme'
    options['fail_on_error'] = False

    # When
    if not media.expected_data:
        with pytest.raises(KnowitException):
            know(media.video_path, options)
    else:
        actual = know(media.video_path, options)

        # Then
        assert_expected(media.expected_data, actual, options)
コード例 #2
0
    def quality_from_file_meta(file_path):
        """
        Get quality from file metadata.

        :param file_path: File path to analyse
        :return: Quality prefix
        """
        if not os.path.isfile(file_path):
            return Quality.UNKNOWN

        try:
            knowledge = knowit.know(file_path)
        except knowit.KnowitException as error:
            log.warning(
                'An error occurred while parsing: {path}\n'
                'KnowIt reported:\n{report}', {
                    'path': file_path,
                    'report': error,
                })
            return Quality.UNKNOWN

        if not knowledge:
            return Quality.UNKNOWN

        height = None
        for track in knowledge.get('video') or []:
            height = track.get('height')
            if height:
                break

        if not height:
            return Quality.UNKNOWN

        height = int(height.magnitude)

        # TODO: Use knowledge information like 'resolution'
        base_filename = os.path.basename(file_path)
        bluray = re.search(r'blue?-?ray|hddvd|b[rd](rip|mux)', base_filename,
                           re.I) is not None
        webdl = re.search(r'web.?dl|web(rip|mux|hd)', base_filename,
                          re.I) is not None

        ret = Quality.UNKNOWN
        if 3240 < height:
            ret = ((Quality.UHD_8K_TV, Quality.UHD_8K_BLURAY)[bluray],
                   Quality.UHD_8K_WEBDL)[webdl]
        if 1620 < height <= 3240:
            ret = ((Quality.UHD_4K_TV, Quality.UHD_4K_BLURAY)[bluray],
                   Quality.UHD_4K_WEBDL)[webdl]
        elif 800 < height <= 1620:
            ret = ((Quality.FULLHDTV, Quality.FULLHDBLURAY)[bluray],
                   Quality.FULLHDWEBDL)[webdl]
        elif 680 < height <= 800:
            ret = ((Quality.HDTV, Quality.HDBLURAY)[bluray],
                   Quality.HDWEBDL)[webdl]
        elif height <= 680:
            ret = (Quality.SDTV, Quality.SDDVD)[re.search(
                r'dvd|b[rd]rip|blue?-?ray', base_filename, re.I) is not None]

        return ret
コード例 #3
0
def get_file_metadata(filename):
    try:
        p = knowit.know(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']

        # Resolution
        width = re.match(r'(\d+)', str(p['video'][0]['width']))
        height = re.match(r'(\d+)', str(p['video'][0]['height']))

        return {
            'title': p.get('title', ""),
            'video': vc,
            'audio': ac,
            'resolution_width': int(width.group(1)) if width else 0,
            'resolution_height': int(height.group(1)) if height else 0,
            'audio_channels': p['audio'][0]['channels'],
        }
    except Exception:
        sickrage.app.log.debug('Failed to parse meta for {}'.format(filename))

    return {}
コード例 #4
0
def test_mkvmerge_provider_real_media(media, options):
    # Given
    options['provider'] = 'mkvmerge'

    # When
    actual = know(media.video_path, options)

    # Then
    assert_expected(media.expected_data, actual, options)
コード例 #5
0
def test_mkvmerge_provider(mkvmerge, media, options):
    # Given
    mkvmerge[media.video_path] = media.input_data

    # When
    actual = know(media.video_path, options)

    # Then
    assert_expected(media.expected_data, actual, options)
コード例 #6
0
ファイル: test_ffmpeg.py プロジェクト: ratoaq2/knowit
def test_ffmpeg_provider(ffmpeg, media, options):
    # Given
    ffmpeg[media.video_path] = media.input_data

    # When
    actual = know(media.video_path, options)

    # Then
    assert_expected(media.expected_data, actual, options)
コード例 #7
0
def test_mediainfo_provider_real_media_cli(mediainfo_cli, media, options):
    # Given
    options['provider'] = 'mediainfo'

    # When
    actual = know(media.video_path, options)

    # Then
    assert_expected(media.expected_data, actual, options)
コード例 #8
0
ファイル: test_enzyme.py プロジェクト: Hellowlol/knowit
def test_enzyme_provider(monkeypatch, video_path, raw, expected):
    # Given
    options = dict(provider='enzyme')
    monkeypatch.setattr('enzyme.MKV', Mock())
    monkeypatch.setattr('knowit.utils.todict', lambda mkv: raw)

    # When
    actual = knowit.know(video_path, options)

    # Then
    assert expected == actual
コード例 #9
0
    def quality_from_file_meta(file_path):
        """
        Get quality file file metadata.

        :param file_path: File path to analyse
        :return: Quality prefix
        """
        if not os.path.isfile(file_path):
            return Quality.UNKNOWN

        knowledge = knowit.know(file_path)

        if not knowledge:
            return Quality.UNKNOWN

        height = None
        for track in knowledge.get('video') or []:
            height = track.get('height')
            if height:
                break

        if not height:
            return Quality.UNKNOWN

        height = int(height.magnitude)

        # TODO: Use knowledge information like 'resolution'
        base_filename = path.basename(file_path)
        bluray = re.search(r"blue?-?ray|hddvd|b[rd](rip|mux)", base_filename,
                           re.I) is not None
        webdl = re.search(r"web.?dl|web(rip|mux|hd)", base_filename,
                          re.I) is not None

        ret = Quality.UNKNOWN
        if 3240 < height:
            ret = ((Quality.UHD_8K_TV, Quality.UHD_8K_BLURAY)[bluray],
                   Quality.UHD_8K_WEBDL)[webdl]
        if 1620 < height <= 3240:
            ret = ((Quality.UHD_4K_TV, Quality.UHD_4K_BLURAY)[bluray],
                   Quality.UHD_4K_WEBDL)[webdl]
        elif 800 < height <= 1620:
            ret = ((Quality.FULLHDTV, Quality.FULLHDBLURAY)[bluray],
                   Quality.FULLHDWEBDL)[webdl]
        elif 680 < height <= 800:
            ret = ((Quality.HDTV, Quality.HDBLURAY)[bluray],
                   Quality.HDWEBDL)[webdl]
        elif height <= 680:
            ret = (Quality.SDTV, Quality.SDDVD)[re.search(
                r'dvd|b[rd]rip|blue?-?ray', base_filename, re.I) is not None]

        return ret
コード例 #10
0
def test_mediainfo_provider(monkeypatch, video_path, raw, expected):
    # Given
    options = dict(provider='mediainfo')
    parse_method = Mock()
    parse_method.to_data.return_value = raw
    monkeypatch.setattr(available_providers['mediainfo'], 'native_lib', True)
    monkeypatch.setattr(MediaInfoProvider, '_parse',
                        lambda self, video: parse_method)

    # When
    actual = knowit.know(video_path, options)

    # Then
    assert expected == actual
コード例 #11
0
def get_embedded_subtitles(video_path):
    """Return all embedded subtitles for the given video path.

    :param video_path: video filename to be checked
    :type video_path: str
    :return:
    :rtype: set of babelfish.Language
    """
    knowledge = knowit.know(video_path)
    tracks = knowledge.get('subtitle', [])
    found_languages = {s['language'] for s in tracks if 'language' in s}
    if found_languages:
        logger.info(u'Found embedded subtitles: {subs}', subs=found_languages)
    return found_languages
コード例 #12
0
ファイル: subtitles.py プロジェクト: pymedusa/SickRage
def get_embedded_subtitles(video_path):
    """Return all embedded subtitles for the given video path.

    :param video_path: video filename to be checked
    :type video_path: str
    :return:
    :rtype: set of babelfish.Language
    """
    knowledge = knowit.know(video_path)
    tracks = knowledge.get('subtitle', [])
    found_languages = {s['language'] for s in tracks if 'language' in s}
    if found_languages:
        logger.info(u'Found embedded subtitles: {subs}', subs=found_languages)
    return found_languages
コード例 #13
0
ファイル: common.py プロジェクト: pymedusa/SickRage
    def quality_from_file_meta(file_path):
        """
        Get quality file file metadata.

        :param file_path: File path to analyse
        :return: Quality prefix
        """
        if not os.path.isfile(file_path):
            return Quality.UNKNOWN

        knowledge = knowit.know(file_path)

        if not knowledge:
            return Quality.UNKNOWN

        height = None
        for track in knowledge.get('video') or []:
            height = track.get('height')
            if height:
                break

        if not height:
            return Quality.UNKNOWN

        height = int(height.magnitude)

        # TODO: Use knowledge information like 'resolution'
        base_filename = os.path.basename(file_path)
        bluray = re.search(r'blue?-?ray|hddvd|b[rd](rip|mux)', base_filename, re.I) is not None
        webdl = re.search(r'web.?dl|web(rip|mux|hd)', base_filename, re.I) is not None

        ret = Quality.UNKNOWN
        if 3240 < height:
            ret = ((Quality.UHD_8K_TV, Quality.UHD_8K_BLURAY)[bluray], Quality.UHD_8K_WEBDL)[webdl]
        if 1620 < height <= 3240:
            ret = ((Quality.UHD_4K_TV, Quality.UHD_4K_BLURAY)[bluray], Quality.UHD_4K_WEBDL)[webdl]
        elif 800 < height <= 1620:
            ret = ((Quality.FULLHDTV, Quality.FULLHDBLURAY)[bluray], Quality.FULLHDWEBDL)[webdl]
        elif 680 < height <= 800:
            ret = ((Quality.HDTV, Quality.HDBLURAY)[bluray], Quality.HDWEBDL)[webdl]
        elif height <= 680:
            ret = (Quality.SDTV, Quality.SDDVD)[re.search(r'dvd|b[rd]rip|blue?-?ray', base_filename, re.I) is not None]

        return ret
コード例 #14
0
def get_embedded_subtitles(video_path):
    """Return all embedded subtitles for the given video path.

    :param video_path: video filename to be checked
    :type video_path: str
    :return:
    :rtype: set of babelfish.Language
    """
    try:
        knowledge = knowit.know(video_path)
    except knowit.KnowitException as error:
        logger.warning('An error occurred while parsing: {0}\n'
                       'KnowIt reported:\n{1}'.format(video_path, error))
        return set()

    tracks = knowledge.get('subtitle', [])
    found_languages = {s['language'] for s in tracks if 'language' in s}
    if found_languages:
        logger.info(u'Found embedded subtitles: {subs}', subs=found_languages)
    return found_languages
コード例 #15
0
from knowit import know
import os
pathname = r"C:\Users\wangh\Downloads\stanford _machine_learning"
filenames = [x for x in os.listdir(pathname) if os.path.splitext(x)[1] == '.mkv']
# filenames = [x for x in os.listdir(pathname) if os.path.isfile(x) and os.path.splitext(x)[1] == '.mkv']
filenames.sort(key=lambda x:int(x[:2])) #列出所有视屏文件并排序
duration_time = []
for i in filenames:
    duration_time.append(know(pathname+'\\'+i)['duration'].seconds)
# print(duration_time)
sum_time = sum([x for x in duration_time if x <1000])
print('total learning time is {} hour {} minutes'.format(int(sum_time/3600),int((sum_time-int(sum_time/3600)*3600)/60)))
# print(filenames)
# filename = r"C:\Users\wangh\Downloads\stanford _machine_learning\1.mkv"
# duration_time = know(filename)['duration']