s4c.py 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. float_or_none,
  6. merge_dicts,
  7. T,
  8. traverse_obj,
  9. txt_or_none,
  10. )
  11. class S4CIE(InfoExtractor):
  12. _VALID_URL = r'https?://(?:www\.)?s4c\.cymru/clic/programme/(?P<id>\d+)'
  13. _TESTS = [{
  14. 'url': 'https://www.s4c.cymru/clic/programme/861362209',
  15. 'info_dict': {
  16. 'id': '861362209',
  17. 'ext': 'mp4',
  18. 'title': 'Y Swn',
  19. 'description': 'md5:f7681a30e4955b250b3224aa9fe70cf0',
  20. 'duration': 5340
  21. },
  22. }, {
  23. 'url': 'https://www.s4c.cymru/clic/programme/856636948',
  24. 'info_dict': {
  25. 'id': '856636948',
  26. 'ext': 'mp4',
  27. 'title': 'Am Dro',
  28. 'duration': 2880,
  29. 'description': 'md5:100d8686fc9a632a0cb2db52a3433ffe',
  30. },
  31. }]
  32. def _real_extract(self, url):
  33. video_id = self._match_id(url)
  34. details = self._download_json(
  35. 'https://www.s4c.cymru/df/full_prog_details',
  36. video_id, query={
  37. 'lang': 'e',
  38. 'programme_id': video_id,
  39. }, fatal=False)
  40. filename = self._download_json(
  41. 'https://player-api.s4c-cdn.co.uk/player-configuration/prod', video_id, query={
  42. 'programme_id': video_id,
  43. 'signed': '0',
  44. 'lang': 'en',
  45. 'mode': 'od',
  46. 'appId': 'clic',
  47. 'streamName': '',
  48. }, note='Downloading player config JSON')['filename']
  49. m3u8_url = self._download_json(
  50. 'https://player-api.s4c-cdn.co.uk/streaming-urls/prod', video_id, query={
  51. 'mode': 'od',
  52. 'application': 'clic',
  53. 'region': 'WW',
  54. 'extra': 'false',
  55. 'thirdParty': 'false',
  56. 'filename': filename,
  57. }, note='Downloading streaming urls JSON')['hls']
  58. # ... self._extract_m3u8_formats_and_subtitles(m3u8_url, video_id, 'mp4', m3u8_id='hls')
  59. formats, subtitles = self._extract_m3u8_formats(m3u8_url, video_id, 'mp4', m3u8_id='hls', entry_protocol='m3u8_native'), {}
  60. return merge_dicts({
  61. 'id': video_id,
  62. 'formats': formats,
  63. 'subtitles': subtitles,
  64. }, traverse_obj(details, ('full_prog_details', 0, {
  65. 'title': (('programme_title', 'series_title'), T(txt_or_none)),
  66. 'description': ('full_billing', T(txt_or_none)),
  67. 'duration': ('duration', T(lambda x: float_or_none(x, invscale=60))),
  68. }), get_all=False),
  69. rev=True)