Created
October 11, 2018 06:26
-
-
Save gileri/4e2638e17e6464f5cdb3c90072387d27 to your computer and use it in GitHub Desktop.
blackpills.com HTTP Live Streaming (HLS) playlist ripper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
from subprocess import run | |
import sys | |
import os | |
import urllib.request | |
import requests | |
EPISODES = ( | |
'https://e-cdn-stream.blackpills.com/stream/<id>/hls/<id>.m3u8', | |
) | |
i = 1 | |
for episode_playlist in EPISODES: | |
episode_directory = str(i) | |
if not os.path.isdir(episode_directory): | |
os.mkdir(episode_directory) | |
# Download video and audio | |
run(['youtube-dl', '-o', f"{episode_directory}/%(id)s.%(ext)s", episode_playlist]) | |
# Download subtitles | |
global_playlist = requests.get(episode_playlist).text | |
subtitles_playlists = re.findall( | |
'^#EXT-X-MEDIA:TYPE=SUBTITLES.*LANGUAGE="(\w+)",.*,URI="([^"]*)"', | |
global_playlist, | |
re.MULTILINE | |
) | |
for language, subtitle_playlist_url in subtitles_playlists: | |
subtitle_url = re.search( | |
'^http.*$', | |
requests.get(subtitle_playlist_url).text, | |
re.MULTILINE | |
) | |
urllib.request.urlretrieve( | |
subtitle_url[0], | |
episode_directory + '/' + language + '.vtt' | |
) | |
i += 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment