Skip to content

Instantly share code, notes, and snippets.

@ntpz
Created January 22, 2017 12:04
Show Gist options
  • Save ntpz/f3f694f297b5034a4b919f4091c8c1e8 to your computer and use it in GitHub Desktop.
Save ntpz/f3f694f297b5034a4b919f4091c8c1e8 to your computer and use it in GitHub Desktop.
calm.com audio exportee
import os
import requests
import json
import re
import urlparse
import unicodedata
URL = 'https://api.calm.com/programs/sections'
def main():
src = requests.get(URL).text
data = json.loads(src)
programs = data['programs']
print('#!/bin/bash\n')
for prog in programs:
dirname = title_to_filename(prog['title'])
print("\nmkdir '{}'".format(dirname))
wget_line(dirname + '/image.png', prog['image'])
if prog.get('background_image'):
wget_line(dirname + '/background.jpg', prog['background_image'])
for g in prog['guides']:
fileurl = g['file']
filename = str(g['position']) + '. ' + url_to_filename(fileurl)
wget_line(dirname + '/' + filename, fileurl)
def title_to_filename(value):
value = unicodedata.normalize('NFKD', value).encode('ascii', 'ignore')
value = unicode(re.sub('[^\w\s-]', '', value).strip())
return value
def url_to_filename(url):
parsed = urlparse.urlparse(url)
return os.path.basename(parsed.path)
def wget_line(out_name, url):
print("wget -nv -O'{}' {}".format(out_name, url))
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment