mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-11-25 08:41:28 +01:00
Compare commits
3 Commits
4c7ea5454b
...
556ef77e4e
Author | SHA1 | Date | |
---|---|---|---|
|
556ef77e4e | ||
|
835c9ede66 | ||
|
6eaedcf5de |
|
@ -4,8 +4,6 @@ import json
|
|||
import re
|
||||
import time
|
||||
import uuid
|
||||
import requests
|
||||
from urllib.parse import urlparse
|
||||
|
||||
from .common import InfoExtractor
|
||||
from ..compat import compat_str
|
||||
|
@ -104,6 +102,7 @@ class HotStarIE(HotStarBaseIE):
|
|||
'upload_date': '20151111',
|
||||
'duration': 381,
|
||||
'episode': 'Can You Not Spread Rumours?',
|
||||
'thumbnail': r're:^https://img1.hotstarext.com/image/upload/f_auto/sources/.+',
|
||||
},
|
||||
'params': {'skip_download': 'm3u8'},
|
||||
}, {
|
||||
|
@ -124,6 +123,7 @@ class HotStarIE(HotStarBaseIE):
|
|||
'season_id': 6771,
|
||||
'episode': 'Janhvi Targets Suman',
|
||||
'episode_number': 8,
|
||||
'thumbnail': r're:^https://img1.hotstarext.com/image/upload/f_auto/sources/.+',
|
||||
}
|
||||
}, {
|
||||
'url': 'https://www.hotstar.com/in/shows/anupama/1260022017/anupama-anuj-share-a-moment/1000282843',
|
||||
|
@ -143,6 +143,7 @@ class HotStarIE(HotStarBaseIE):
|
|||
'episode_number': 853,
|
||||
'duration': 1272,
|
||||
'channel_id': 3,
|
||||
'thumbnail': r're:^https://img1.hotstarext.com/image/upload/f_auto/sources/.+',
|
||||
},
|
||||
'skip': 'HTTP Error 504: Gateway Time-out', # XXX: Investigate 504 errors on some episodes
|
||||
}, {
|
||||
|
@ -163,6 +164,7 @@ class HotStarIE(HotStarBaseIE):
|
|||
'episode_number': 1,
|
||||
'duration': 1810,
|
||||
'channel_id': 54,
|
||||
'thumbnail': r're:^https://img1.hotstarext.com/image/upload/f_auto/sources/.+',
|
||||
},
|
||||
}, {
|
||||
'url': 'https://www.hotstar.com/in/clips/e3-sairat-kahani-pyaar-ki/1000262286',
|
||||
|
@ -175,7 +177,7 @@ class HotStarIE(HotStarBaseIE):
|
|||
'upload_date': '20210606',
|
||||
'timestamp': 1622943900,
|
||||
'duration': 5395,
|
||||
'thumbnail': r're:^https://img1.hotstarext.com/.+',
|
||||
'thumbnail': r're:^https://img1.hotstarext.com/image/upload/f_auto/sources/.+',
|
||||
},
|
||||
}, {
|
||||
'url': 'https://www.hotstar.com/in/movies/premam/1000091195',
|
||||
|
@ -189,7 +191,7 @@ class HotStarIE(HotStarBaseIE):
|
|||
'upload_date': '20160502',
|
||||
'episode': 'Premam',
|
||||
'duration': 8994,
|
||||
'thumbnail': r're:^https://img1.hotstarext.com/.+',
|
||||
'thumbnail': r're:^https://img1.hotstarext.com/image/upload/f_auto/sources/.+',
|
||||
},
|
||||
}, {
|
||||
'url': 'https://www.hotstar.com/movies/radha-gopalam/1000057157',
|
||||
|
@ -232,54 +234,10 @@ class HotStarIE(HotStarBaseIE):
|
|||
root = join_nonempty(cls._BASE_URL, video_type, delim='/')
|
||||
return f'{root}/{slug}/{video_id}'
|
||||
|
||||
def _real_extract(self, url, st=None):
|
||||
def _real_extract(self, url):
|
||||
video_id, video_type = self._match_valid_url(url).group('id', 'type')
|
||||
exact_url = urlparse(url)
|
||||
url_path = exact_url.path
|
||||
video_type = self._TYPE.get(video_type, video_type)
|
||||
cookies = self._get_cookies(url) # Cookies before any request
|
||||
st = int_or_none(st) or int(time.time())
|
||||
exp = st + 6000
|
||||
auth = 'st=%d~exp=%d~acl=/*' % (st, exp)
|
||||
auth += '~hmac=' + hmac.new(self._AKAMAI_ENCRYPTION_KEY, auth.encode(), hashlib.sha256).hexdigest()
|
||||
if cookies and cookies.get('userUP'):
|
||||
token = cookies.get('userUP').value
|
||||
else:
|
||||
token = self._download_json(
|
||||
f'{self._API_URL}/um/v3/users',
|
||||
video_id, note='Downloading token',
|
||||
data=json.dumps({"device_ids": [{"id": compat_str(uuid.uuid4()), "type": "device_id"}]}).encode('utf-8'),
|
||||
headers={
|
||||
'hotstarauth': auth,
|
||||
'x-hs-platform': 'PCTV', # or 'web'
|
||||
'Content-Type': 'application/json',
|
||||
})['user_identity']
|
||||
json_data = {"deeplink_url": url_path, "app_launch_count": 0}
|
||||
header = {
|
||||
'x-hs-platform': 'web',
|
||||
'x-hs-usertoken': token,
|
||||
'Referer': url
|
||||
}
|
||||
|
||||
thumbnail_response = requests.post(
|
||||
f'{self._BASE_URL}/api/internal/bff/v2/start',
|
||||
headers=header,
|
||||
json=json_data # Use the data parameter for sending JSON data as a string
|
||||
).text
|
||||
response_json = json.loads(thumbnail_response)
|
||||
json_ld_data = response_json.get("success", {}).get("page", {}).get("spaces", {}).get("seo", {}).get("widget_wrappers", [{}])[0].get("widget", {}).get("data", {}).get("json_ld_data", {})
|
||||
thumbnails = []
|
||||
for schema in json_ld_data['schemas']:
|
||||
schema_dict = eval(schema)
|
||||
|
||||
# Check if the schema has 'thumbnailURL'
|
||||
if 'thumbnailURL' in schema_dict:
|
||||
thumbnail_info = {
|
||||
'url': schema_dict['thumbnailURL'],
|
||||
'preference': schema_dict.get('preference', 0),
|
||||
'id': str(len(thumbnails)) # You can adjust the id logic based on your requirements
|
||||
}
|
||||
thumbnails.append(thumbnail_info)
|
||||
video_data = traverse_obj(
|
||||
self._call_api_v1(
|
||||
f'{video_type}/detail', video_id, fatal=False, query={'tas': 10000, 'contentId': video_id}),
|
||||
|
@ -361,6 +319,17 @@ class HotStarIE(HotStarBaseIE):
|
|||
self._remove_duplicate_formats(formats)
|
||||
for f in formats:
|
||||
f.setdefault('http_headers', {}).update(headers)
|
||||
thumbnails = []
|
||||
img_list = video_data.get('images')
|
||||
base_url = "https://img1.hotstarext.com/image/upload/f_auto/"
|
||||
for index, (key, value) in enumerate(img_list.items()):
|
||||
thumbnail_url = base_url + value
|
||||
thumbnail_entry = {
|
||||
"url": thumbnail_url,
|
||||
"preference": index,
|
||||
"id": str(index)
|
||||
}
|
||||
thumbnails.append(thumbnail_entry)
|
||||
|
||||
return {
|
||||
'id': video_id,
|
||||
|
|
Loading…
Reference in New Issue
Block a user