import re import requests import tempfile import subprocess import urllib.request def parseRedditVideo(link: str, outPath: str): response = requests.get(url=link, headers = {'User-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:69.0) Gecko/20100101 Firefox/69.0'}) json = response.json() isVideo = json[0]['data']['children'][0]['data']['is_video'] if not isVideo: return mpdListLink = json[0]['data']['children'][0]['data']['media']['reddit_video']['dash_url'] mpdResponse = requests.get(url=mpdListLink, headers = {'User-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:69.0) Gecko/20100101 Firefox/69.0'}) mpdXMLData = mpdResponse.text baseLink = json[0]['data']['children'][0]['data']['url'] reSearchData = re.findall('(.*?)', mpdXMLData) highestVideoQualityFullLink = reSearchData[0] audioPartialLink = reSearchData[-1] highestVideoQualityFullLink = baseLink + '/' + highestVideoQualityFullLink audioFullLink = baseLink + '/' + audioPartialLink tempDir = tempfile.gettempdir() tempVideoFilepath = tempDir + '\\' + next(tempfile._get_candidate_names()) tempAudioFilepath = tempDir + '\\' + next(tempfile._get_candidate_names()) urllib.request.urlretrieve(highestVideoQualityFullLink, tempVideoFilepath) urllib.request.urlretrieve(audioFullLink, tempAudioFilepath) ffmpegJoiningCommand = f"ffmpeg -i \"{tempVideoFilepath}\" -i \"{tempAudioFilepath}\" -c copy \"{outPath}\"" subprocess.call(ffmpegJoiningCommand, shell=True) def main(): #Example link = "https://www.reddit.com/r/Animemes/comments/d5ga6a/sign_memes_are_now_banned/.json" parseRedditVideo(link,"G:\\out.mkv") main()