logo

oasis-root

Compiled tree of Oasis Linux based on own branch at <https://hacktivis.me/git/oasis/> git clone https://anongit.hacktivis.me/git/oasis-root.git

plvideo.py (5603B)


  1. from .common import InfoExtractor
  2. from ..utils import (
  3. float_or_none,
  4. int_or_none,
  5. parse_iso8601,
  6. parse_resolution,
  7. url_or_none,
  8. )
  9. from ..utils.traversal import traverse_obj
  10. class PlVideoIE(InfoExtractor):
  11. IE_DESC = 'Платформа'
  12. _VALID_URL = r'https?://(?:www\.)?plvideo\.ru/(?:watch\?(?:[^#]+&)?v=|shorts/)(?P<id>[\w-]+)'
  13. _TESTS = [{
  14. 'url': 'https://plvideo.ru/watch?v=Y5JzUzkcQTMK',
  15. 'md5': 'fe8e18aca892b3b31f3bf492169f8a26',
  16. 'info_dict': {
  17. 'id': 'Y5JzUzkcQTMK',
  18. 'ext': 'mp4',
  19. 'thumbnail': 'https://img.plvideo.ru/images/fp-2024-images/v/cover/37/dd/37dd00a4c96c77436ab737e85947abd7/original663a4a3bb713e5.33151959.jpg',
  20. 'title': 'Presidente de Cuba llega a Moscú en una visita de trabajo',
  21. 'channel': 'RT en Español',
  22. 'channel_id': 'ZH4EKqunVDvo',
  23. 'media_type': 'video',
  24. 'comment_count': int,
  25. 'tags': ['rusia', 'cuba', 'russia', 'miguel díaz-canel'],
  26. 'description': 'md5:a1a395d900d77a86542a91ee0826c115',
  27. 'released_timestamp': 1715096124,
  28. 'channel_is_verified': True,
  29. 'like_count': int,
  30. 'timestamp': 1715095911,
  31. 'duration': 44320,
  32. 'view_count': int,
  33. 'dislike_count': int,
  34. 'upload_date': '20240507',
  35. 'modified_date': '20240701',
  36. 'channel_follower_count': int,
  37. 'modified_timestamp': 1719824073,
  38. },
  39. }, {
  40. 'url': 'https://plvideo.ru/shorts/S3Uo9c-VLwFX',
  41. 'md5': '7d8fa2279406c69d2fd2a6fc548a9805',
  42. 'info_dict': {
  43. 'id': 'S3Uo9c-VLwFX',
  44. 'ext': 'mp4',
  45. 'channel': 'Romaatom',
  46. 'tags': 'count:22',
  47. 'dislike_count': int,
  48. 'upload_date': '20241130',
  49. 'description': 'md5:452e6de219bf2f32bb95806c51c3b364',
  50. 'duration': 58433,
  51. 'modified_date': '20241130',
  52. 'thumbnail': 'https://img.plvideo.ru/images/fp-2024-11-cover/S3Uo9c-VLwFX/f9318999-a941-482b-b700-2102a7049366.jpg',
  53. 'media_type': 'shorts',
  54. 'like_count': int,
  55. 'modified_timestamp': 1732961458,
  56. 'channel_is_verified': True,
  57. 'channel_id': 'erJyyTIbmUd1',
  58. 'timestamp': 1732961355,
  59. 'comment_count': int,
  60. 'title': 'Белоусов отменил приказы о кадровом резерве на гражданской службе',
  61. 'channel_follower_count': int,
  62. 'view_count': int,
  63. 'released_timestamp': 1732961458,
  64. },
  65. }]
  66. def _real_extract(self, url):
  67. video_id = self._match_id(url)
  68. video_data = self._download_json(
  69. f'https://api.g1.plvideo.ru/v1/videos/{video_id}?Aud=18', video_id)
  70. is_live = False
  71. formats = []
  72. subtitles = {}
  73. automatic_captions = {}
  74. for quality, data in traverse_obj(video_data, ('item', 'profiles', {dict.items}, lambda _, v: url_or_none(v[1]['hls']))):
  75. formats.append({
  76. 'format_id': quality,
  77. 'ext': 'mp4',
  78. 'protocol': 'm3u8_native',
  79. **traverse_obj(data, {
  80. 'url': 'hls',
  81. 'fps': ('fps', {float_or_none}),
  82. 'aspect_ratio': ('aspectRatio', {float_or_none}),
  83. }),
  84. **parse_resolution(quality),
  85. })
  86. if livestream_url := traverse_obj(video_data, ('item', 'livestream', 'url', {url_or_none})):
  87. is_live = True
  88. formats.extend(self._extract_m3u8_formats(livestream_url, video_id, 'mp4', live=True))
  89. for lang, url in traverse_obj(video_data, ('item', 'subtitles', {dict.items}, lambda _, v: url_or_none(v[1]))):
  90. if lang.endswith('-auto'):
  91. automatic_captions.setdefault(lang[:-5], []).append({
  92. 'url': url,
  93. })
  94. else:
  95. subtitles.setdefault(lang, []).append({
  96. 'url': url,
  97. })
  98. return {
  99. 'id': video_id,
  100. 'formats': formats,
  101. 'subtitles': subtitles,
  102. 'automatic_captions': automatic_captions,
  103. 'is_live': is_live,
  104. **traverse_obj(video_data, ('item', {
  105. 'id': ('id', {str}),
  106. 'title': ('title', {str}),
  107. 'description': ('description', {str}),
  108. 'thumbnail': ('cover', 'paths', 'original', 'src', {url_or_none}),
  109. 'duration': ('uploadFile', 'videoDuration', {int_or_none}),
  110. 'channel': ('channel', 'name', {str}),
  111. 'channel_id': ('channel', 'id', {str}),
  112. 'channel_follower_count': ('channel', 'stats', 'subscribers', {int_or_none}),
  113. 'channel_is_verified': ('channel', 'verified', {bool}),
  114. 'tags': ('tags', ..., {str}),
  115. 'timestamp': ('createdAt', {parse_iso8601}),
  116. 'released_timestamp': ('publishedAt', {parse_iso8601}),
  117. 'modified_timestamp': ('updatedAt', {parse_iso8601}),
  118. 'view_count': ('stats', 'viewTotalCount', {int_or_none}),
  119. 'like_count': ('stats', 'likeCount', {int_or_none}),
  120. 'dislike_count': ('stats', 'dislikeCount', {int_or_none}),
  121. 'comment_count': ('stats', 'commentCount', {int_or_none}),
  122. 'media_type': ('type', {str}),
  123. })),
  124. }