lnkgo.py 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. from .common import InfoExtractor
  2. from ..compat import compat_str
  3. from ..utils import (
  4. clean_html,
  5. format_field,
  6. int_or_none,
  7. parse_iso8601,
  8. unified_strdate,
  9. )
  10. class LnkGoIE(InfoExtractor):
  11. _VALID_URL = r'https?://(?:www\.)?lnk(?:go)?\.(?:alfa\.)?lt/(?:visi-video/[^/]+|video)/(?P<id>[A-Za-z0-9-]+)(?:/(?P<episode_id>\d+))?'
  12. _TESTS = [{
  13. 'url': 'http://www.lnkgo.lt/visi-video/aktualai-pratesimas/ziurek-putka-trys-klausimai',
  14. 'info_dict': {
  15. 'id': '10809',
  16. 'ext': 'mp4',
  17. 'title': "Put'ka: Trys Klausimai",
  18. 'upload_date': '20161216',
  19. 'description': 'Seniai matytas Put’ka užduoda tris klausimėlius. Pabandykime surasti atsakymus.',
  20. 'age_limit': 18,
  21. 'duration': 117,
  22. 'thumbnail': r're:^https?://.*\.jpg$',
  23. 'timestamp': 1481904000,
  24. },
  25. 'params': {
  26. 'skip_download': True, # HLS download
  27. },
  28. }, {
  29. 'url': 'http://lnkgo.alfa.lt/visi-video/aktualai-pratesimas/ziurek-nerdas-taiso-kompiuteri-2',
  30. 'info_dict': {
  31. 'id': '10467',
  32. 'ext': 'mp4',
  33. 'title': 'Nėrdas: Kompiuterio Valymas',
  34. 'upload_date': '20150113',
  35. 'description': 'md5:7352d113a242a808676ff17e69db6a69',
  36. 'age_limit': 18,
  37. 'duration': 346,
  38. 'thumbnail': r're:^https?://.*\.jpg$',
  39. 'timestamp': 1421164800,
  40. },
  41. 'params': {
  42. 'skip_download': True, # HLS download
  43. },
  44. }, {
  45. 'url': 'https://lnk.lt/video/neigalieji-tv-bokste/37413',
  46. 'only_matching': True,
  47. }]
  48. _AGE_LIMITS = {
  49. 'N-7': 7,
  50. 'N-14': 14,
  51. 'S': 18,
  52. }
  53. _M3U8_TEMPL = 'https://vod.lnk.lt/lnk_vod/lnk/lnk/%s:%s/playlist.m3u8%s'
  54. def _real_extract(self, url):
  55. display_id, video_id = self._match_valid_url(url).groups()
  56. video_info = self._download_json(
  57. 'https://lnk.lt/api/main/video-page/%s/%s/false' % (display_id, video_id or '0'),
  58. display_id)['videoConfig']['videoInfo']
  59. video_id = compat_str(video_info['id'])
  60. title = video_info['title']
  61. prefix = 'smil' if video_info.get('isQualityChangeAvailable') else 'mp4'
  62. formats = self._extract_m3u8_formats(
  63. self._M3U8_TEMPL % (prefix, video_info['videoUrl'], video_info.get('secureTokenParams') or ''),
  64. video_id, 'mp4', 'm3u8_native')
  65. return {
  66. 'id': video_id,
  67. 'display_id': display_id,
  68. 'title': title,
  69. 'formats': formats,
  70. 'thumbnail': format_field(video_info, 'posterImage', 'https://lnk.lt/all-images/%s'),
  71. 'duration': int_or_none(video_info.get('duration')),
  72. 'description': clean_html(video_info.get('htmlDescription')),
  73. 'age_limit': self._AGE_LIMITS.get(video_info.get('pgRating'), 0),
  74. 'timestamp': parse_iso8601(video_info.get('airDate')),
  75. 'view_count': int_or_none(video_info.get('viewsCount')),
  76. }
  77. class LnkIE(InfoExtractor):
  78. _VALID_URL = r'https?://(?:www\.)?lnk\.lt/[^/]+/(?P<id>\d+)'
  79. _TESTS = [{
  80. 'url': 'https://lnk.lt/zinios/79791',
  81. 'info_dict': {
  82. 'id': '79791',
  83. 'ext': 'mp4',
  84. 'title': 'LNK.lt: Viešintų gyventojai sukilo prieš radijo bangų siųstuvą',
  85. 'description': 'Svarbiausios naujienos trumpai, LNK žinios ir Info dienos pokalbiai.',
  86. 'view_count': int,
  87. 'duration': 233,
  88. 'upload_date': '20191123',
  89. 'thumbnail': r're:^https?://.*\.jpg$',
  90. 'episode_number': 13431,
  91. 'series': 'Naujausi žinių reportažai',
  92. 'episode': 'Episode 13431'
  93. },
  94. 'params': {'skip_download': True}
  95. }, {
  96. 'url': 'https://lnk.lt/istorijos-trumpai/152546',
  97. 'info_dict': {
  98. 'id': '152546',
  99. 'ext': 'mp4',
  100. 'title': 'Radžio koncertas gaisre ',
  101. 'description': 'md5:0666b5b85cb9fc7c1238dec96f71faba',
  102. 'view_count': int,
  103. 'duration': 54,
  104. 'upload_date': '20220105',
  105. 'thumbnail': r're:^https?://.*\.jpg$',
  106. 'episode_number': 1036,
  107. 'series': 'Istorijos trumpai',
  108. 'episode': 'Episode 1036'
  109. },
  110. 'params': {'skip_download': True}
  111. }, {
  112. 'url': 'https://lnk.lt/gyvunu-pasaulis/151549',
  113. 'info_dict': {
  114. 'id': '151549',
  115. 'ext': 'mp4',
  116. 'title': 'Gyvūnų pasaulis',
  117. 'description': '',
  118. 'view_count': int,
  119. 'duration': 1264,
  120. 'upload_date': '20220108',
  121. 'thumbnail': r're:^https?://.*\.jpg$',
  122. 'episode_number': 16,
  123. 'series': 'Gyvūnų pasaulis',
  124. 'episode': 'Episode 16'
  125. },
  126. 'params': {'skip_download': True}
  127. }]
  128. def _real_extract(self, url):
  129. id = self._match_id(url)
  130. video_json = self._download_json(f'https://lnk.lt/api/video/video-config/{id}', id)['videoInfo']
  131. formats, subtitles = [], {}
  132. if video_json.get('videoUrl'):
  133. fmts, subs = self._extract_m3u8_formats_and_subtitles(video_json['videoUrl'], id)
  134. formats.extend(fmts)
  135. subtitles = self._merge_subtitles(subtitles, subs)
  136. if video_json.get('videoFairplayUrl') and not video_json.get('drm'):
  137. fmts, subs = self._extract_m3u8_formats_and_subtitles(video_json['videoFairplayUrl'], id)
  138. formats.extend(fmts)
  139. subtitles = self._merge_subtitles(subtitles, subs)
  140. return {
  141. 'id': id,
  142. 'title': video_json.get('title'),
  143. 'description': video_json.get('description'),
  144. 'view_count': video_json.get('viewsCount'),
  145. 'duration': video_json.get('duration'),
  146. 'upload_date': unified_strdate(video_json.get('airDate')),
  147. 'thumbnail': format_field(video_json, 'posterImage', 'https://lnk.lt/all-images/%s'),
  148. 'episode_number': int_or_none(video_json.get('episodeNumber')),
  149. 'series': video_json.get('programTitle'),
  150. 'formats': formats,
  151. 'subtitles': subtitles,
  152. }