Skip to content

Instantly share code, notes, and snippets.

@lvm
Last active October 8, 2018 15:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lvm/e1ac21d96de5420c83de61b2b4edc38d to your computer and use it in GitHub Desktop.
Save lvm/e1ac21d96de5420c83de61b2b4edc38d to your computer and use it in GitHub Desktop.
conversesamplelibrary.com downloader

converse-dl

This a hacky script to download a bunch of samples from https://www.conversesamplelibrary.com/.

Useful info: https://www.reddit.com/r/edmproduction/comments/2ux1bq/converse_has_released_their_new_rubber_tracks/cocwtga/

HELP

usage: converse-dl.py [-h] [-a ACCESS_TOKEN] [-j JSON] [-t FILE_TYPE] [-w]
                   [-f FILTER_BY]

optional arguments:
  -h, --help            show this help message and exit
  -a ACCESS_TOKEN, --access-token ACCESS_TOKEN
                        Access Token required to download WAV files
  -j JSON, --json JSON  JSON with samples
  -t FILE_TYPE, --file-type FILE_TYPE
                        File type: 'mp3' or 'wav'. Default: mp3
  -w, --request-wav     When dowloading wav files, it requires an extra
                        request which provides the actual wav file url, this
                        option forces that extra request.
  -f FILTER_BY, --filter-by FILTER_BY
                        Filters. format: 'artist:dreamers,type:one_shot'
#!/usr/bin/env python3
import sys
import json
import argparse
import requests
HOST_STORAGE = "https://d34x6xks9kc6p2.cloudfront.net/"
WAV_URL = "https://www.conversesamplelibrary.com/motian_auth/samples/{sample_id}/download?access_token={access_token}"
def download_mp3(record):
return "{}{}".format(
HOST_STORAGE,
record.get('s3_key').replace('.wav', '.mp3')
)
def download_wav(record, access_token):
return WAV_URL.format(
sample_id=record.get('_id'),
access_token=access_token
)
def parse_json(json_file):
data = []
with open(json_file, 'r') as j:
data = json.load(j)
return data
def simplify(thing):
return "{}".format(thing).lower()
def matches(value, search):
result = False
search = simplify(search)
if isinstance(value, list):
if search in map(lambda s: simplify(s), value):
result = True
else:
if simplify(value) == search:
result = True
return result
def get_results(json_file, filter_by):
data = parse_json(json_file)
results = []
for record in data:
if all( [matches(record.get(f), s) for f,s in filter_by] ):
results += [record]
return results
def start(args):
filter_by = [(f,s) for f,s in [filt.split(':') for filt in args.filter_by.split(",")]]
file_type = args.file_type
if not args.access_token:
file_type = "mp3"
if args.json:
results = get_results(args.json, filter_by)
for r in results:
if args.file_type.lower() == "wav":
wav = download_wav(r, args.access_token)
if args.request_wav:
req = requests.get(wav)
print (req.json().get('download_url'))
else:
print (wav)
if args.file_type.lower() == "mp3":
print (download_mp3(r))
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument('-a', '--access-token',
type=str,
help="Access Token required to download WAV files")
parser.add_argument('-j', '--json',
type=str,
help="JSON with samples")
parser.add_argument('-t', '--file-type',
type=str,
help="File type: 'mp3' or 'wav'. Default: mp3",
default="mp3")
parser.add_argument('-w', '--request-wav',
action="store_true",
help="When dowloading wav files, it requires an extra request which provides the actual wav file url, this option forces that extra request.",
default=False)
parser.add_argument('-f', '--filter-by',
type=str,
help="Filters. format: 'artist:dreamers,type:one_shot'")
args = parser.parse_args()
start(args)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment