Spaces:
Runtime error
Runtime error
from operator import le | |
from matplotlib.cbook import violin_stats | |
import streamlit as st | |
from fake_useragent import UserAgent | |
import requests #doenload json, mp4 | |
import json | |
from telegram import Video #json parsing | |
ua = UserAgent() | |
st.title("Reddit Video Downloader") | |
reddit_url = st.text_input(label="Enter your reddit url here") | |
if reddit_url: | |
if reddit_url[len(reddit_url)-1] == "/": | |
json_url = reddit_url[:len(reddit_url)-1] + ".json" | |
else: | |
json_url = reddit_url + '.json' | |
headers = {'User-Agent':str(ua.random)} | |
json_response = requests.get(json_url, headers=headers) | |
st.write(json_response.status_code) | |
# st.write(headers) | |
if json_response.status_code != 200: | |
st.warning("Error Detected, check the URLl!!") | |
else: | |
mp4_url = json_response.json()[0]['data']['children'][0]['data']['secure_media']['reddit_video']['fallback_url'] | |
st.write(mp4_url) | |
with st.spinner("Waiting to download the video"): | |
mp4_response = requests.get(mp4_url,headers=headers ) | |
if mp4_response.status_code == 200: | |
st.video(mp4_response.content) | |
else: | |
st.warning("Video Download Failed") | |
else: | |
st.error("Enter a correct reddit url") |