You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
1.7 KiB

  1. from __future__ import unicode_literals
  2. import json
  3. from .common import InfoExtractor
  4. class RadioDeIE(InfoExtractor):
  5. IE_NAME = 'radio.de'
  6. _VALID_URL = r'https?://(?P<id>.+?)\.(?:radio\.(?:de|at|fr|pt|es|pl|it)|rad\.io)'
  7. _TEST = {
  8. 'url': 'http://ndr2.radio.de/',
  9. 'md5': '3b4cdd011bc59174596b6145cda474a4',
  10. 'info_dict': {
  11. 'id': 'ndr2',
  12. 'ext': 'mp3',
  13. 'title': 're:^NDR 2 [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$',
  14. 'description': 'md5:591c49c702db1a33751625ebfb67f273',
  15. 'thumbnail': 're:^https?://.*\.png',
  16. },
  17. 'params': {
  18. 'skip_download': True,
  19. }
  20. }
  21. def _real_extract(self, url):
  22. radio_id = self._match_id(url)
  23. webpage = self._download_webpage(url, radio_id)
  24. broadcast = json.loads(self._search_regex(
  25. r'_getBroadcast\s*=\s*function\(\s*\)\s*{\s*return\s+({.+?})\s*;\s*}',
  26. webpage, 'broadcast'))
  27. title = self._live_title(broadcast['name'])
  28. description = broadcast.get('description') or broadcast.get('shortDescription')
  29. thumbnail = broadcast.get('picture4Url') or broadcast.get('picture4TransUrl')
  30. formats = [{
  31. 'url': stream['streamUrl'],
  32. 'ext': stream['streamContentFormat'].lower(),
  33. 'acodec': stream['streamContentFormat'],
  34. 'abr': stream['bitRate'],
  35. 'asr': stream['sampleRate']
  36. } for stream in broadcast['streamUrls']]
  37. self._sort_formats(formats)
  38. return {
  39. 'id': radio_id,
  40. 'title': title,
  41. 'description': description,
  42. 'thumbnail': thumbnail,
  43. 'is_live': True,
  44. 'formats': formats,
  45. }