[mediathekviewweb] flake8

This commit is contained in:
ckaotik 2021-02-21 08:51:48 +01:00
parent 4c91c4f146
commit a482e8fba0

View File

@ -1,12 +1,12 @@
import datetime import datetime
import itertools import itertools
import json import json
import re
from .common import InfoExtractor, SearchInfoExtractor from .common import InfoExtractor, SearchInfoExtractor
from ..compat import compat_urllib_parse_unquote from ..compat import compat_urllib_parse_unquote
from ..utils import ExtractorError, int_or_none from ..utils import ExtractorError, int_or_none
class MediathekViewWebSearchIE(SearchInfoExtractor): class MediathekViewWebSearchIE(SearchInfoExtractor):
IE_NAME = 'mediathekviewweb:search' IE_NAME = 'mediathekviewweb:search'
IE_DESC = 'MediathekViewWeb search' IE_DESC = 'MediathekViewWeb search'
@ -32,10 +32,6 @@ class MediathekViewWebSearchIE(SearchInfoExtractor):
def _build_conditions(self, search): def _build_conditions(self, search):
# @note So far, there is no API endpoint to convert a query string into # @note So far, there is no API endpoint to convert a query string into
# a complete query object, as required by the /api/query endpoint. # a complete query object, as required by the /api/query endpoint.
# @see https://github.com/mediathekview/mediathekviewweb/blob/master/client/index.ts#L144
# for parsing the search string into properties.
# @see https://github.com/mediathekview/mediathekviewweb/blob/master/client/index.ts#L389
# for converting properties into field queries.
filters = {} filters = {}
extra = {} extra = {}
for component in search.lower().split(): for component in search.lower().split():
@ -89,7 +85,7 @@ class MediathekViewWebSearchIE(SearchInfoExtractor):
for item in results: for item in results:
variant = None variant = None
for key, value in self._variants.items(): for key, value in self._variants.items():
if item['title'].find(value) != -1: if item.setdefault('title', '').find(value) != -1:
variant = key variant = key
formats = [] formats = []
@ -99,7 +95,7 @@ class MediathekViewWebSearchIE(SearchInfoExtractor):
'format_id': ('medium-' + variant) if variant else 'medium', 'format_id': ('medium-' + variant) if variant else 'medium',
'language_preference': -10 if variant else 10, 'language_preference': -10 if variant else 10,
'quality': -2, 'quality': -2,
'filesize': item['size'], 'filesize': item.get('size'),
}) })
if len(item.get('url_video_low', '')) > 0: if len(item.get('url_video_low', '')) > 0:
formats.append({ formats.append({
@ -122,21 +118,22 @@ class MediathekViewWebSearchIE(SearchInfoExtractor):
video = { video = {
'_type': 'video', '_type': 'video',
'formats': formats, 'formats': formats,
'id': item['id'], 'id': item.get('id'),
'title': item['title'], 'title': item.get('title'),
'description': item['description'], 'description': item.get('description'),
'series': item['topic'], 'series': item.get('topic'),
'channel': item['channel'], 'channel': item.get('channel'),
'uploader': item['channel'], 'uploader': item.get('channel'),
'duration': int_or_none(item['duration']), 'duration': int_or_none(item.get('duration')),
'webpage_url': item['url_website'], 'webpage_url': item.get('url_website'),
} }
if item.get('timestamp'):
upload_date = datetime.datetime.utcfromtimestamp(item['timestamp']) upload_date = datetime.datetime.utcfromtimestamp(item['timestamp'])
video['upload_date'] = upload_date.strftime('%Y%m%d') video['upload_date'] = upload_date.strftime('%Y%m%d')
if item['url_subtitle']: if item.get('url_subtitle'):
video.setdefault('subtitles', {}).setdefault('de', []).append({ video.setdefault('subtitles', {}).setdefault('de', []).append({
'url': item['url_subtitle'], 'url': item.get('url_subtitle'),
}) })
entries.append(video) entries.append(video)
@ -168,12 +165,15 @@ class MediathekViewWebSearchIE(SearchInfoExtractor):
entries.extend(self._extract_playlist_entries(results['result']['results'])) entries.extend(self._extract_playlist_entries(results['result']['results']))
meta = results['result']['queryInfo'] meta = results['result']['queryInfo']
# @todo This returns full pages: 100 results if 51 are requested. if len(entries) >= n:
if len(entries) >= n or meta['resultCount'] == 0: entries = entries[0:n]
break
elif meta['resultCount'] == 0:
break break
return self.playlist_result(entries, playlist_title=query) return self.playlist_result(entries, playlist_title=query)
class MediathekViewWebIE(InfoExtractor): class MediathekViewWebIE(InfoExtractor):
# @see https://github.com/mediathekview/mediathekviewweb # @see https://github.com/mediathekview/mediathekviewweb
IE_NAME = 'mediathekviewweb' IE_NAME = 'mediathekviewweb'