logo

youtube-dl

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

atvat.py (2512B)


  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. determine_ext,
  6. int_or_none,
  7. unescapeHTML,
  8. )
  9. class ATVAtIE(InfoExtractor):
  10. _VALID_URL = r'https?://(?:www\.)?atv\.at/(?:[^/]+/){2}(?P<id>[dv]\d+)'
  11. _TESTS = [{
  12. 'url': 'http://atv.at/aktuell/di-210317-2005-uhr/v1698449/',
  13. 'md5': 'c3b6b975fb3150fc628572939df205f2',
  14. 'info_dict': {
  15. 'id': '1698447',
  16. 'ext': 'mp4',
  17. 'title': 'DI, 21.03.17 | 20:05 Uhr 1/1',
  18. }
  19. }, {
  20. 'url': 'http://atv.at/aktuell/meinrad-knapp/d8416/',
  21. 'only_matching': True,
  22. }]
  23. def _real_extract(self, url):
  24. display_id = self._match_id(url)
  25. webpage = self._download_webpage(url, display_id)
  26. video_data = self._parse_json(unescapeHTML(self._search_regex(
  27. [r'flashPlayerOptions\s*=\s*(["\'])(?P<json>(?:(?!\1).)+)\1',
  28. r'class="[^"]*jsb_video/FlashPlayer[^"]*"[^>]+data-jsb="(?P<json>[^"]+)"'],
  29. webpage, 'player data', group='json')),
  30. display_id)['config']['initial_video']
  31. video_id = video_data['id']
  32. video_title = video_data['title']
  33. parts = []
  34. for part in video_data.get('parts', []):
  35. part_id = part['id']
  36. part_title = part['title']
  37. formats = []
  38. for source in part.get('sources', []):
  39. source_url = source.get('src')
  40. if not source_url:
  41. continue
  42. ext = determine_ext(source_url)
  43. if ext == 'm3u8':
  44. formats.extend(self._extract_m3u8_formats(
  45. source_url, part_id, 'mp4', 'm3u8_native',
  46. m3u8_id='hls', fatal=False))
  47. else:
  48. formats.append({
  49. 'format_id': source.get('delivery'),
  50. 'url': source_url,
  51. })
  52. self._sort_formats(formats)
  53. parts.append({
  54. 'id': part_id,
  55. 'title': part_title,
  56. 'thumbnail': part.get('preview_image_url'),
  57. 'duration': int_or_none(part.get('duration')),
  58. 'is_live': part.get('is_livestream'),
  59. 'formats': formats,
  60. })
  61. return {
  62. '_type': 'multi_video',
  63. 'id': video_id,
  64. 'title': video_title,
  65. 'entries': parts,
  66. }