arnes.py 3.4 KB

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