urort.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import urllib.parse
  2. from .common import InfoExtractor
  3. from ..utils import unified_strdate
  4. class UrortIE(InfoExtractor):
  5. _WORKING = False
  6. IE_DESC = 'NRK P3 Urørt'
  7. _VALID_URL = r'https?://(?:www\.)?urort\.p3\.no/#!/Band/(?P<id>[^/]+)$'
  8. _TEST = {
  9. 'url': 'https://urort.p3.no/#!/Band/Gerilja',
  10. 'md5': '5ed31a924be8a05e47812678a86e127b',
  11. 'info_dict': {
  12. 'id': '33124-24',
  13. 'ext': 'mp3',
  14. 'title': 'The Bomb',
  15. 'thumbnail': r're:^https?://.+\.jpg',
  16. 'uploader': 'Gerilja',
  17. 'uploader_id': 'Gerilja',
  18. 'upload_date': '20100323',
  19. },
  20. 'params': {
  21. 'matchtitle': '^The Bomb$', # To test, we want just one video
  22. },
  23. }
  24. def _real_extract(self, url):
  25. playlist_id = self._match_id(url)
  26. fstr = urllib.parse.quote(f"InternalBandUrl eq '{playlist_id}'")
  27. json_url = f'http://urort.p3.no/breeze/urort/TrackDTOViews?$filter={fstr}&$orderby=Released%20desc&$expand=Tags%2CFiles'
  28. songs = self._download_json(json_url, playlist_id)
  29. entries = []
  30. for s in songs:
  31. formats = [{
  32. 'tbr': f.get('Quality'),
  33. 'ext': f['FileType'],
  34. 'format_id': '{}-{}'.format(f['FileType'], f.get('Quality', '')),
  35. 'url': 'http://p3urort.blob.core.windows.net/tracks/{}'.format(f['FileRef']),
  36. 'quality': 3 if f['FileType'] == 'mp3' else 2,
  37. } for f in s['Files']]
  38. e = {
  39. 'id': '%d-%s' % (s['BandId'], s['$id']),
  40. 'title': s['Title'],
  41. 'uploader_id': playlist_id,
  42. 'uploader': s.get('BandName', playlist_id),
  43. 'thumbnail': 'http://urort.p3.no/cloud/images/{}'.format(s['Image']),
  44. 'upload_date': unified_strdate(s.get('Released')),
  45. 'formats': formats,
  46. }
  47. entries.append(e)
  48. return {
  49. '_type': 'playlist',
  50. 'id': playlist_id,
  51. 'title': playlist_id,
  52. 'entries': entries,
  53. }