Advertisement
Guest User

twitter space dl

a guest
Dec 1st, 2021
345
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.09 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. import os
  3. import requests
  4. import re
  5. import time
  6. from datetime import datetime
  7.  
  8. def get_playlist_url(url):
  9.     response = requests.get(url)
  10.     playlist_url = re.search(r"(/Transcoding.*m3u8)", response.text).group(1)
  11.     playlist_url = re.search(r"(.*)/Transcoding", url).group(1) + playlist_url
  12.     return playlist_url
  13.  
  14. def get_m3u8(url, master_url):
  15.     pre = master_url.replace("master_playlist.m3u8", "")
  16.     with open("playlist.m3u8", "w") as file:
  17.         response = requests.get(url)
  18.         content = response.text.replace("chunk", f"{pre}chunk")
  19.         file.write(content)
  20.  
  21. if __name__ == '__main__':
  22.     url = input("Enter m3u8 playlist URL: ")
  23.     master_url = re.sub(r"dynamic.*", "master_playlist.m3u8", url)
  24.     playlist_url = get_playlist_url(master_url)
  25.     get_m3u8(playlist_url, master_url)
  26.     print("Downloading...")
  27.     t = datetime.now().strftime('%Y%m%d%H%M%S')
  28.     os.system(f"ffmpeg -loglevel quiet -protocol_whitelist https,file,tls,tcp -i playlist.m3u8 -c copy {t}.m4a")
  29.     os.remove("playlist.m3u8")
  30.     print(f"Done, file: {t}.m4a")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement