]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/zippcast.py
Fine tune the changelog.
[youtubedl] / youtube_dl / extractor / zippcast.py
1 from __future__ import unicode_literals
2
3 import re
4
5 from .common import InfoExtractor
6 from ..utils import (
7 determine_ext,
8 str_to_int,
9 )
10
11
12 class ZippCastIE(InfoExtractor):
13 _VALID_URL = r'https?://(?:www\.)?zippcast\.com/(?:video/|videoview\.php\?.*\bvplay=)(?P<id>[0-9a-zA-Z]+)'
14 _TESTS = [{
15 # m3u8, hq direct link
16 'url': 'http://www.zippcast.com/video/c9cfd5c7e44dbc29c81',
17 'md5': '5ea0263b5606866c4d6cda0fc5e8c6b6',
18 'info_dict': {
19 'id': 'c9cfd5c7e44dbc29c81',
20 'ext': 'mp4',
21 'title': '[Vinesauce] Vinny - Digital Space Traveler',
22 'description': 'Muted on youtube, but now uploaded in it\'s original form.',
23 'thumbnail': 're:^https?://.*\.jpg$',
24 'uploader': 'vinesauce',
25 'view_count': int,
26 'categories': ['Entertainment'],
27 'tags': list,
28 },
29 }, {
30 # f4m, lq ipod direct link
31 'url': 'http://www.zippcast.com/video/b79c0a233e9c6581775',
32 'only_matching': True,
33 }, {
34 'url': 'http://www.zippcast.com/videoview.php?vplay=c9cfd5c7e44dbc29c81&auto=no',
35 'only_matching': True,
36 }]
37
38 def _real_extract(self, url):
39 video_id = self._match_id(url)
40
41 webpage = self._download_webpage(
42 'http://www.zippcast.com/video/%s' % video_id, video_id)
43
44 formats = []
45 video_url = self._search_regex(
46 r'<source[^>]+src=(["\'])(?P<url>.+?)\1', webpage,
47 'video url', default=None, group='url')
48 if video_url:
49 formats.append({
50 'url': video_url,
51 'format_id': 'http',
52 'preference': 0, # direct link is almost always of worse quality
53 })
54 src_url = self._search_regex(
55 r'src\s*:\s*(?:escape\()?(["\'])(?P<url>http://.+?)\1',
56 webpage, 'src', default=None, group='url')
57 ext = determine_ext(src_url)
58 if ext == 'm3u8':
59 formats.extend(self._extract_m3u8_formats(
60 src_url, video_id, 'mp4', entry_protocol='m3u8_native',
61 m3u8_id='hls', fatal=False))
62 elif ext == 'f4m':
63 formats.extend(self._extract_f4m_formats(
64 src_url, video_id, f4m_id='hds', fatal=False))
65 self._sort_formats(formats)
66
67 title = self._og_search_title(webpage)
68 description = self._og_search_description(webpage) or self._html_search_meta(
69 'description', webpage)
70 uploader = self._search_regex(
71 r'<a[^>]+href="https?://[^/]+/profile/[^>]+>([^<]+)</a>',
72 webpage, 'uploader', fatal=False)
73 thumbnail = self._og_search_thumbnail(webpage)
74 view_count = str_to_int(self._search_regex(
75 r'>([\d,.]+) views!', webpage, 'view count', fatal=False))
76
77 categories = re.findall(
78 r'<a[^>]+href="https?://[^/]+/categories/[^"]+">([^<]+),?<',
79 webpage)
80 tags = re.findall(
81 r'<a[^>]+href="https?://[^/]+/search/tags/[^"]+">([^<]+),?<',
82 webpage)
83
84 return {
85 'id': video_id,
86 'title': title,
87 'description': description,
88 'thumbnail': thumbnail,
89 'uploader': uploader,
90 'view_count': view_count,
91 'categories': categories,
92 'tags': tags,
93 'formats': formats,
94 }