aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--yt_dlp/extractor/extractors.py4
-rw-r--r--yt_dlp/extractor/nate.py124
-rw-r--r--yt_dlp/extractor/olympics.py5
-rw-r--r--yt_dlp/extractor/sonyliv.py60
-rw-r--r--yt_dlp/extractor/tiktok.py18
5 files changed, 199 insertions, 12 deletions
diff --git a/yt_dlp/extractor/extractors.py b/yt_dlp/extractor/extractors.py
index 73eb374ee..e4755b3d1 100644
--- a/yt_dlp/extractor/extractors.py
+++ b/yt_dlp/extractor/extractors.py
@@ -857,6 +857,10 @@ from .n1 import (
N1InfoAssetIE,
N1InfoIIE,
)
+from .nate import (
+ NateIE,
+ NateProgramIE,
+)
from .nationalgeographic import (
NationalGeographicVideoIE,
NationalGeographicTVIE,
diff --git a/yt_dlp/extractor/nate.py b/yt_dlp/extractor/nate.py
new file mode 100644
index 000000000..072faf6ea
--- /dev/null
+++ b/yt_dlp/extractor/nate.py
@@ -0,0 +1,124 @@
+# coding: utf-8
+from __future__ import unicode_literals
+
+import itertools
+
+from .common import InfoExtractor
+from ..utils import (
+ int_or_none,
+ str_or_none,
+ traverse_obj,
+ unified_strdate,
+)
+
+
+class NateIE(InfoExtractor):
+ _VALID_URL = r'https?://tv\.nate\.com/clip/(?P<id>[0-9]+)'
+
+ _TESTS = [{
+ 'url': 'https://tv.nate.com/clip/1848976',
+ 'info_dict': {
+ 'id': '1848976',
+ 'ext': 'mp4',
+ 'title': '[결승 오프닝 타이틀] 2018 LCK 서머 스플릿 결승전 kt Rolster VS Griffin',
+ 'description': 'md5:e1b79a7dcf0d8d586443f11366f50e6f',
+ 'thumbnail': r're:^https?://.*\.jpg',
+ 'upload_date': '20180908',
+ 'age_limit': 15,
+ 'duration': 73,
+ 'uploader': '2018 LCK 서머 스플릿(롤챔스)',
+ 'channel': '2018 LCK 서머 스플릿(롤챔스)',
+ 'channel_id': '3606',
+ 'uploader_id': '3606',
+ 'tags': 'count:59',
+ },
+ 'params': {'skip_download': True}
+ }, {
+ 'url': 'https://tv.nate.com/clip/4300566',
+ 'info_dict': {
+ 'id': '4300566',
+ 'ext': 'mp4',
+ 'title': '[심쿵엔딩] 이준호x이세영, 서로를 기억하며 끌어안는 두 사람!💕, MBC 211204 방송',
+ 'description': 'md5:be1653502d9c13ce344ddf7828e089fa',
+ 'thumbnail': r're:^https?://.*\.jpg',
+ 'upload_date': '20211204',
+ 'age_limit': 15,
+ 'duration': 201,
+ 'uploader': '옷소매 붉은 끝동',
+ 'channel': '옷소매 붉은 끝동',
+ 'channel_id': '27987',
+ 'uploader_id': '27987',
+ 'tags': 'count:20',
+ },
+ 'params': {'skip_download': True}
+ }]
+
+ _QUALITY = {
+ '36': 2160,
+ '35': 1080,
+ '34': 720,
+ '33': 480,
+ '32': 360,
+ '31': 270,
+ }
+
+ def _real_extract(self, url):
+ id = self._match_id(url)
+ video_data = self._download_json(f'https://tv.nate.com/api/v1/clip/{id}', id)
+ formats = [{
+ 'format_id': f_url[-2:],
+ 'url': f_url,
+ 'height': self._QUALITY.get(f_url[-2:]),
+ 'quality': int_or_none(f_url[-2:]),
+ } for f_url in video_data.get('smcUriList') or []]
+ self._sort_formats(formats)
+ return {
+ 'id': id,
+ 'title': video_data.get('clipTitle'),
+ 'description': video_data.get('synopsis'),
+ 'thumbnail': video_data.get('contentImg'),
+ 'upload_date': unified_strdate(traverse_obj(video_data, 'broadDate', 'regDate')),
+ 'age_limit': video_data.get('targetAge'),
+ 'duration': video_data.get('playTime'),
+ 'formats': formats,
+ 'uploader': video_data.get('programTitle'),
+ 'channel': video_data.get('programTitle'),
+ 'channel_id': str_or_none(video_data.get('programSeq')),
+ 'uploader_id': str_or_none(video_data.get('programSeq')),
+ 'tags': video_data['hashTag'].split(',') if video_data.get('hashTag') else None,
+ }
+
+
+class NateProgramIE(InfoExtractor):
+ _VALID_URL = r'https?://tv\.nate\.com/program/clips/(?P<id>[0-9]+)'
+
+ _TESTS = [{
+ 'url': 'https://tv.nate.com/program/clips/27987',
+ 'playlist_mincount': 191,
+ 'info_dict': {
+ 'id': '27987',
+ },
+ }, {
+ 'url': 'https://tv.nate.com/program/clips/3606',
+ 'playlist_mincount': 15,
+ 'info_dict': {
+ 'id': '3606',
+ },
+ }]
+
+ def _entries(self, id):
+ for page_num in itertools.count(1):
+ program_data = self._download_json(f'https://tv.nate.com/api/v1/program/{id}/clip/ranking?size=20&page={page_num}',
+ id, note=f'Downloading page {page_num}')
+ for clip in program_data.get('content') or []:
+ clip_id = clip.get('clipSeq')
+ if clip_id:
+ yield self.url_result(
+ 'https://tv.nate.com/clip/%s' % clip_id,
+ ie=NateIE.ie_key(), video_id=clip_id)
+ if program_data.get('last'):
+ break
+
+ def _real_extract(self, url):
+ id = self._match_id(url)
+ return self.playlist_result(self._entries(id), playlist_id=id)
diff --git a/yt_dlp/extractor/olympics.py b/yt_dlp/extractor/olympics.py
index 0aad836fa..784f282c7 100644
--- a/yt_dlp/extractor/olympics.py
+++ b/yt_dlp/extractor/olympics.py
@@ -19,6 +19,7 @@ class OlympicsReplayIE(InfoExtractor):
'upload_date': '20210801',
'timestamp': 1627783200,
'description': 'md5:c66af4a5bc7429dbcc43d15845ff03b3',
+ 'uploader': 'International Olympic Committee',
},
'params': {
'skip_download': True,
@@ -61,10 +62,8 @@ class OlympicsReplayIE(InfoExtractor):
return {
'id': uuid,
'title': title,
- 'timestamp': json_ld.get('timestamp'),
- 'description': json_ld.get('description'),
'thumbnails': thumbnails,
- 'duration': json_ld.get('duration'),
'formats': formats,
'subtitles': subtitles,
+ **json_ld
}
diff --git a/yt_dlp/extractor/sonyliv.py b/yt_dlp/extractor/sonyliv.py
index c3ed44275..a5026b2e0 100644
--- a/yt_dlp/extractor/sonyliv.py
+++ b/yt_dlp/extractor/sonyliv.py
@@ -1,6 +1,9 @@
# coding: utf-8
from __future__ import unicode_literals
+import datetime
+import math
+import random
import time
import uuid
@@ -56,17 +59,57 @@ class SonyLIVIE(InfoExtractor):
'only_matching': True,
}]
_GEO_COUNTRIES = ['IN']
- _TOKEN = None
+ _HEADERS = {}
+ _LOGIN_HINT = 'Use "--username <mobile_number>" to login using OTP or "--username token --password <auth_token>" to login using auth token.'
+ _NETRC_MACHINE = 'sonyliv'
+
+ def _get_device_id(self):
+ e = int(time.time() * 1000)
+ t = list('xxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx')
+ for i, c in enumerate(t):
+ n = int((e + 16 * random.random()) % 16) | 0
+ e = math.floor(e / 16)
+ if c == 'x':
+ t[i] = str(n)
+ elif c == 'y':
+ t[i] = '{:x}'.format(3 & n | 8)
+ return ''.join(t) + '-' + str(int(time.time() * 1000))
+
+ def _login(self, username, password):
+ if username.lower() == 'token' and len(password) > 1198:
+ return password
+ elif len(username) != 10 or not username.isdigit():
+ raise ExtractorError(f'Invalid username/password; {self._LOGIN_HINT}')
+
+ self.report_login()
+ data = '''{"mobileNumber":"%s","channelPartnerID":"MSMIND","country":"IN","timestamp":"%s",
+ "otpSize":6,"loginType":"REGISTERORSIGNIN","isMobileMandatory":true}
+ ''' % (username, datetime.datetime.now().strftime("%Y-%m-%dT%H:%M:%S.%MZ"))
+ otp_request_json = self._download_json(
+ 'https://apiv2.sonyliv.com/AGL/1.6/A/ENG/WEB/IN/HR/CREATEOTP-V2',
+ None, note='Sending OTP', data=data.encode(), headers=self._HEADERS)
+ if otp_request_json['resultCode'] == 'KO':
+ raise ExtractorError(otp_request_json['message'], expected=True)
+ otp_code = self._get_tfa_info('OTP')
+ data = '''{"channelPartnerID":"MSMIND","mobileNumber":"%s","country":"IN","otp":"%s",
+ "dmaId":"IN","ageConfirmation":true,"timestamp":"%s","isMobileMandatory":true}
+ ''' % (username, otp_code, datetime.datetime.now().strftime("%Y-%m-%dT%H:%M:%S.%MZ"))
+ otp_verify_json = self._download_json(
+ 'https://apiv2.sonyliv.com/AGL/2.0/A/ENG/WEB/IN/HR/CONFIRMOTP-V2',
+ None, note='Verifying OTP', data=data.encode(), headers=self._HEADERS)
+ if otp_verify_json['resultCode'] == 'KO':
+ raise ExtractorError(otp_request_json['message'], expected=True)
+ return otp_verify_json['resultObj']['accessToken']
def _call_api(self, version, path, video_id):
- headers = {}
- if self._TOKEN:
- headers['security_token'] = self._TOKEN
try:
return self._download_json(
'https://apiv2.sonyliv.com/AGL/%s/A/ENG/WEB/%s' % (version, path),
- video_id, headers=headers)['resultObj']
+ video_id, headers=self._HEADERS)['resultObj']
except ExtractorError as e:
+ if isinstance(e.cause, compat_HTTPError) and e.cause.code == 406 and self._parse_json(
+ e.cause.read().decode(), video_id)['message'] == 'Please subscribe to watch this content':
+ self.raise_login_required(self._LOGIN_HINT, method=None)
if isinstance(e.cause, compat_HTTPError) and e.cause.code == 403:
message = self._parse_json(
e.cause.read().decode(), video_id)['message']
@@ -76,7 +119,12 @@ class SonyLIVIE(InfoExtractor):
raise
def _real_initialize(self):
- self._TOKEN = self._call_api('1.4', 'ALL/GETTOKEN', None)
+ self._HEADERS['security_token'] = self._call_api('1.4', 'ALL/GETTOKEN', None)
+ username, password = self._get_login_info()
+ if username:
+ self._HEADERS['device_id'] = self._get_device_id()
+ self._HEADERS['content-type'] = 'application/json'
+ self._HEADERS['authorization'] = self._login(username, password)
def _real_extract(self, url):
video_id = self._match_id(url)
diff --git a/yt_dlp/extractor/tiktok.py b/yt_dlp/extractor/tiktok.py
index 7d79ad8d5..a3079151a 100644
--- a/yt_dlp/extractor/tiktok.py
+++ b/yt_dlp/extractor/tiktok.py
@@ -26,8 +26,9 @@ class TikTokBaseIE(InfoExtractor):
_MANIFEST_APP_VERSION = '291'
_APP_NAME = 'trill'
_AID = 1180
- _API_HOSTNAME = 'api-t2.tiktokv.com'
+ _API_HOSTNAME = 'api-h2.tiktokv.com'
_UPLOADER_URL_FORMAT = 'https://www.tiktok.com/@%s'
+ _WEBPAGE_HOST = 'https://www.tiktok.com/'
QUALITIES = ('360p', '540p', '720p')
def _call_api(self, ep, query, video_id, fatal=True,
@@ -68,6 +69,9 @@ class TikTokBaseIE(InfoExtractor):
'cp': 'cbfhckdckkde1',
}
self._set_cookie(self._API_HOSTNAME, 'odin_tt', ''.join(random.choice('0123456789abcdef') for _ in range(160)))
+ webpage_cookies = self._get_cookies(self._WEBPAGE_HOST)
+ if webpage_cookies.get('sid_tt'):
+ self._set_cookie(self._API_HOSTNAME, 'sid_tt', webpage_cookies['sid_tt'].value)
return self._download_json(
'https://%s/aweme/v1/%s/' % (self._API_HOSTNAME, ep), video_id=video_id,
fatal=fatal, note=note, errnote=errnote, headers={
@@ -176,6 +180,7 @@ class TikTokBaseIE(InfoExtractor):
user_url = self._UPLOADER_URL_FORMAT % (traverse_obj(author_info,
'sec_uid', 'id', 'uid', 'unique_id',
expected_type=str_or_none, get_all=False))
+ labels = traverse_obj(aweme_detail, ('hybrid_label', ..., 'text'), expected_type=str)
contained_music_track = traverse_obj(
music_info, ('matched_song', 'title'), ('matched_pgc_sound', 'title'), expected_type=str)
@@ -206,7 +211,11 @@ class TikTokBaseIE(InfoExtractor):
'timestamp': int_or_none(aweme_detail.get('create_time')),
'formats': formats,
'thumbnails': thumbnails,
- 'duration': int_or_none(traverse_obj(video_info, 'duration', ('download_addr', 'duration')), scale=1000)
+ 'duration': int_or_none(traverse_obj(video_info, 'duration', ('download_addr', 'duration')), scale=1000),
+ 'availability': self._availability(
+ is_private='Private' in labels,
+ needs_subscription='Friends only' in labels,
+ is_unlisted='Followers only' in labels)
}
def _parse_aweme_video_web(self, aweme_detail, webpage_url):
@@ -340,7 +349,9 @@ class TikTokIE(TikTokBaseIE):
def _extract_aweme_app(self, aweme_id):
aweme_detail = self._call_api('aweme/detail', {'aweme_id': aweme_id}, aweme_id,
- note='Downloading video details', errnote='Unable to download video details')['aweme_detail']
+ note='Downloading video details', errnote='Unable to download video details').get('aweme_detail')
+ if not aweme_detail:
+ raise ExtractorError('Video not available', video_id=aweme_id)
return self._parse_aweme_video_app(aweme_detail)
def _real_extract(self, url):
@@ -542,6 +553,7 @@ class DouyinIE(TikTokIE):
_AID = 1128
_API_HOSTNAME = 'aweme.snssdk.com'
_UPLOADER_URL_FORMAT = 'https://www.douyin.com/user/%s'
+ _WEBPAGE_HOST = 'https://www.douyin.com/'
def _real_extract(self, url):
video_id = self._match_id(url)