1
1
mirror of https://github.com/ytdl-org/youtube-dl synced 2024-11-09 05:37:09 +01:00
This commit is contained in:
Sol Toder 2024-07-28 01:29:37 +09:00 committed by GitHub
commit f5d8acf121
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,6 +1,7 @@
from __future__ import unicode_literals
import re
import random
from .common import InfoExtractor
from ..utils import (
@ -29,9 +30,19 @@ class RedditIE(InfoExtractor):
},
}
@staticmethod
def _gen_session_id():
# The actual value of the cookie does not seem to matter.
# Using a random 16-char hex string for now.
id_length = 16
rand_max = 1 << (id_length * 4)
return '%0.*x' % (id_length, random.randrange(rand_max))
def _real_extract(self, url):
video_id = self._match_id(url)
self._set_cookie('.reddit.com', 'reddit_session', RedditIE._gen_session_id())
formats = self._extract_m3u8_formats(
'https://v.redd.it/%s/HLSPlaylist.m3u8' % video_id, video_id,
'mp4', entry_protocol='m3u8_native', m3u8_id='hls', fatal=False)
@ -103,6 +114,8 @@ class RedditRIE(InfoExtractor):
video_id = self._match_id(url)
self._set_cookie('.reddit.com', 'reddit_session', RedditIE._gen_session_id())
data = self._download_json(
url + '/.json', video_id)[0]['data']['children'][0]['data']