logo

youtube-dl

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

arnes.py (3634B)


  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..compat import (
  5. compat_parse_qs,
  6. compat_urllib_parse_urlparse,
  7. )
  8. from ..utils import (
  9. float_or_none,
  10. int_or_none,
  11. parse_iso8601,
  12. remove_start,
  13. )
  14. class ArnesIE(InfoExtractor):
  15. IE_NAME = 'video.arnes.si'
  16. IE_DESC = 'Arnes Video'
  17. _VALID_URL = r'https?://video\.arnes\.si/(?:[a-z]{2}/)?(?:watch|embed|api/(?:asset|public/video))/(?P<id>[0-9a-zA-Z]{12})'
  18. _TESTS = [{
  19. 'url': 'https://video.arnes.si/watch/a1qrWTOQfVoU?t=10',
  20. 'md5': '4d0f4d0a03571b33e1efac25fd4a065d',
  21. 'info_dict': {
  22. 'id': 'a1qrWTOQfVoU',
  23. 'ext': 'mp4',
  24. 'title': 'Linearna neodvisnost, definicija',
  25. 'description': 'Linearna neodvisnost, definicija',
  26. 'license': 'PRIVATE',
  27. 'creator': 'Polona Oblak',
  28. 'timestamp': 1585063725,
  29. 'upload_date': '20200324',
  30. 'channel': 'Polona Oblak',
  31. 'channel_id': 'q6pc04hw24cj',
  32. 'channel_url': 'https://video.arnes.si/?channel=q6pc04hw24cj',
  33. 'duration': 596.75,
  34. 'view_count': int,
  35. 'tags': ['linearna_algebra'],
  36. 'start_time': 10,
  37. }
  38. }, {
  39. 'url': 'https://video.arnes.si/api/asset/s1YjnV7hadlC/play.mp4',
  40. 'only_matching': True,
  41. }, {
  42. 'url': 'https://video.arnes.si/embed/s1YjnV7hadlC',
  43. 'only_matching': True,
  44. }, {
  45. 'url': 'https://video.arnes.si/en/watch/s1YjnV7hadlC',
  46. 'only_matching': True,
  47. }, {
  48. 'url': 'https://video.arnes.si/embed/s1YjnV7hadlC?t=123&hideRelated=1',
  49. 'only_matching': True,
  50. }, {
  51. 'url': 'https://video.arnes.si/api/public/video/s1YjnV7hadlC',
  52. 'only_matching': True,
  53. }]
  54. _BASE_URL = 'https://video.arnes.si'
  55. def _real_extract(self, url):
  56. video_id = self._match_id(url)
  57. video = self._download_json(
  58. self._BASE_URL + '/api/public/video/' + video_id, video_id)['data']
  59. title = video['title']
  60. formats = []
  61. for media in (video.get('media') or []):
  62. media_url = media.get('url')
  63. if not media_url:
  64. continue
  65. formats.append({
  66. 'url': self._BASE_URL + media_url,
  67. 'format_id': remove_start(media.get('format'), 'FORMAT_'),
  68. 'format_note': media.get('formatTranslation'),
  69. 'width': int_or_none(media.get('width')),
  70. 'height': int_or_none(media.get('height')),
  71. })
  72. self._sort_formats(formats)
  73. channel = video.get('channel') or {}
  74. channel_id = channel.get('url')
  75. thumbnail = video.get('thumbnailUrl')
  76. return {
  77. 'id': video_id,
  78. 'title': title,
  79. 'formats': formats,
  80. 'thumbnail': self._BASE_URL + thumbnail,
  81. 'description': video.get('description'),
  82. 'license': video.get('license'),
  83. 'creator': video.get('author'),
  84. 'timestamp': parse_iso8601(video.get('creationTime')),
  85. 'channel': channel.get('name'),
  86. 'channel_id': channel_id,
  87. 'channel_url': self._BASE_URL + '/?channel=' + channel_id if channel_id else None,
  88. 'duration': float_or_none(video.get('duration'), 1000),
  89. 'view_count': int_or_none(video.get('views')),
  90. 'tags': video.get('hashtags'),
  91. 'start_time': int_or_none(compat_parse_qs(
  92. compat_urllib_parse_urlparse(url).query).get('t', [None])[0]),
  93. }