]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/funk.py
Fix the changelog.
[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 int_or_none
9
10
11 class FunkBaseIE(InfoExtractor):
12 def _make_url_result(self, video):
13 return {
14 '_type': 'url_transparent',
15 'url': 'nexx:741:%s' % video['sourceId'],
16 'ie_key': NexxIE.ie_key(),
17 'id': video['sourceId'],
18 'title': video.get('title'),
19 'description': video.get('description'),
20 'duration': int_or_none(video.get('duration')),
21 'season_number': int_or_none(video.get('seasonNr')),
22 'episode_number': int_or_none(video.get('episodeNr')),
23 }
24
25
26 class FunkMixIE(FunkBaseIE):
27 _VALID_URL = r'https?://(?:www\.)?funk\.net/mix/(?P<id>[^/]+)/(?P<alias>[^/?#&]+)'
28 _TESTS = [{
29 'url': 'https://www.funk.net/mix/59d65d935f8b160001828b5b/die-realste-kifferdoku-aller-zeiten',
30 'md5': '8edf617c2f2b7c9847dfda313f199009',
31 'info_dict': {
32 'id': '123748',
33 'ext': 'mp4',
34 'title': '"Die realste Kifferdoku aller Zeiten"',
35 'description': 'md5:c97160f5bafa8d47ec8e2e461012aa9d',
36 'timestamp': 1490274721,
37 'upload_date': '20170323',
38 },
39 }]
40
41 def _real_extract(self, url):
42 mobj = re.match(self._VALID_URL, url)
43 mix_id = mobj.group('id')
44 alias = mobj.group('alias')
45
46 lists = self._download_json(
47 'https://www.funk.net/api/v3.1/curation/curatedLists/',
48 mix_id, headers={
49 'authorization': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJjbGllbnROYW1lIjoiY3VyYXRpb24tdG9vbC12Mi4wIiwic2NvcGUiOiJzdGF0aWMtY29udGVudC1hcGksY3VyYXRpb24tc2VydmljZSxzZWFyY2gtYXBpIn0.SGCC1IXHLtZYoo8PvRKlU2gXH1su8YSu47sB3S4iXBI',
50 'Referer': url,
51 }, query={
52 'size': 100,
53 })['result']['lists']
54
55 metas = next(
56 l for l in lists
57 if mix_id in (l.get('entityId'), l.get('alias')))['videoMetas']
58 video = next(
59 meta['videoDataDelegate']
60 for meta in metas if meta.get('alias') == alias)
61
62 return self._make_url_result(video)
63
64
65 class FunkChannelIE(FunkBaseIE):
66 _VALID_URL = r'https?://(?:www\.)?funk\.net/channel/(?P<id>[^/]+)/(?P<alias>[^/?#&]+)'
67 _TESTS = [{
68 'url': 'https://www.funk.net/channel/ba/die-lustigsten-instrumente-aus-dem-internet-teil-2',
69 'info_dict': {
70 'id': '1155821',
71 'ext': 'mp4',
72 'title': 'Die LUSTIGSTEN INSTRUMENTE aus dem Internet - Teil 2',
73 'description': 'md5:a691d0413ef4835588c5b03ded670c1f',
74 'timestamp': 1514507395,
75 'upload_date': '20171229',
76 },
77 'params': {
78 'skip_download': True,
79 },
80 }, {
81 'url': 'https://www.funk.net/channel/59d5149841dca100012511e3/mein-erster-job-lovemilla-folge-1/lovemilla/',
82 'only_matching': True,
83 }]
84
85 def _real_extract(self, url):
86 mobj = re.match(self._VALID_URL, url)
87 channel_id = mobj.group('id')
88 alias = mobj.group('alias')
89
90 results = self._download_json(
91 'https://www.funk.net/api/v3.0/content/videos/filter', channel_id,
92 headers={
93 'authorization': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJjbGllbnROYW1lIjoiY3VyYXRpb24tdG9vbCIsInNjb3BlIjoic3RhdGljLWNvbnRlbnQtYXBpLGN1cmF0aW9uLWFwaSxzZWFyY2gtYXBpIn0.q4Y2xZG8PFHai24-4Pjx2gym9RmJejtmK6lMXP5wAgc',
94 'Referer': url,
95 }, query={
96 'channelId': channel_id,
97 'size': 100,
98 })['result']
99
100 video = next(r for r in results if r.get('alias') == alias)
101
102 return self._make_url_result(video)