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