forked from platypush/platypush
More robust URL query for YouTube
This commit is contained in:
parent
93ac6c8af9
commit
b716b1a0c1
1 changed files with 9 additions and 10 deletions
|
@ -483,27 +483,26 @@ class MediaPlugin(Plugin):
|
||||||
patterns = [
|
patterns = [
|
||||||
re.compile(pattern)
|
re.compile(pattern)
|
||||||
for pattern in [
|
for pattern in [
|
||||||
r'https?://www.youtube.com/watch?v=([^&#]+)'
|
r'https?://www.youtube.com/watch\?v=([^&#]+)'
|
||||||
r'https?://youtube.com/watch?v=([^&#]+)'
|
r'https?://youtube.com/watch\?v=([^&#]+)'
|
||||||
r'https?://youtu.be/([^&#/]+)'
|
r'https?://youtu.be/([^&#/]+)'
|
||||||
r'youtube:video:([^&#:])'
|
r'youtube:video:([^&#:])'
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
|
|
||||||
for pattern in patterns:
|
for pattern in patterns:
|
||||||
m = pattern.match(url)
|
m = pattern.search(url)
|
||||||
if m:
|
if m:
|
||||||
return m.group(1)
|
return m.group(1)
|
||||||
|
|
||||||
@action
|
@action
|
||||||
def get_youtube_url(self, url):
|
def get_youtube_url(self, url):
|
||||||
m = re.match('youtube:video:(.*)', url)
|
youtube_id = self.get_youtube_id(url)
|
||||||
if m:
|
if youtube_id:
|
||||||
url = 'https://www.youtube.com/watch?v={}'.format(m.group(1))
|
url = 'https://www.youtube.com/watch?v={}'.format(youtube_id)
|
||||||
|
proc = subprocess.Popen(['youtube-dl', '-f', 'best', '-g', url], stdout=subprocess.PIPE)
|
||||||
proc = subprocess.Popen(['youtube-dl', '-f', 'best', '-g', url], stdout=subprocess.PIPE)
|
raw_url = proc.stdout.read().decode("utf-8", "strict")[:-1]
|
||||||
raw_url = proc.stdout.read().decode("utf-8", "strict")[:-1]
|
return raw_url if raw_url else url
|
||||||
return raw_url if raw_url else url
|
|
||||||
|
|
||||||
@action
|
@action
|
||||||
def get_youtube_info(self, url):
|
def get_youtube_info(self, url):
|
||||||
|
|
Loading…
Reference in a new issue