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']
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]
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'
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'
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'
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)
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)
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)
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
def simple(): return DownloaderParametersFixture( io=IOContext(destdir='/tmp/', rtmpdump_binary='rtmpdump'), filters=StreamFilters(), downloader=YleDlDownloader(MockSubtitleDownloader(), MockGeoLocation()))
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 == []
def fetch_title(url, filters=StreamFilters()): return fetch(url, StreamAction.PRINT_STREAM_TITLE, filters)
def fetch_stream_url(url, filters=StreamFilters()): return fetch(url, StreamAction.PRINT_STREAM_URL, filters)
def fetch_episode_pages(url, filters=StreamFilters()): return fetch(url, StreamAction.PRINT_EPISODE_PAGES, filters)
def fetch_metadata(url, filters=StreamFilters(), meta_language=None): return json.loads('\n'.join( fetch(url, StreamAction.PRINT_METADATA, filters, meta_language)))
def simple(): return DownloaderParametersFixture(io=IOContext(destdir='/tmp/'), filters=StreamFilters(), downloader=YleDlDownloader( MockGeoLocation()))