]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/urort.py
Completely change project name to yt-dlp (#85)
[yt-dlp.git] / yt_dlp / extractor / urort.py
CommitLineData
e2b06e76
PH
1# coding: utf-8
2from __future__ import unicode_literals
3
e2b06e76 4from .common import InfoExtractor
1cc79574 5from ..compat import (
e2b06e76 6 compat_urllib_parse,
1cc79574
PH
7)
8from ..utils import (
0dae5083 9 unified_strdate,
e2b06e76
PH
10)
11
12
13class UrortIE(InfoExtractor):
14 IE_DESC = 'NRK P3 Urørt'
15 _VALID_URL = r'https?://(?:www\.)?urort\.p3\.no/#!/Band/(?P<id>[^/]+)$'
16
17 _TEST = {
18 'url': 'https://urort.p3.no/#!/Band/Gerilja',
19 'md5': '5ed31a924be8a05e47812678a86e127b',
20 'info_dict': {
baa7081d 21 'id': '33124-24',
e2b06e76
PH
22 'ext': 'mp3',
23 'title': 'The Bomb',
ec85ded8 24 'thumbnail': r're:^https?://.+\.jpg',
e2b06e76
PH
25 'uploader': 'Gerilja',
26 'uploader_id': 'Gerilja',
0dae5083 27 'upload_date': '20100323',
e2b06e76
PH
28 },
29 'params': {
30 'matchtitle': '^The Bomb$', # To test, we want just one video
31 }
32 }
33
34 def _real_extract(self, url):
6a1b20de 35 playlist_id = self._match_id(url)
e2b06e76
PH
36
37 fstr = compat_urllib_parse.quote("InternalBandUrl eq '%s'" % playlist_id)
baa7081d 38 json_url = 'http://urort.p3.no/breeze/urort/TrackDTOViews?$filter=%s&$orderby=Released%%20desc&$expand=Tags%%2CFiles' % fstr
e2b06e76 39 songs = self._download_json(json_url, playlist_id)
baa7081d
PH
40 entries = []
41 for s in songs:
42 formats = [{
43 'tbr': f.get('Quality'),
44 'ext': f['FileType'],
45 'format_id': '%s-%s' % (f['FileType'], f.get('Quality', '')),
46 'url': 'http://p3urort.blob.core.windows.net/tracks/%s' % f['FileRef'],
f983b875 47 'quality': 3 if f['FileType'] == 'mp3' else 2,
baa7081d
PH
48 } for f in s['Files']]
49 self._sort_formats(formats)
50 e = {
51 'id': '%d-%s' % (s['BandId'], s['$id']),
52 'title': s['Title'],
53 'uploader_id': playlist_id,
54 'uploader': s.get('BandName', playlist_id),
55 'thumbnail': 'http://urort.p3.no/cloud/images/%s' % s['Image'],
56 'upload_date': unified_strdate(s.get('Released')),
57 'formats': formats,
58 }
59 entries.append(e)
e2b06e76
PH
60
61 return {
62 '_type': 'playlist',
63 'id': playlist_id,
64 'title': playlist_id,
65 'entries': entries,
66 }