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.

52 lines
1.8 KiB

  1. from __future__ import unicode_literals
  2. from .common import InfoExtractor
  3. class RadioDeIE(InfoExtractor):
  4. IE_NAME = 'radio.de'
  5. _VALID_URL = r'https?://(?P<id>.+?)\.(?:radio\.(?:de|at|fr|pt|es|pl|it)|rad\.io)'
  6. _TEST = {
  7. 'url': 'http://ndr2.radio.de/',
  8. 'info_dict': {
  9. 'id': 'ndr2',
  10. 'ext': 'mp3',
  11. 'title': 're:^NDR 2 [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$',
  12. 'description': 'md5:591c49c702db1a33751625ebfb67f273',
  13. 'thumbnail': r're:^https?://.*\.png',
  14. 'is_live': True,
  15. },
  16. 'params': {
  17. 'skip_download': True,
  18. }
  19. }
  20. def _real_extract(self, url):
  21. radio_id = self._match_id(url)
  22. webpage = self._download_webpage(url, radio_id)
  23. jscode = self._search_regex(
  24. r"'components/station/stationService':\s*\{\s*'?station'?:\s*(\{.*?\s*\}),\n",
  25. webpage, 'broadcast')
  26. broadcast = self._parse_json(jscode, radio_id)
  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') or broadcast.get('logo100x100')
  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. }