[urort] Add extractor (Fixes #2634)
[youtube-dl] / youtube_dl / extractor / urort.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import re
5
6 from .common import InfoExtractor
7 from ..utils import (
8     compat_urllib_parse,
9 )
10
11
12 class UrortIE(InfoExtractor):
13     IE_DESC = 'NRK P3 Urørt'
14     _VALID_URL = r'https?://(?:www\.)?urort\.p3\.no/#!/Band/(?P<id>[^/]+)$'
15
16     _TEST = {
17         'url': 'https://urort.p3.no/#!/Band/Gerilja',
18         'md5': '5ed31a924be8a05e47812678a86e127b',
19         'info_dict': {
20             'id': '33124-4',
21             'ext': 'mp3',
22             'title': 'The Bomb',
23             'thumbnail': 're:^https?://.+\.jpg',
24             'like_count': int,
25             'uploader': 'Gerilja',
26             'uploader_id': 'Gerilja',
27         },
28         'params': {
29             'matchtitle': '^The Bomb$',  # To test, we want just one video
30         }
31     }
32
33     def _real_extract(self, url):
34         mobj = re.match(self._VALID_URL, url)
35         playlist_id = mobj.group('id')
36
37         fstr = compat_urllib_parse.quote("InternalBandUrl eq '%s'" % playlist_id)
38         json_url = 'http://urort.p3.no/breeze/urort/TrackDtos?$filter=' + fstr
39         songs = self._download_json(json_url, playlist_id)
40
41         entries = [{
42             'id': '%d-%s' % (s['BandId'], s['$id']),
43             'title': s['Title'],
44             'url': s['TrackUrl'],
45             'ext': 'mp3',
46             'uploader_id': playlist_id,
47             'uploader': s.get('BandName', playlist_id),
48             'like_count': s.get('LikeCount'),
49             'thumbnail': 'http://urort.p3.no/cloud/images/%s' % s['Image'],
50         } for s in songs]
51
52         return {
53             '_type': 'playlist',
54             'id': playlist_id,
55             'title': playlist_id,
56             'entries': entries,
57         }