]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/funk.py
0ff058619bc05fa6b3d6c0680be56bff957ca802
[youtubedl] / youtube_dl / extractor / funk.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import re
5
6 from .common import InfoExtractor
7 from .nexx import NexxIE
8 from ..utils import (
9 int_or_none,
10 try_get,
11 )
12
13
14 class FunkBaseIE(InfoExtractor):
15 def _make_url_result(self, video):
16 return {
17 '_type': 'url_transparent',
18 'url': 'nexx:741:%s' % video['sourceId'],
19 'ie_key': NexxIE.ie_key(),
20 'id': video['sourceId'],
21 'title': video.get('title'),
22 'description': video.get('description'),
23 'duration': int_or_none(video.get('duration')),
24 'season_number': int_or_none(video.get('seasonNr')),
25 'episode_number': int_or_none(video.get('episodeNr')),
26 }
27
28
29 class FunkMixIE(FunkBaseIE):
30 _VALID_URL = r'https?://(?:www\.)?funk\.net/mix/(?P<id>[^/]+)/(?P<alias>[^/?#&]+)'
31 _TESTS = [{
32 'url': 'https://www.funk.net/mix/59d65d935f8b160001828b5b/die-realste-kifferdoku-aller-zeiten',
33 'md5': '8edf617c2f2b7c9847dfda313f199009',
34 'info_dict': {
35 'id': '123748',
36 'ext': 'mp4',
37 'title': '"Die realste Kifferdoku aller Zeiten"',
38 'description': 'md5:c97160f5bafa8d47ec8e2e461012aa9d',
39 'timestamp': 1490274721,
40 'upload_date': '20170323',
41 },
42 }]
43
44 def _real_extract(self, url):
45 mobj = re.match(self._VALID_URL, url)
46 mix_id = mobj.group('id')
47 alias = mobj.group('alias')
48
49 lists = self._download_json(
50 'https://www.funk.net/api/v3.1/curation/curatedLists/',
51 mix_id, headers={
52 'authorization': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJjbGllbnROYW1lIjoiY3VyYXRpb24tdG9vbC12Mi4wIiwic2NvcGUiOiJzdGF0aWMtY29udGVudC1hcGksY3VyYXRpb24tc2VydmljZSxzZWFyY2gtYXBpIn0.SGCC1IXHLtZYoo8PvRKlU2gXH1su8YSu47sB3S4iXBI',
53 'Referer': url,
54 }, query={
55 'size': 100,
56 })['result']['lists']
57
58 metas = next(
59 l for l in lists
60 if mix_id in (l.get('entityId'), l.get('alias')))['videoMetas']
61 video = next(
62 meta['videoDataDelegate']
63 for meta in metas if meta.get('alias') == alias)
64
65 return self._make_url_result(video)
66
67
68 class FunkChannelIE(FunkBaseIE):
69 _VALID_URL = r'https?://(?:www\.)?funk\.net/channel/(?P<id>[^/]+)/(?P<alias>[^/?#&]+)'
70 _TESTS = [{
71 'url': 'https://www.funk.net/channel/ba/die-lustigsten-instrumente-aus-dem-internet-teil-2',
72 'info_dict': {
73 'id': '1155821',
74 'ext': 'mp4',
75 'title': 'Die LUSTIGSTEN INSTRUMENTE aus dem Internet - Teil 2',
76 'description': 'md5:a691d0413ef4835588c5b03ded670c1f',
77 'timestamp': 1514507395,
78 'upload_date': '20171229',
79 },
80 'params': {
81 'skip_download': True,
82 },
83 }, {
84 # only available via byIdList API
85 'url': 'https://www.funk.net/channel/informr/martin-sonneborn-erklaert-die-eu',
86 'info_dict': {
87 'id': '205067',
88 'ext': 'mp4',
89 'title': 'Martin Sonneborn erklärt die EU',
90 'description': 'md5:050f74626e4ed87edf4626d2024210c0',
91 'timestamp': 1494424042,
92 'upload_date': '20170510',
93 },
94 'params': {
95 'skip_download': True,
96 },
97 }, {
98 'url': 'https://www.funk.net/channel/59d5149841dca100012511e3/mein-erster-job-lovemilla-folge-1/lovemilla/',
99 'only_matching': True,
100 }]
101
102 def _real_extract(self, url):
103 mobj = re.match(self._VALID_URL, url)
104 channel_id = mobj.group('id')
105 alias = mobj.group('alias')
106
107 headers = {
108 'authorization': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJjbGllbnROYW1lIjoiY3VyYXRpb24tdG9vbCIsInNjb3BlIjoic3RhdGljLWNvbnRlbnQtYXBpLGN1cmF0aW9uLWFwaSxzZWFyY2gtYXBpIn0.q4Y2xZG8PFHai24-4Pjx2gym9RmJejtmK6lMXP5wAgc',
109 'Referer': url,
110 }
111
112 video = None
113
114 by_id_list = self._download_json(
115 'https://www.funk.net/api/v3.0/content/videos/byIdList', channel_id,
116 headers=headers, query={
117 'ids': alias,
118 }, fatal=False)
119 if by_id_list:
120 video = try_get(by_id_list, lambda x: x['result'][0], dict)
121
122 if not video:
123 results = self._download_json(
124 'https://www.funk.net/api/v3.0/content/videos/filter', channel_id,
125 headers=headers, query={
126 'channelId': channel_id,
127 'size': 100,
128 })['result']
129 video = next(r for r in results if r.get('alias') == alias)
130
131 return self._make_url_result(video)