[subtitles] Added tests to check correct behavior when no subtitles are
[youtube-dl] / youtube_dl / extractor / traileraddict.py
1 import re
2
3 from .common import InfoExtractor
4
5
6 class TrailerAddictIE(InfoExtractor):
7     _VALID_URL = r'(?:http://)?(?:www\.)?traileraddict\.com/trailer/([^/]+)/(?:trailer|feature-trailer)'
8     _TEST = {
9         u'url': u'http://www.traileraddict.com/trailer/prince-avalanche/trailer',
10         u'file': u'76184.mp4',
11         u'md5': u'41365557f3c8c397d091da510e73ceb4',
12         u'info_dict': {
13             u"title": u"Prince Avalanche Trailer",
14             u"description": u"Trailer for Prince Avalanche.Two highway road workers spend the summer of 1988 away from their city lives. The isolated landscape becomes a place of misadventure as the men find themselves at odds with each other and the women they left behind."
15         }
16     }
17
18     def _real_extract(self, url):
19         mobj = re.match(self._VALID_URL, url)
20         video_id = mobj.group(1)
21         webpage = self._download_webpage(url, video_id)
22         
23         title = self._search_regex(r'<title>(.+?)</title>',
24                 webpage, 'video title').replace(' - Trailer Addict','')
25         view_count = self._search_regex(r'Views: (.+?)<br />',
26                 webpage, 'Views Count')
27         video_id = self._og_search_property('video', webpage, 'Video id').split('=')[1]
28
29         info_url = "http://www.traileraddict.com/fvar.php?tid=%s" %(str(video_id))
30         info_webpage = self._download_webpage(info_url, video_id , "Downloading the info webpage")
31         
32         final_url = self._search_regex(r'&fileurl=(.+)',
33                 info_webpage, 'Download url').replace('%3F','?')
34         thumbnail_url = self._search_regex(r'&image=(.+?)&',
35                 info_webpage, 'thumbnail url')
36         ext = final_url.split('.')[-1].split('?')[0]
37         
38         return [{
39             'id'          : video_id,
40             'url'         : final_url,
41             'ext'         : ext,
42             'title'       : title,
43             'thumbnail'   : thumbnail_url,
44             'description' : self._og_search_description(webpage),
45             'view_count'  : view_count,
46         }]