logo

youtube-dl

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

ruv.py (3359B)


  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. determine_ext,
  6. unified_timestamp,
  7. )
  8. class RuvIE(InfoExtractor):
  9. _VALID_URL = r'https?://(?:www\.)?ruv\.is/(?:sarpurinn/[^/]+|node)/(?P<id>[^/]+(?:/\d+)?)'
  10. _TESTS = [{
  11. # m3u8
  12. 'url': 'http://ruv.is/sarpurinn/ruv-aukaras/fh-valur/20170516',
  13. 'md5': '66347652f4e13e71936817102acc1724',
  14. 'info_dict': {
  15. 'id': '1144499',
  16. 'display_id': 'fh-valur/20170516',
  17. 'ext': 'mp4',
  18. 'title': 'FH - Valur',
  19. 'description': 'Bein útsending frá 3. leik FH og Vals í úrslitum Olísdeildar karla í handbolta.',
  20. 'timestamp': 1494963600,
  21. 'upload_date': '20170516',
  22. },
  23. }, {
  24. # mp3
  25. 'url': 'http://ruv.is/sarpurinn/ras-2/morgunutvarpid/20170619',
  26. 'md5': '395ea250c8a13e5fdb39d4670ef85378',
  27. 'info_dict': {
  28. 'id': '1153630',
  29. 'display_id': 'morgunutvarpid/20170619',
  30. 'ext': 'mp3',
  31. 'title': 'Morgunútvarpið',
  32. 'description': 'md5:a4cf1202c0a1645ca096b06525915418',
  33. 'timestamp': 1497855000,
  34. 'upload_date': '20170619',
  35. },
  36. }, {
  37. 'url': 'http://ruv.is/sarpurinn/ruv/frettir/20170614',
  38. 'only_matching': True,
  39. }, {
  40. 'url': 'http://www.ruv.is/node/1151854',
  41. 'only_matching': True,
  42. }, {
  43. 'url': 'http://ruv.is/sarpurinn/klippa/secret-soltice-hefst-a-morgun',
  44. 'only_matching': True,
  45. }, {
  46. 'url': 'http://ruv.is/sarpurinn/ras-1/morgunvaktin/20170619',
  47. 'only_matching': True,
  48. }]
  49. def _real_extract(self, url):
  50. display_id = self._match_id(url)
  51. webpage = self._download_webpage(url, display_id)
  52. title = self._og_search_title(webpage)
  53. FIELD_RE = r'video\.%s\s*=\s*(["\'])(?P<url>(?:(?!\1).)+)\1'
  54. media_url = self._html_search_regex(
  55. FIELD_RE % 'src', webpage, 'video URL', group='url')
  56. video_id = self._search_regex(
  57. r'<link\b[^>]+\bhref=["\']https?://www\.ruv\.is/node/(\d+)',
  58. webpage, 'video id', default=display_id)
  59. ext = determine_ext(media_url)
  60. if ext == 'm3u8':
  61. formats = self._extract_m3u8_formats(
  62. media_url, video_id, 'mp4', entry_protocol='m3u8_native',
  63. m3u8_id='hls')
  64. elif ext == 'mp3':
  65. formats = [{
  66. 'format_id': 'mp3',
  67. 'url': media_url,
  68. 'vcodec': 'none',
  69. }]
  70. else:
  71. formats = [{
  72. 'url': media_url,
  73. }]
  74. description = self._og_search_description(webpage, default=None)
  75. thumbnail = self._og_search_thumbnail(
  76. webpage, default=None) or self._search_regex(
  77. FIELD_RE % 'poster', webpage, 'thumbnail', fatal=False)
  78. timestamp = unified_timestamp(self._html_search_meta(
  79. 'article:published_time', webpage, 'timestamp', fatal=False))
  80. return {
  81. 'id': video_id,
  82. 'display_id': display_id,
  83. 'title': title,
  84. 'description': description,
  85. 'thumbnail': thumbnail,
  86. 'timestamp': timestamp,
  87. 'formats': formats,
  88. }