]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/adobetv.py
debian/control: Prefer mplayer to mplayer2 in Recommends.
[youtubedl] / youtube_dl / extractor / adobetv.py
1 from __future__ import unicode_literals
2
3 from .common import InfoExtractor
4 from ..utils import (
5 parse_duration,
6 unified_strdate,
7 str_to_int,
8 float_or_none,
9 ISO639Utils,
10 )
11
12
13 class AdobeTVIE(InfoExtractor):
14 _VALID_URL = r'https?://tv\.adobe\.com/watch/[^/]+/(?P<id>[^/]+)'
15
16 _TEST = {
17 'url': 'http://tv.adobe.com/watch/the-complete-picture-with-julieanne-kost/quick-tip-how-to-draw-a-circle-around-an-object-in-photoshop/',
18 'md5': '9bc5727bcdd55251f35ad311ca74fa1e',
19 'info_dict': {
20 'id': 'quick-tip-how-to-draw-a-circle-around-an-object-in-photoshop',
21 'ext': 'mp4',
22 'title': 'Quick Tip - How to Draw a Circle Around an Object in Photoshop',
23 'description': 'md5:99ec318dc909d7ba2a1f2b038f7d2311',
24 'thumbnail': 're:https?://.*\.jpg$',
25 'upload_date': '20110914',
26 'duration': 60,
27 'view_count': int,
28 },
29 }
30
31 def _real_extract(self, url):
32 video_id = self._match_id(url)
33 webpage = self._download_webpage(url, video_id)
34
35 player = self._parse_json(
36 self._search_regex(r'html5player:\s*({.+?})\s*\n', webpage, 'player'),
37 video_id)
38
39 title = player.get('title') or self._search_regex(
40 r'data-title="([^"]+)"', webpage, 'title')
41 description = self._og_search_description(webpage)
42 thumbnail = self._og_search_thumbnail(webpage)
43
44 upload_date = unified_strdate(
45 self._html_search_meta('datepublished', webpage, 'upload date'))
46
47 duration = parse_duration(
48 self._html_search_meta('duration', webpage, 'duration') or
49 self._search_regex(
50 r'Runtime:\s*(\d{2}:\d{2}:\d{2})',
51 webpage, 'duration', fatal=False))
52
53 view_count = str_to_int(self._search_regex(
54 r'<div class="views">\s*Views?:\s*([\d,.]+)\s*</div>',
55 webpage, 'view count'))
56
57 formats = [{
58 'url': source['src'],
59 'format_id': source.get('quality') or source['src'].split('-')[-1].split('.')[0] or None,
60 'tbr': source.get('bitrate'),
61 } for source in player['sources']]
62 self._sort_formats(formats)
63
64 return {
65 'id': video_id,
66 'title': title,
67 'description': description,
68 'thumbnail': thumbnail,
69 'upload_date': upload_date,
70 'duration': duration,
71 'view_count': view_count,
72 'formats': formats,
73 }
74
75
76 class AdobeTVVideoIE(InfoExtractor):
77 _VALID_URL = r'https?://video\.tv\.adobe\.com/v/(?P<id>\d+)'
78
79 _TEST = {
80 # From https://helpx.adobe.com/acrobat/how-to/new-experience-acrobat-dc.html?set=acrobat--get-started--essential-beginners
81 'url': 'https://video.tv.adobe.com/v/2456/',
82 'md5': '43662b577c018ad707a63766462b1e87',
83 'info_dict': {
84 'id': '2456',
85 'ext': 'mp4',
86 'title': 'New experience with Acrobat DC',
87 'description': 'New experience with Acrobat DC',
88 'duration': 248.667,
89 },
90 }
91
92 def _real_extract(self, url):
93 video_id = self._match_id(url)
94
95 webpage = self._download_webpage(url, video_id)
96
97 player_params = self._parse_json(self._search_regex(
98 r'var\s+bridge\s*=\s*([^;]+);', webpage, 'player parameters'),
99 video_id)
100
101 formats = [{
102 'url': source['src'],
103 'width': source.get('width'),
104 'height': source.get('height'),
105 'tbr': source.get('bitrate'),
106 } for source in player_params['sources']]
107
108 # For both metadata and downloaded files the duration varies among
109 # formats. I just pick the max one
110 duration = max(filter(None, [
111 float_or_none(source.get('duration'), scale=1000)
112 for source in player_params['sources']]))
113
114 subtitles = {}
115 for translation in player_params.get('translations', []):
116 lang_id = translation.get('language_w3c') or ISO639Utils.long2short(translation['language_medium'])
117 if lang_id not in subtitles:
118 subtitles[lang_id] = []
119 subtitles[lang_id].append({
120 'url': translation['vttPath'],
121 'ext': 'vtt',
122 })
123
124 return {
125 'id': video_id,
126 'formats': formats,
127 'title': player_params['title'],
128 'description': self._og_search_description(webpage),
129 'duration': duration,
130 'subtitles': subtitles,
131 }