]> jfr.im git - yt-dlp.git/blobdiff - yt_dlp/extractor/lnkgo.py
[extractor/youtube] Fix live chat for videos with content warning
[yt-dlp.git] / yt_dlp / extractor / lnkgo.py
index 3e71852aab92fdfb607332cb1438f526f7ee6ae0..3bb52777f68bad4ade8d7a3effbb6b86a7436cdc 100644 (file)
@@ -1,14 +1,11 @@
-# coding: utf-8
-from __future__ import unicode_literals
-
-import re
-
 from .common import InfoExtractor
 from ..utils import (
     clean_html,
     compat_str,
+    format_field,
     int_or_none,
     parse_iso8601,
+    unified_strdate,
 )
 
 
@@ -58,7 +55,7 @@ class LnkGoIE(InfoExtractor):
     _M3U8_TEMPL = 'https://vod.lnk.lt/lnk_vod/lnk/lnk/%s:%s/playlist.m3u8%s'
 
     def _real_extract(self, url):
-        display_id, video_id = re.match(self._VALID_URL, url).groups()
+        display_id, video_id = self._match_valid_url(url).groups()
 
         video_info = self._download_json(
             'https://lnk.lt/api/main/video-page/%s/%s/false' % (display_id, video_id or '0'),
@@ -72,17 +69,97 @@ def _real_extract(self, url):
             video_id, 'mp4', 'm3u8_native')
         self._sort_formats(formats)
 
-        poster_image = video_info.get('posterImage')
-
         return {
             'id': video_id,
             'display_id': display_id,
             'title': title,
             'formats': formats,
-            'thumbnail': 'https://lnk.lt/all-images/' + poster_image if poster_image else None,
+            'thumbnail': format_field(video_info, 'posterImage', 'https://lnk.lt/all-images/%s'),
             'duration': int_or_none(video_info.get('duration')),
             'description': clean_html(video_info.get('htmlDescription')),
             'age_limit': self._AGE_LIMITS.get(video_info.get('pgRating'), 0),
             'timestamp': parse_iso8601(video_info.get('airDate')),
             'view_count': int_or_none(video_info.get('viewsCount')),
         }
+
+
+class LnkIE(InfoExtractor):
+    _VALID_URL = r'https?://(?:www\.)?lnk\.lt/[^/]+/(?P<id>\d+)'
+
+    _TESTS = [{
+        'url': 'https://lnk.lt/zinios/79791',
+        'info_dict': {
+            'id': '79791',
+            'ext': 'mp4',
+            'title': 'LNK.lt: Viešintų gyventojai sukilo prieš radijo bangų siųstuvą',
+            'description': 'Svarbiausios naujienos trumpai, LNK žinios ir Info dienos pokalbiai.',
+            'view_count': int,
+            'duration': 233,
+            'upload_date': '20191123',
+            'thumbnail': r're:^https?://.*\.jpg$',
+            'episode_number': 13431,
+            'series': 'Naujausi žinių reportažai',
+            'episode': 'Episode 13431'
+        },
+        'params': {'skip_download': True}
+    }, {
+        'url': 'https://lnk.lt/istorijos-trumpai/152546',
+        'info_dict': {
+            'id': '152546',
+            'ext': 'mp4',
+            'title': 'Radžio koncertas gaisre ',
+            'description': 'md5:0666b5b85cb9fc7c1238dec96f71faba',
+            'view_count': int,
+            'duration': 54,
+            'upload_date': '20220105',
+            'thumbnail': r're:^https?://.*\.jpg$',
+            'episode_number': 1036,
+            'series': 'Istorijos trumpai',
+            'episode': 'Episode 1036'
+        },
+        'params': {'skip_download': True}
+    }, {
+        'url': 'https://lnk.lt/gyvunu-pasaulis/151549',
+        'info_dict': {
+            'id': '151549',
+            'ext': 'mp4',
+            'title': 'Gyvūnų pasaulis',
+            'description': '',
+            'view_count': int,
+            'duration': 1264,
+            'upload_date': '20220108',
+            'thumbnail': r're:^https?://.*\.jpg$',
+            'episode_number': 16,
+            'series': 'Gyvūnų pasaulis',
+            'episode': 'Episode 16'
+        },
+        'params': {'skip_download': True}
+    }]
+
+    def _real_extract(self, url):
+        id = self._match_id(url)
+        video_json = self._download_json(f'https://lnk.lt/api/video/video-config/{id}', id)['videoInfo']
+        formats, subtitles = [], {}
+        if video_json.get('videoUrl'):
+            fmts, subs = self._extract_m3u8_formats_and_subtitles(video_json['videoUrl'], id)
+            formats.extend(fmts)
+            subtitles = self._merge_subtitles(subtitles, subs)
+        if video_json.get('videoFairplayUrl') and not video_json.get('drm'):
+            fmts, subs = self._extract_m3u8_formats_and_subtitles(video_json['videoFairplayUrl'], id)
+            formats.extend(fmts)
+            subtitles = self._merge_subtitles(subtitles, subs)
+
+        self._sort_formats(formats)
+        return {
+            'id': id,
+            'title': video_json.get('title'),
+            'description': video_json.get('description'),
+            'view_count': video_json.get('viewsCount'),
+            'duration': video_json.get('duration'),
+            'upload_date': unified_strdate(video_json.get('airDate')),
+            'thumbnail': format_field(video_json, 'posterImage', 'https://lnk.lt/all-images/%s'),
+            'episode_number': int_or_none(video_json.get('episodeNumber')),
+            'series': video_json.get('programTitle'),
+            'formats': formats,
+            'subtitles': subtitles,
+        }