logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

kommunetv.py (1185B)


  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..utils import update_url
  5. class KommunetvIE(InfoExtractor):
  6. _VALID_URL = r'https://(\w+).kommunetv.no/archive/(?P<id>\w+)'
  7. _TEST = {
  8. 'url': 'https://oslo.kommunetv.no/archive/921',
  9. 'md5': '5f102be308ee759be1e12b63d5da4bbc',
  10. 'info_dict': {
  11. 'id': '921',
  12. 'title': 'Bystyremøte',
  13. 'ext': 'mp4'
  14. }
  15. }
  16. def _real_extract(self, url):
  17. video_id = self._match_id(url)
  18. headers = {
  19. 'Accept': 'application/json'
  20. }
  21. data = self._download_json('https://oslo.kommunetv.no/api/streams?streamType=1&id=%s' % video_id, video_id, headers=headers)
  22. title = data['stream']['title']
  23. file = data['playlist'][0]['playlist'][0]['file']
  24. url = update_url(file, query=None, fragment=None)
  25. formats = self._extract_m3u8_formats(url, video_id, ext='mp4', entry_protocol='m3u8_native', m3u8_id='hls', fatal=False)
  26. self._sort_formats(formats)
  27. return {
  28. 'id': video_id,
  29. 'formats': formats,
  30. 'title': title
  31. }