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