Skip to content

Instantly share code, notes, and snippets.

@gileri
Created October 11, 2018 06:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gileri/4e2638e17e6464f5cdb3c90072387d27 to your computer and use it in GitHub Desktop.
Save gileri/4e2638e17e6464f5cdb3c90072387d27 to your computer and use it in GitHub Desktop.
blackpills.com HTTP Live Streaming (HLS) playlist ripper
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