def test_all():
    selected = subtitle_downloader.select(subtitles, StreamFilters())
    assert selected == subtitles

    selected = subtitle_downloader.select(subtitles,
                                          StreamFilters(sublang='all'))
    assert selected == subtitles
def test_filter_by_lang():
    filters_fin = StreamFilters(sublang='fin')
    selected_fin = subtitle_downloader.select(subtitles, filters_fin)

    assert selected_fin == [sub for sub in subtitles if sub.lang == 'fin']

    filters_swe = StreamFilters(sublang='swe')
    selected_swe = subtitle_downloader.select(subtitles, filters_swe)

    assert selected_swe == [sub for sub in subtitles if sub.lang == 'swe']
Esempio n. 3
0
def test_radio_stream_url_media_url():
    # The default stream is RTMP. This test is about the secondary
    # "media_url" stream. Therefore the rtmpdump backend is disabled.
    filters = StreamFilters(enabled_backends=['wget', 'ffmpeg'])
    url = fetch_stream_url('https://areena.yle.fi/1-4561516', filters)

    assert len(url) == 1
    assert '.mp3?' in url[0]
Esempio n. 4
0
def test_download_filter_exact_resolution(simple):
    state = {}
    filters = StreamFilters(maxheight=720)
    clips = [successful_clip(state)]
    res = simple.downloader.download_clips(clips, simple.io, filters)

    assert res == RD_SUCCESS
    assert state['command'] == 'download'
    assert state['stream_id'] == 'medium_quality'
Esempio n. 5
0
def test_download_multiple_filters(simple):
    state = {}
    filters = StreamFilters(maxheight=700, maxbitrate=900)
    clips = [successful_clip(state)]
    res = simple.downloader.download_clips(clips, simple.io, filters)

    assert res == RD_SUCCESS
    assert state['command'] == 'download'
    assert state['stream_id'] == 'low_quality'
Esempio n. 6
0
def test_download_filter_bitrate2(simple):
    state = {}
    filters = StreamFilters(maxbitrate=2000)
    clips = [successful_clip(state)]
    res = simple.downloader.download_clips(clips, simple.io, filters)

    assert res == RD_SUCCESS
    assert state['command'] == 'download'
    assert state['stream_id'] == 'medium_quality_high_bitrate'
Esempio n. 7
0
def test_radio_latest():
    # Test fetching the latest radio episode and also implicitly that
    # getting the latest episode is fast even though there are
    # hundreds of news episodes.
    filters = StreamFilters(latest_only=True)
    metadata = fetch_metadata('https://areena.yle.fi/audio/1-1440981', filters)

    assert len(metadata) == 1

    publish_date = datetime.strptime(metadata[0]['publish_timestamp'][:10], '%Y-%m-%d')
    assert publish_date >= datetime(2021, 1, 1)
Esempio n. 8
0
def test_areena_latest_episode():
    filters = StreamFilters(latest_only=True)
    metadata = fetch_metadata('https://areena.yle.fi/1-4655342', filters)

    assert len(metadata) == 1

    # The latest episode at the time of writing this test was
    # published on 2021-01-27
    publish_date = datetime.strptime(metadata[0]['publish_timestamp'][:10],
                                     '%Y-%m-%d')
    assert publish_date >= datetime(2021, 1, 27)
Esempio n. 9
0
def filter_flavors(flavors,
                   max_height=None,
                   max_bitrate=None,
                   enabled_backends=None):
    if enabled_backends is None:
        enabled_backends = list(Backends.default_order)

    filters = StreamFilters(maxheight=max_height,
                            maxbitrate=max_bitrate,
                            enabled_backends=enabled_backends)
    return yle_dl_downloader().select_flavor(flavors, filters)
Esempio n. 10
0
def fetch(url, action):
    backends = [BackendFactory(BackendFactory.ADOBEHDSPHP)]
    basic_filters = StreamFilters()
    io = IOContext(destdir='/tmp/')

    with Capturing() as output:
        res = download(url,
                       action,
                       io,
                       stream_filters=basic_filters,
                       backends=backends,
                       postprocess_command=None)
        assert res == RD_SUCCESS

    return output
Esempio n. 11
0
def simple():
    return DownloaderParametersFixture(
        io=IOContext(destdir='/tmp/', rtmpdump_binary='rtmpdump'),
        filters=StreamFilters(),
        downloader=YleDlDownloader(MockSubtitleDownloader(),
                                   MockGeoLocation()))
Esempio n. 12
0
def fetch_metadata(url, filters=StreamFilters()):
    return json.loads('\n'.join(
        fetch(url, StreamAction.PRINT_METADATA, filters)))
def test_do_not_download_if_hardsubs_is_set():
    filters = StreamFilters(hardsubs=True)
    selected = subtitle_downloader.select(subtitles, filters)
    assert selected == []
Esempio n. 14
0
def fetch_title(url, filters=StreamFilters()):
    return fetch(url, StreamAction.PRINT_STREAM_TITLE, filters)
Esempio n. 15
0
def fetch_stream_url(url, filters=StreamFilters()):
    return fetch(url, StreamAction.PRINT_STREAM_URL, filters)
Esempio n. 16
0
def fetch_episode_pages(url, filters=StreamFilters()):
    return fetch(url, StreamAction.PRINT_EPISODE_PAGES, filters)
Esempio n. 17
0
def fetch_metadata(url, filters=StreamFilters(), meta_language=None):
    return json.loads('\n'.join(
        fetch(url, StreamAction.PRINT_METADATA, filters, meta_language)))
Esempio n. 18
0
def simple():
    return DownloaderParametersFixture(io=IOContext(destdir='/tmp/'),
                                       filters=StreamFilters(),
                                       downloader=YleDlDownloader(
                                           MockGeoLocation()))