Merge pull request #9195 from remitamine/ffmpeg-pipe
[youtube-dl] / youtube_dl / extractor / vice.py
1 from __future__ import unicode_literals
2
3 import re
4
5 from .common import InfoExtractor
6 from .ooyala import OoyalaIE
7 from ..utils import ExtractorError
8
9
10 class ViceIE(InfoExtractor):
11     _VALID_URL = r'https?://(?:.+?\.)?vice\.com/(?:[^/]+/)?videos?/(?P<id>[^/?#&]+)'
12
13     _TESTS = [{
14         'url': 'http://www.vice.com/video/cowboy-capitalists-part-1',
15         'info_dict': {
16             'id': '43cW1mYzpia9IlestBjVpd23Yu3afAfp',
17             'ext': 'flv',
18             'title': 'VICE_COWBOYCAPITALISTS_PART01_v1_VICE_WM_1080p.mov',
19             'duration': 725.983,
20         },
21     }, {
22         'url': 'http://www.vice.com/video/how-to-hack-a-car',
23         'md5': '6fb2989a3fed069fb8eab3401fc2d3c9',
24         'info_dict': {
25             'id': '3jstaBeXgAs',
26             'ext': 'mp4',
27             'title': 'How to Hack a Car: Phreaked Out (Episode 2)',
28             'description': 'md5:ee95453f7ff495db8efe14ae8bf56f30',
29             'uploader_id': 'MotherboardTV',
30             'uploader': 'Motherboard',
31             'upload_date': '20140529',
32         },
33     }, {
34         'url': 'https://news.vice.com/video/experimenting-on-animals-inside-the-monkey-lab',
35         'only_matching': True,
36     }, {
37         'url': 'http://www.vice.com/ru/video/big-night-out-ibiza-clive-martin-229',
38         'only_matching': True,
39     }, {
40         'url': 'https://munchies.vice.com/en/videos/watch-the-trailer-for-our-new-series-the-pizza-show',
41         'only_matching': True,
42     }]
43
44     def _real_extract(self, url):
45         video_id = self._match_id(url)
46         webpage = self._download_webpage(url, video_id)
47         try:
48             embed_code = self._search_regex(
49                 r'embedCode=([^&\'"]+)', webpage,
50                 'ooyala embed code', default=None)
51             if embed_code:
52                 ooyala_url = OoyalaIE._url_for_embed_code(embed_code)
53                 return self.url_result('ooyala:%s' % embed_code, 'Ooyala')
54             youtube_id = self._search_regex(
55                 r'data-youtube-id="([^"]+)"', webpage, 'youtube id')
56             return self.url_result(youtube_id, 'Youtube')
57         except ExtractorError:
58             raise ExtractorError('The page doesn\'t contain a video', expected=True)
59
60
61 class ViceShowIE(InfoExtractor):
62     _VALID_URL = r'https?://(?:.+?\.)?vice\.com/(?:[^/]+/)?show/(?P<id>[^/?#&]+)'
63
64     _TEST = {
65         'url': 'https://munchies.vice.com/en/show/fuck-thats-delicious-2',
66         'info_dict': {
67             'id': 'fuck-thats-delicious-2',
68             'title': "Fuck, That's Delicious",
69             'description': 'Follow the culinary adventures of rapper Action Bronson during his ongoing world tour.',
70         },
71         'playlist_count': 17,
72     }
73
74     def _real_extract(self, url):
75         show_id = self._match_id(url)
76         webpage = self._download_webpage(url, show_id)
77
78         entries = [
79             self.url_result(video_url, ViceIE.ie_key())
80             for video_url, _ in re.findall(
81                 r'<h2[^>]+class="article-title"[^>]+data-id="\d+"[^>]*>\s*<a[^>]+href="(%s.*?)"'
82                 % ViceIE._VALID_URL, webpage)]
83
84         title = self._search_regex(
85             r'<title>(.+?)</title>', webpage, 'title', default=None)
86         if title:
87             title = re.sub(r'(.+)\s*\|\s*.+$', r'\1', title).strip()
88         description = self._html_search_meta('description', webpage, 'description')
89
90         return self.playlist_result(entries, show_id, title, description)