[Cinemassacre] Add detection for videos from blip.tv
[youtube-dl] / youtube_dl / extractor / screenwavemedia.py
1 # encoding: utf-8
2 from __future__ import unicode_literals
3
4 import re
5
6 from .common import InfoExtractor
7 from ..utils import (
8     int_or_none,
9     unified_strdate,
10     ExtractorError
11 )
12 from .bliptv import BlipTVIE
13
14
15 class ScreenwaveMediaIE(InfoExtractor):
16     _VALID_URL = r'http://player\.screenwavemedia\.com/play/[a-zA-Z]+\.php\?[^"]*\bid=(?P<id>.+)'
17
18     _TESTS = [{
19         'url': 'http://player.screenwavemedia.com/play/play.php?playerdiv=videoarea&companiondiv=squareAd&id=Cinemassacre-19911',
20         'only_matching': True,
21     }]
22
23     def _real_extract(self, url):
24         video_id = self._match_id(url)
25         playerdata = self._download_webpage(url, video_id, 'Downloading player webpage')
26
27         vidtitle = self._search_regex(
28             r'\'vidtitle\'\s*:\s*"([^"]+)"', playerdata, 'vidtitle').replace('\\/', '/')
29         vidurl = self._search_regex(
30             r'\'vidurl\'\s*:\s*"([^"]+)"', playerdata, 'vidurl').replace('\\/', '/')
31
32         videolist_url = None
33
34         mobj = re.search(r"'videoserver'\s*:\s*'(?P<videoserver>[^']+)'", playerdata)
35         if mobj:
36             videoserver = mobj.group('videoserver')
37             mobj = re.search(r'\'vidid\'\s*:\s*"(?P<vidid>[^\']+)"', playerdata)
38             vidid = mobj.group('vidid') if mobj else video_id
39             videolist_url = 'http://%s/vod/smil:%s.smil/jwplayer.smil' % (videoserver, vidid)
40         else:
41             mobj = re.search(r"file\s*:\s*'(?P<smil>http.+?/jwplayer\.smil)'", playerdata)
42             if mobj:
43                 videolist_url = mobj.group('smil')
44
45         if videolist_url:
46             videolist = self._download_xml(videolist_url, video_id, 'Downloading videolist XML')
47             formats = []
48             baseurl = vidurl[:vidurl.rfind('/') + 1]
49             for video in videolist.findall('.//video'):
50                 src = video.get('src')
51                 if not src:
52                     continue
53                 file_ = src.partition(':')[-1]
54                 width = int_or_none(video.get('width'))
55                 height = int_or_none(video.get('height'))
56                 bitrate = int_or_none(video.get('system-bitrate'), scale=1000)
57                 format = {
58                     'url': baseurl + file_,
59                     'format_id': src.rpartition('.')[0].rpartition('_')[-1],
60                 }
61                 if width or height:
62                     format.update({
63                         'tbr': bitrate,
64                         'width': width,
65                         'height': height,
66                     })
67                 else:
68                     format.update({
69                         'abr': bitrate,
70                         'vcodec': 'none',
71                     })
72                 formats.append(format)
73         else:
74             formats = [{
75                 'url': vidurl,
76             }]
77         self._sort_formats(formats)
78
79         return {
80             'id': video_id,
81             'title': vidtitle,
82             'formats': formats,
83         }
84
85
86 class CinemassacreIE(InfoExtractor):
87     _VALID_URL = 'https?://(?:www\.)?cinemassacre\.com/(?P<date_y>[0-9]{4})/(?P<date_m>[0-9]{2})/(?P<date_d>[0-9]{2})/(?P<display_id>[^?#/]+)'
88     _TESTS = [
89         {
90             'url': 'http://cinemassacre.com/2012/11/10/avgn-the-movie-trailer/',
91             'md5': 'fde81fbafaee331785f58cd6c0d46190',
92             'info_dict': {
93                 'id': 'Cinemassacre-19911',
94                 'ext': 'mp4',
95                 'upload_date': '20121110',
96                 'title': '“Angry Video Game Nerd: The Movie” – Trailer',
97                 'description': 'md5:fb87405fcb42a331742a0dce2708560b',
98             },
99         },
100         {
101             'url': 'http://cinemassacre.com/2013/10/02/the-mummys-hand-1940',
102             'md5': 'd72f10cd39eac4215048f62ab477a511',
103             'info_dict': {
104                 'id': 'Cinemassacre-521be8ef82b16',
105                 'ext': 'mp4',
106                 'upload_date': '20131002',
107                 'title': 'The Mummy’s Hand (1940)',
108             },
109         },
110         {
111             'url': 'http://cinemassacre.com/2006/12/07/chronologically-confused-about-bad-movie-and-video-game-sequel-titles/',
112             'md5': 'ca9b3c8dd5a66f9375daeb5135f5a3de',
113             'info_dict': {
114                 'id': '4065369',
115                 'ext': 'flv',
116                 'title': 'AVGN: Chronologically Confused about Bad Movie and Video Game Sequel Titles',
117                 'upload_date': '20061207',
118                 'uploader': 'cinemassacre',
119                 'uploader_id': '250778',
120                 'timestamp': 1283233867,
121                 'description': 'md5:0a108c78d130676b207d0f6d029ecffd',
122             }
123         }
124     ]
125
126     def _real_extract(self, url):
127         mobj = re.match(self._VALID_URL, url)
128         display_id = mobj.group('display_id')
129         video_date = mobj.group('date_y') + mobj.group('date_m') + mobj.group('date_d')
130
131         webpage = self._download_webpage(url, display_id)
132
133         playerdata_url = self._search_regex(
134             r'src="(http://player\.screenwavemedia\.com/play/[a-zA-Z]+\.php\?[^"]*\bid=.+?)"',
135             webpage, 'player data URL', default=None)
136         if not playerdata_url:
137             playerdata_url = BlipTVIE._extract_url(webpage)
138         if not playerdata_url:
139             raise ExtractorError('Unable to find player data')
140
141         video_title = self._html_search_regex(
142             r'<title>(?P<title>.+?)\|', webpage, 'title')
143         video_description = self._html_search_regex(
144             r'<div class="entry-content">(?P<description>.+?)</div>',
145             webpage, 'description', flags=re.DOTALL, fatal=False)
146         video_thumbnail = self._og_search_thumbnail(webpage)
147
148         return {
149             '_type': 'url_transparent',
150             'display_id': display_id,
151             'title': video_title,
152             'description': video_description,
153             'upload_date': video_date,
154             'thumbnail': video_thumbnail,
155             'url': playerdata_url,
156         }
157
158
159 class TeamFourIE(InfoExtractor):
160     _VALID_URL = r'https?://(?:www\.)?teamfourstar\.com/video/(?P<id>[a-z0-9\-]+)/?'
161     _TEST = {
162         'url': 'http://teamfourstar.com/video/a-moment-with-tfs-episode-4/',
163         'info_dict': {
164             'id': 'TeamFourStar-5292a02f20bfa',
165             'ext': 'mp4',
166             'upload_date': '20130401',
167             'description': 'Check out this and more on our website: http://teamfourstar.com\nTFS Store: http://sharkrobot.com/team-four-star\nFollow on Twitter: http://twitter.com/teamfourstar\nLike on FB: http://facebook.com/teamfourstar',
168             'title': 'A Moment With TFS Episode 4',
169         }
170     }
171
172     def _real_extract(self, url):
173         display_id = self._match_id(url)
174         webpage = self._download_webpage(url, display_id)
175
176         playerdata_url = self._search_regex(
177             r'src="(http://player\.screenwavemedia\.com/play/[a-zA-Z]+\.php\?[^"]*\bid=.+?)"',
178             webpage, 'player data URL')
179
180         video_title = self._html_search_regex(
181             r'<div class="heroheadingtitle">(?P<title>.+?)</div>',
182             webpage, 'title')
183         video_date = unified_strdate(self._html_search_regex(
184             r'<div class="heroheadingdate">(?P<date>.+?)</div>',
185             webpage, 'date', fatal=False))
186         video_description = self._html_search_regex(
187             r'(?s)<div class="postcontent">(?P<description>.+?)</div>',
188             webpage, 'description', fatal=False)
189         video_thumbnail = self._og_search_thumbnail(webpage)
190
191         return {
192             '_type': 'url_transparent',
193             'display_id': display_id,
194             'title': video_title,
195             'description': video_description,
196             'upload_date': video_date,
197             'thumbnail': video_thumbnail,
198             'url': playerdata_url,
199         }