detect vevo embed
[youtube-dl] / youtube_dl / extractor / worldstarhiphop.py
1 import re
2
3 from .common import InfoExtractor
4
5
6 class WorldStarHipHopIE(InfoExtractor):
7     _VALID_URL = r'https?://(?:www|m)\.worldstar(?:candy|hiphop)\.com/videos/video\.php\?v=(?P<id>.*)'
8     _TEST = {
9         "url": "http://www.worldstarhiphop.com/videos/video.php?v=wshh6a7q1ny0G34ZwuIO",
10         "file": "wshh6a7q1ny0G34ZwuIO.mp4",
11         "md5": "9d04de741161603bf7071bbf4e883186",
12         "info_dict": {
13             "title": "Video: KO Of The Week: MMA Fighter Gets Knocked Out By Swift Head Kick!"
14         }
15     }
16
17
18     def _real_extract(self, url):
19         m = re.match(self._VALID_URL, url)
20         video_id = m.group('id')
21
22         webpage_src = self._download_webpage(url, video_id)
23
24         video_url = self._search_regex('videoId=(.*?)&amp?',
25             webpage_src, u'video URL', fatal=False)
26
27         if video_url:
28             self.to_screen(u'Vevo video detected:')
29             vevo_id = 'vevo:%s' video_url
30             self.url_result(vevo_id)
31
32         video_url = self._search_regex(r'so\.addVariable\("file","(.*?)"\)',
33             webpage_src, u'video URL')
34
35         if 'youtube' in video_url:
36             self.to_screen(u'Youtube video detected:')
37             return self.url_result(video_url, ie='Youtube')
38
39         if 'mp4' in video_url:
40             ext = 'mp4'
41         else:
42             ext = 'flv'
43
44         video_title = self._html_search_regex(r"<title>(.*)</title>",
45             webpage_src, u'title')
46
47         # Getting thumbnail and if not thumbnail sets correct title for WSHH candy video.
48         thumbnail = self._html_search_regex(r'rel="image_src" href="(.*)" />',
49             webpage_src, u'thumbnail', fatal=False)
50
51         if not thumbnail:
52             _title = r"""candytitles.*>(.*)</span>"""
53             mobj = re.search(_title, webpage_src)
54             if mobj is not None:
55                 video_title = mobj.group(1)
56
57         results = [{
58                     'id': video_id,
59                     'url' : video_url,
60                     'title' : video_title,
61                     'thumbnail' : thumbnail,
62                     'ext' : ext,
63                     }]
64         return results