Merge pull request #8611 from remitamine/ffmpegfd
[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': 'mp4',
18             'title': 'VICE_COWBOYCAPITALISTS_PART01_v1_VICE_WM_1080p.mov',
19             'duration': 725.983,
20         },
21         'params': {
22             # Requires ffmpeg (m3u8 manifest)
23             'skip_download': True,
24         },
25     }, {
26         'url': 'https://news.vice.com/video/experimenting-on-animals-inside-the-monkey-lab',
27         'only_matching': True,
28     }, {
29         'url': 'http://www.vice.com/ru/video/big-night-out-ibiza-clive-martin-229',
30         'only_matching': True,
31     }, {
32         'url': 'https://munchies.vice.com/en/videos/watch-the-trailer-for-our-new-series-the-pizza-show',
33         'only_matching': True,
34     }]
35
36     def _real_extract(self, url):
37         video_id = self._match_id(url)
38         webpage = self._download_webpage(url, video_id)
39         try:
40             embed_code = self._search_regex(
41                 r'embedCode=([^&\'"]+)', webpage,
42                 'ooyala embed code')
43             ooyala_url = OoyalaIE._url_for_embed_code(embed_code)
44         except ExtractorError:
45             raise ExtractorError('The page doesn\'t contain a video', expected=True)
46         return self.url_result(ooyala_url, ie='Ooyala')
47
48
49 class ViceShowIE(InfoExtractor):
50     _VALID_URL = r'https?://(?:.+?\.)?vice\.com/(?:[^/]+/)?show/(?P<id>[^/?#&]+)'
51
52     _TEST = {
53         'url': 'https://munchies.vice.com/en/show/fuck-thats-delicious-2',
54         'info_dict': {
55             'id': 'fuck-thats-delicious-2',
56             'title': "Fuck, That's Delicious",
57             'description': 'Follow the culinary adventures of rapper Action Bronson during his ongoing world tour.',
58         },
59         'playlist_count': 17,
60     }
61
62     def _real_extract(self, url):
63         show_id = self._match_id(url)
64         webpage = self._download_webpage(url, show_id)
65
66         entries = [
67             self.url_result(video_url, ViceIE.ie_key())
68             for video_url, _ in re.findall(
69                 r'<h2[^>]+class="article-title"[^>]+data-id="\d+"[^>]*>\s*<a[^>]+href="(%s.*?)"'
70                 % ViceIE._VALID_URL, webpage)]
71
72         title = self._search_regex(
73             r'<title>(.+?)</title>', webpage, 'title', default=None)
74         if title:
75             title = re.sub(r'(.+)\s*\|\s*.+$', r'\1', title).strip()
76         description = self._html_search_meta('description', webpage, 'description')
77
78         return self.playlist_result(entries, show_id, title, description)