arnes.py 3.5 KB

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