logo

youtube-dl

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

tv2hu.py (2411B)


  1. # encoding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..utils import int_or_none
  5. class TV2HuIE(InfoExtractor):
  6. IE_NAME = 'tv2.hu'
  7. _VALID_URL = r'https?://(?:www\.)?tv2\.hu/(?:[^/]+/)+(?P<id>\d+)_[^/?#]+?\.html'
  8. _TESTS = [{
  9. 'url': 'http://tv2.hu/ezek_megorultek/217679_ezek-megorultek---1.-adas-1.-resz.html',
  10. 'md5': '585e58e2e090f34603804bb2c48e98d8',
  11. 'info_dict': {
  12. 'id': '217679',
  13. 'ext': 'mp4',
  14. 'title': 'Ezek megőrültek! - 1. adás 1. rész',
  15. 'upload_date': '20160826',
  16. 'thumbnail': r're:^https?://.*\.jpg$'
  17. }
  18. }, {
  19. 'url': 'http://tv2.hu/ezek_megorultek/teljes_adasok/217677_ezek-megorultek---1.-adas-2.-resz.html',
  20. 'only_matching': True
  21. }, {
  22. 'url': 'http://tv2.hu/musoraink/aktiv/aktiv_teljes_adas/217963_aktiv-teljes-adas---2016.08.30..html',
  23. 'only_matching': True
  24. }]
  25. def _real_extract(self, url):
  26. video_id = self._match_id(url)
  27. webpage = self._download_webpage(url, video_id)
  28. json_url = self._search_regex(
  29. r'jsonUrl\s*=\s*"([^"]+)"', webpage, 'json url')
  30. json_data = self._download_json(json_url, video_id)
  31. formats = []
  32. for b in ('bitrates', 'backupBitrates'):
  33. bitrates = json_data.get(b, {})
  34. m3u8_url = bitrates.get('hls')
  35. if m3u8_url:
  36. formats.extend(self._extract_wowza_formats(
  37. m3u8_url, video_id, skip_protocols=['rtmp', 'rtsp']))
  38. for mp4_url in bitrates.get('mp4', []):
  39. height = int_or_none(self._search_regex(
  40. r'\.(\d+)p\.mp4', mp4_url, 'height', default=None))
  41. formats.append({
  42. 'format_id': 'http' + ('-%d' % height if height else ''),
  43. 'url': mp4_url,
  44. 'height': height,
  45. 'width': int_or_none(height / 9.0 * 16.0 if height else None),
  46. })
  47. self._sort_formats(formats)
  48. return {
  49. 'id': video_id,
  50. 'title': self._og_search_title(webpage).strip(),
  51. 'thumbnail': self._og_search_thumbnail(webpage),
  52. 'upload_date': self._search_regex(
  53. r'/vod/(\d{8})/', json_url, 'upload_date', default=None),
  54. 'formats': formats,
  55. }