Skip to content

Instantly share code, notes, and snippets.

@bradybellini
Created September 19, 2019 04:21
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 bradybellini/6850b4a3e639814abb596af3c1b69f7d to your computer and use it in GitHub Desktop.
Save bradybellini/6850b4a3e639814abb596af3c1b69f7d to your computer and use it in GitHub Desktop.
Download twitch clips with python without rendering js
import urllib.request
import json
import requests
import re
def main():
clip_url = input('Please enter the link of the clip(embed links not supported): ')
clip_name = input('Enter the name for the clip to be saved as: ')
if not clip_name:
clip_name = 'clip.mp4'
else:
clip_name = clip_name + '.mp4'
try:
clip_id = re.findall(r"^((http[s]?|ftp):\/)?\/?([^:\/\s]+)((\/\w+)*\/)([\w\-\.]+[^#?\s]+)(.*)?(#[\w\-]+)?$", clip_url)[0][5]
except Exception as e:
print(e)
url = 'https://clips.twitch.tv/api/v2/clips/' + clip_id + '/status'
r = requests.get(url)
data = json.loads(r.content.decode('utf-8'))
vid_link = data['quality_options'][0]['source']
try:
print("Downloading starting...\n")
urllib.request.urlretrieve(vid_link, clip_name)
print("Download completed!")
except Exception as e:
print(e)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment