urort.py 1.7 KB

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