]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/gaia.py
Fix extraction from youtube.
[youtubedl] / youtube_dl / extractor / gaia.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import re
5
6 from .common import InfoExtractor
7 from ..compat import compat_str
8 from ..utils import (
9 int_or_none,
10 str_or_none,
11 strip_or_none,
12 try_get,
13 )
14
15
16 class GaiaIE(InfoExtractor):
17 _VALID_URL = r'https?://(?:www\.)?gaia\.com/video/(?P<id>[^/?]+).*?\bfullplayer=(?P<type>feature|preview)'
18 _TESTS = [{
19 'url': 'https://www.gaia.com/video/connecting-universal-consciousness?fullplayer=feature',
20 'info_dict': {
21 'id': '89356',
22 'ext': 'mp4',
23 'title': 'Connecting with Universal Consciousness',
24 'description': 'md5:844e209ad31b7d31345f5ed689e3df6f',
25 'upload_date': '20151116',
26 'timestamp': 1447707266,
27 'duration': 936,
28 },
29 'params': {
30 # m3u8 download
31 'skip_download': True,
32 },
33 }, {
34 'url': 'https://www.gaia.com/video/connecting-universal-consciousness?fullplayer=preview',
35 'info_dict': {
36 'id': '89351',
37 'ext': 'mp4',
38 'title': 'Connecting with Universal Consciousness',
39 'description': 'md5:844e209ad31b7d31345f5ed689e3df6f',
40 'upload_date': '20151116',
41 'timestamp': 1447707266,
42 'duration': 53,
43 },
44 'params': {
45 # m3u8 download
46 'skip_download': True,
47 },
48 }]
49
50 def _real_extract(self, url):
51 display_id, vtype = re.search(self._VALID_URL, url).groups()
52 node_id = self._download_json(
53 'https://brooklyn.gaia.com/pathinfo', display_id, query={
54 'path': 'video/' + display_id,
55 })['id']
56 node = self._download_json(
57 'https://brooklyn.gaia.com/node/%d' % node_id, node_id)
58 vdata = node[vtype]
59 media_id = compat_str(vdata['nid'])
60 title = node['title']
61
62 media = self._download_json(
63 'https://brooklyn.gaia.com/media/' + media_id, media_id)
64 formats = self._extract_m3u8_formats(
65 media['mediaUrls']['bcHLS'], media_id, 'mp4')
66 self._sort_formats(formats)
67
68 subtitles = {}
69 text_tracks = media.get('textTracks', {})
70 for key in ('captions', 'subtitles'):
71 for lang, sub_url in text_tracks.get(key, {}).items():
72 subtitles.setdefault(lang, []).append({
73 'url': sub_url,
74 })
75
76 fivestar = node.get('fivestar', {})
77 fields = node.get('fields', {})
78
79 def get_field_value(key, value_key='value'):
80 return try_get(fields, lambda x: x[key][0][value_key])
81
82 return {
83 'id': media_id,
84 'display_id': display_id,
85 'title': title,
86 'formats': formats,
87 'description': strip_or_none(get_field_value('body') or get_field_value('teaser')),
88 'timestamp': int_or_none(node.get('created')),
89 'subtitles': subtitles,
90 'duration': int_or_none(vdata.get('duration')),
91 'like_count': int_or_none(try_get(fivestar, lambda x: x['up_count']['value'])),
92 'dislike_count': int_or_none(try_get(fivestar, lambda x: x['down_count']['value'])),
93 'comment_count': int_or_none(node.get('comment_count')),
94 'series': try_get(node, lambda x: x['series']['title'], compat_str),
95 'season_number': int_or_none(get_field_value('season')),
96 'season_id': str_or_none(get_field_value('series_nid', 'nid')),
97 'episode_number': int_or_none(get_field_value('episode')),
98 }