Improve regex for YouTube mobile urls + cover with tests

This commit is contained in:
Juda Kaleta 2014-05-31 10:52:08 +02:00
parent 90ba3b0b53
commit a451e148ec
2 changed files with 5 additions and 1 deletions

View file

@ -211,6 +211,7 @@ class YoutubeBackend(VideoBackend):
re_code = re.compile(
r'''youtu(\.?)be(\.com)?/ # match youtube's domains
(\#/)? # for mobile urls
(embed/)? # match the embed url syntax
(v/)?
(watch\?v=)? # match the youtube page url
@ -235,7 +236,8 @@ class YoutubeBackend(VideoBackend):
try:
code = urlparse.parse_qs(parse_data.query)['v'][0]
except KeyError:
raise UnknownIdException
raise UnknownIdException(
'Cannot get ID from `{0}`'.format(self._url))
return code

View file

@ -56,6 +56,8 @@ class YoutubeBackendTestCase(BackendTestMixin, TestCase):
('https://www.youtube.com/watch?feature=player_embedded&v=2NpZbaAIXag', '2NpZbaAIXag'),
('https://www.youtube.com/watch?v=XPk521voaOE&feature=youtube_gdata_player', 'XPk521voaOE'),
('http://www.youtube.com/watch?v=6xu00J3-g2s&list=PLb5n6wzDlPakFKvJ69rJ9AJW24Aaaki2z', '6xu00J3-g2s'),
('https://m.youtube.com/#/watch?v=IAooXLAPoBQ', 'IAooXLAPoBQ'),
('https://m.youtube.com/watch?v=IAooXLAPoBQ', 'IAooXLAPoBQ')
)
instance = YoutubeBackend