Mapping YouTube API responses to the internal simpler format recognized by OMXPlayer plugin

This commit is contained in:
BlackLight 2018-12-12 22:46:32 +01:00
parent 679cad53b5
commit b7603ba166

View file

@ -440,7 +440,7 @@ class VideoOmxplayerPlugin(Plugin):
self.logger.info('Searching YouTube for "{}"'.format(query))
try:
return get_plugin('google.youtube').search(query=query)
return self._youtube_search_api(query=query)
except Exception as e:
self.logger.warning('Unable to load the YouTube plugin, falling ' +
'back to HTML parse method: {}'.format(str(e)))
@ -448,6 +448,16 @@ class VideoOmxplayerPlugin(Plugin):
return self._youtube_search_html_parse(query=query)
def _youtube_search_api(self, query):
return [
{
'url': 'https://www.youtube.com/watch?v=' + item['id']['videoId'],
'title' item.get('snippet', {}).get('title', '<No Title>'),
}
for item in get_plugin('google.youtube').search(query=query).output
if item.get('id', {}).get('kind') == 'youtube#video'
]
def _youtube_search_html_parse(self, query):
query = urllib.parse.quote(query)
url = "https://www.youtube.com/results?search_query=" + query