This commit is contained in:
Sol Toder 2024-05-11 04:44:45 +08:00 committed by GitHub
commit 9ab04b1ea6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 13 additions and 0 deletions

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']