Created
December 31, 2022 04:08
-
-
Save Benjins/75e72b6004960f144d337f767d07b893 to your computer and use it in GitHub Desktop.
A quick python script to download videos from the food network site. Written on Dec. 30, 2022 and may not work on all playlists, or for a long time
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import json | |
from urllib.request import urlopen | |
import subprocess | |
FFMPEG = 'ffmpeg' | |
def DLPath(path, filename): | |
url = 'https://www.foodnetwork.com/apps/api/playback?path=' + path | |
print('Using FFMPEG to DL "%s" -> "%s"' % (url, filename)) | |
subprocess.run([FFMPEG, '-i', url, '-c', 'copy', filename]) | |
def DLVid(url): | |
print('Downloading "%s"...' % url) | |
with urlopen(url) as fNet: | |
txt = fNet.read().decode('utf-8', 'ignore') | |
for config in txt.split('<script type="text/x-config">')[1:]: | |
config = config.split('</script>',1)[0] | |
config_js = None | |
try: | |
config_js = json.loads(config) | |
except: | |
continue | |
if config_js is not None and 'webPlayer' in config_js: | |
if 'channels' in config_js['webPlayer']: | |
channel = config_js['webPlayer']['channels'][0] | |
for video in channel['videos']: | |
path = video['path'] | |
video_id = video['videoID'] | |
metadata = video['mux']['metaData'] | |
vid_filename = '%s - %s.mp4' % (metadata['videoTitle'], metadata['videoId']) | |
meta_filename = '%s - %s.json' % (metadata['videoTitle'], metadata['videoId']) | |
with open(meta_filename, 'w', encoding='utf-8') as f: | |
f.write(json.dumps(video)) | |
DLPath(path, vid_filename) | |
break | |
for arg in sys.argv[1:]: | |
DLVid(arg) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment