Skip to content

Instantly share code, notes, and snippets.

@miromannino
Last active December 10, 2023 22:52
Show Gist options
  • Save miromannino/53f80ea26f6570bd38f8d4b166f390fc to your computer and use it in GitHub Desktop.
Save miromannino/53f80ea26f6570bd38f8d4b166f390fc to your computer and use it in GitHub Desktop.
Download Wistia videos in a Teachable course to be able to watch offline

Go to your teachable course and show the page where videos are.

Now open your Browser's console. For example in Chrome you can press F12 to open it.

Paste the following code in the console

$('.attachment-wistia-player').each(function () { console.log($(this).attr('data-wistia-id')); });

Press enter to retrieve all videos IDs that are present in the opened page. For example:

myid1
myid2
myid3

Paste the list of videos ids to download in a file ids.txt

Lunch the provided wistia-downloader.py with the command line:

python3 wistia-downloader.py

This will read the videos IDs from the file ids.txt and it will download the videos in the current directory

import requests
import re
import json
import urllib.request
ids = open('ids.txt').read().split('\n')
num = 0
for wid in ids:
r = requests.get('https://fast.wistia.net/embed/iframe/' + wid, allow_redirects=True)
content = str(r.content).replace('\\\'', '') \
.replace('\\\\"', '') \
.replace('\\', '')
rs = re.search("iframeInit\((.*?)\);", content)
f = open('debug.json', 'w')
f.write("[" + rs.group(1) + "]")
f.close
json_config = json.loads("[" + rs.group(1) + "]")
filename = '{:02d}'.format(num) + ' - ' + json_config[0]['name']
assets = json_config[0]['assets']
max_size = 0
link_with_max_size = 'NONE'
for a in assets:
if a['size'] > max_size:
max_size = a['size']
link_with_max_size = a['url']
print('downloading ' + filename)
urllib.request.urlretrieve(link_with_max_size, filename)
print('download complete\n')
num += 1
@amclaire
Copy link

it doesn't work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment