]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/cinemassacre.py
Add CinemassacreIE
[yt-dlp.git] / youtube_dl / extractor / cinemassacre.py
CommitLineData
400afdda 1# encoding: utf-8
2import re
3
4from .common import InfoExtractor
5from ..utils import (
6 ExtractorError,
7)
8
9class CinemassacreIE(InfoExtractor):
10 """Information Extractor for Cinemassacre"""
11 _VALID_URL = r'(?:http://)?(?:www\.)?(?P<url>cinemassacre\.com/(?P<date_Y>[0-9]{4})/(?P<date_m>[0-9]{2})/(?P<date_d>[0-9]{2})/.+?)(?:[/?].*)?'
12 _TESTS = [{
13 u'url': u'http://cinemassacre.com/2012/11/10/avgn-the-movie-trailer/',
14 u'file': u'19911.mp4',
15 u'info_dict': {
16 u'upload_date': u'20121110',
17 u'title': u'“Angry Video Game Nerd: The Movie” – Trailer',
18 #u'description': u'“Angry Video Game Nerd: The Movie” is...', # Description is too long
19 },
20 u'params': {
21 u'skip_download': True,
22 },
23 }]
24
25 def _real_extract(self,url):
26 mobj = re.match(self._VALID_URL, url)
27
28 webpage_url = u'http://' + mobj.group('url')
29 webpage = self._download_webpage(webpage_url, None) # Don't know video id yet
30 video_date = mobj.group('date_Y') + mobj.group('date_m') + mobj.group('date_d')
31 video_id = self._html_search_regex(r'src="http://player\.screenwavemedia\.com/play/embed\.php\?id=(?P<video_id>.+?)"',
32 webpage, u'video_id')
33 video_title = self._html_search_regex(r'<h1 class="entry-title">(?P<title>.+?)</h1>[^<]*</div>',
34 webpage, u'title')
35 video_description = self._html_search_regex(r'<div class="entry-content">(?P<description>.+?)</div>',
36 webpage, u'description', flags=re.DOTALL, fatal=False)
37
38 playerdata_url = u'http://player.screenwavemedia.com/play/player.php?id=' + video_id
39 playerdata = self._download_webpage(playerdata_url, video_id)
40 base_url = self._html_search_regex(r'\'streamer\': \'(?P<base_url>rtmp://[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})/vod\'',
41 playerdata, u'base_url')
42 base_url += '/Cinemassacre/'
43 # The file names in playerdata are wrong for some videos???
44 sd_file = 'Cinemassacre-%s_high.mp4' % video_id
45 hd_file = 'Cinemassacre-%s.mp4' % video_id
46 video_thumbnail = 'http://image.screenwavemedia.com/Cinemassacre/Cinemassacre-%s_thumb_640x360.jpg' % video_id
47
48 formats = [{
49 'id': video_id,
50 'url': base_url + hd_file,
51 'format': 'hd',
52 'ext': 'mp4',
53 'title': video_title,
54 'description': video_description,
55 'upload_date': video_date,
56 'thumbnail': video_thumbnail,
57 },
58 {
59 'id': video_id,
60 'url': base_url + sd_file,
61 'ext': 'mp4',
62 'format': 'sd',
63 'title': video_title,
64 'description': video_description,
65 'upload_date': video_date,
66 'thumbnail': video_thumbnail,
67 }]
68
69 if self._downloader.params.get('listformats', None):
70 self._print_formats(formats)
71 return
72
73 req_format = self._downloader.params.get('format', 'best')
74 self.to_screen(u'Format: %s' % req_format)
75
76 if req_format is None or req_format == 'best':
77 return [formats[0]]
78 elif req_format == 'worst':
79 return [formats[-1]]
80 elif req_format in ('-1', 'all'):
81 return formats
82 else:
83 format = self._specific( req_format, formats )
84 if format is None:
85 raise ExtractorError(u'Requested format not available')
86 return [format]
87
88 def _print_formats(self, formats):
89 """Print all available formats"""
90 print(u'Available formats:')
91 print(u'ext\t\tformat')
92 print(u'---------------------------------')
93 for format in formats:
94 print(u'%s\t\t%s' % (format['ext'], format['format']))
95
96 def _specific(self, req_format, formats):
97 for x in formats:
98 if x["format"] == req_format:
99 return x
100 return None