Support more YouTube URLs
The regular expression is also more strict, yet accepts the youtu.be short URLs and user page URLs.
This commit is contained in:
parent
740e7f12d2
commit
5e90c1f47c
3 changed files with 7 additions and 1 deletions
|
|
@ -45,7 +45,7 @@ class YoutubeBackend(BaseBackend, ICapVideo):
|
||||||
LICENSE = 'AGPLv3+'
|
LICENSE = 'AGPLv3+'
|
||||||
BROWSER = YoutubeBrowser
|
BROWSER = YoutubeBrowser
|
||||||
|
|
||||||
URL_RE = re.compile(r'https?://.*youtube.com/watch\?v=(.*)')
|
URL_RE = re.compile(r'^https?://(?:\w*\.?youtube\.com/watch\?v=|youtu\.be\/|\w*\.?youtube\.com\/user\/\w+#p\/u\/\d+\/)(.*)$')
|
||||||
AVAILABLE_FORMATS = [38, 37, 22, 45, 35, 34, 43, 18, 6, 5, 17, 13]
|
AVAILABLE_FORMATS = [38, 37, 22, 45, 35, 34, 43, 18, 6, 5, 17, 13]
|
||||||
FORMAT_EXTENSIONS = {
|
FORMAT_EXTENSIONS = {
|
||||||
13: '3gp',
|
13: '3gp',
|
||||||
|
|
|
||||||
|
|
@ -29,4 +29,5 @@ class YoutubeTest(BackendTest):
|
||||||
v = l[0]
|
v = l[0]
|
||||||
self.backend.fillobj(v, ('url',))
|
self.backend.fillobj(v, ('url',))
|
||||||
self.assertTrue(v.url and v.url.startswith('http://'), 'URL for video "%s" not found: %s' % (v.id, v.url))
|
self.assertTrue(v.url and v.url.startswith('http://'), 'URL for video "%s" not found: %s' % (v.id, v.url))
|
||||||
|
assert self.backend.get_video(v.shorturl)
|
||||||
self.backend.browser.openurl(v.url)
|
self.backend.browser.openurl(v.url)
|
||||||
|
|
|
||||||
|
|
@ -28,3 +28,8 @@ class YoutubeVideo(BaseVideo):
|
||||||
@classmethod
|
@classmethod
|
||||||
def id2url(cls, _id):
|
def id2url(cls, _id):
|
||||||
return 'http://www.youtube.com/watch?v=%s' % _id
|
return 'http://www.youtube.com/watch?v=%s' % _id
|
||||||
|
|
||||||
|
def _get_shorturl(self):
|
||||||
|
return 'http://youtu.be/%s' % self.id
|
||||||
|
|
||||||
|
shorturl = property(_get_shorturl)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue