[Cinemassacre] Move to a standalone module
[youtube-dl] / youtube_dl / extractor / cinemassacre.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 ExtractorError
8 from .bliptv import BlipTVIE
9
10
11 class CinemassacreIE(InfoExtractor):
12     _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>[^?#/]+)'
13     _TESTS = [
14         {
15             'url': 'http://cinemassacre.com/2012/11/10/avgn-the-movie-trailer/',
16             'md5': 'fde81fbafaee331785f58cd6c0d46190',
17             'info_dict': {
18                 'id': 'Cinemassacre-19911',
19                 'ext': 'mp4',
20                 'upload_date': '20121110',
21                 'title': '“Angry Video Game Nerd: The Movie” – Trailer',
22                 'description': 'md5:fb87405fcb42a331742a0dce2708560b',
23             },
24         },
25         {
26             'url': 'http://cinemassacre.com/2013/10/02/the-mummys-hand-1940',
27             'md5': 'd72f10cd39eac4215048f62ab477a511',
28             'info_dict': {
29                 'id': 'Cinemassacre-521be8ef82b16',
30                 'ext': 'mp4',
31                 'upload_date': '20131002',
32                 'title': 'The Mummy’s Hand (1940)',
33             },
34         },
35         {
36             'url': 'http://cinemassacre.com/2006/12/07/chronologically-confused-about-bad-movie-and-video-game-sequel-titles/',
37             'md5': 'ca9b3c8dd5a66f9375daeb5135f5a3de',
38             'info_dict': {
39                 'id': '4065369',
40                 'ext': 'flv',
41                 'title': 'AVGN: Chronologically Confused about Bad Movie and Video Game Sequel Titles',
42                 'upload_date': '20061207',
43                 'uploader': 'cinemassacre',
44                 'uploader_id': '250778',
45                 'timestamp': 1283233867,
46                 'description': 'md5:0a108c78d130676b207d0f6d029ecffd',
47             }
48         }
49     ]
50
51     def _real_extract(self, url):
52         mobj = re.match(self._VALID_URL, url)
53         display_id = mobj.group('display_id')
54         video_date = mobj.group('date_y') + mobj.group('date_m') + mobj.group('date_d')
55
56         webpage = self._download_webpage(url, display_id)
57
58         playerdata_url = self._search_regex(
59             r'src="(http://player\.screenwavemedia\.com/play/[a-zA-Z]+\.php\?[^"]*\bid=.+?)"',
60             webpage, 'player data URL', default=None)
61         if not playerdata_url:
62             playerdata_url = BlipTVIE._extract_url(webpage)
63         if not playerdata_url:
64             raise ExtractorError('Unable to find player data')
65
66         video_title = self._html_search_regex(
67             r'<title>(?P<title>.+?)\|', webpage, 'title')
68         video_description = self._html_search_regex(
69             r'<div class="entry-content">(?P<description>.+?)</div>',
70             webpage, 'description', flags=re.DOTALL, fatal=False)
71         video_thumbnail = self._og_search_thumbnail(webpage)
72
73         return {
74             '_type': 'url_transparent',
75             'display_id': display_id,
76             'title': video_title,
77             'description': video_description,
78             'upload_date': video_date,
79             'thumbnail': video_thumbnail,
80             'url': playerdata_url,
81         }