forked from platypush/platypush
Smarter logic for parsing YouTube URLs in Kodi
This commit is contained in:
parent
a4824a4e95
commit
c943acb9c2
2 changed files with 23 additions and 12 deletions
|
@ -478,6 +478,23 @@ class MediaPlugin(Plugin):
|
||||||
|
|
||||||
threading.Thread(target=_youtube_dl_thread).start()
|
threading.Thread(target=_youtube_dl_thread).start()
|
||||||
|
|
||||||
|
@action
|
||||||
|
def get_youtube_id(self, url: str) -> Optional[str]:
|
||||||
|
patterns = [
|
||||||
|
re.compile(pattern)
|
||||||
|
for pattern in [
|
||||||
|
'https?://www.youtube.com/watch?v=([^&#]+)'
|
||||||
|
'https?://youtube.com/watch?v=([^&#]+)'
|
||||||
|
'https?://youtu.be/([^&#/]+)'
|
||||||
|
'youtube:video:([^&#:])'
|
||||||
|
]
|
||||||
|
]
|
||||||
|
|
||||||
|
for pattern in patterns:
|
||||||
|
m = re.match(pattern, url)
|
||||||
|
if m:
|
||||||
|
return m.group(1)
|
||||||
|
|
||||||
@action
|
@action
|
||||||
def get_youtube_url(self, url):
|
def get_youtube_url(self, url):
|
||||||
m = re.match('youtube:video:(.*)', url)
|
m = re.match('youtube:video:(.*)', url)
|
||||||
|
|
|
@ -155,18 +155,12 @@ class MediaKodiPlugin(MediaPlugin):
|
||||||
:param resource: URL or path to the media to be played
|
:param resource: URL or path to the media to be played
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if resource.startswith('youtube:video:') \
|
youtube_id = self.get_youtube_id(resource)
|
||||||
or resource.startswith('https://www.youtube.com/watch?v='):
|
if youtube_id:
|
||||||
m1 = re.match('youtube:video:([^:?&]+)', resource)
|
try:
|
||||||
m2 = re.match('https://www.youtube.com/watch?v=([^:?&#/]+)', resource)
|
resource = self.get_youtube_url('https://www.youtube.com/watch?v=' + youtube_id)
|
||||||
youtube_id = None
|
except Exception as e:
|
||||||
|
self.logger.warning('youtube-dl error, falling back to Kodi YouTube plugin: {}'.format(str(e)))
|
||||||
if m1:
|
|
||||||
youtube_id = m1.group(1)
|
|
||||||
elif m2:
|
|
||||||
youtube_id = m2.group(1)
|
|
||||||
|
|
||||||
if youtube_id:
|
|
||||||
resource = 'plugin://plugin.video.youtube/?action=play_video&videoid=' + youtube_id
|
resource = 'plugin://plugin.video.youtube/?action=play_video&videoid=' + youtube_id
|
||||||
|
|
||||||
if resource.startswith('file://'):
|
if resource.startswith('file://'):
|
||||||
|
|
Loading…
Reference in a new issue