Skip to content

Instantly share code, notes, and snippets.

@qubodup
Last active December 16, 2015 01:09
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 qubodup/5353355 to your computer and use it in GitHub Desktop.
Save qubodup/5353355 to your computer and use it in GitHub Desktop.
# This requires python3 # Add Freesound API key below, have "ids.txt" that contains two columns, separated by " " and the second one contains the ID # credits.txt will be overwritten (I think)
#!/usr/bin/python
# -*- coding: utf-8 -*-
# This requires python3
# Add Freesound API key below
# Needs "ids.txt" containing two columns, separated by " " and the second one = Sound ID
# credits.txt will be overwritten (I think)
# some of these might be useless
from __future__ import print_function
import urllib.request
import os
import json
import pprint
import time
import datetime
import random
import sqlite3 as lite
import sys
import logging
# You need to set your freesound api key here
FSKEY = "set your freesound api key here"
class App:
def __init__(self):
with open("ids.txt") as f:
content = f.readlines()
sounds = []
for i in content:
tmp = i.split(" ")
sounds.append([tmp[0], tmp[1].strip()])
for i in sounds:
sndid = i[1]
url="http://www.freesound.org/api/sounds/" + sndid + "/?api_key=" + FSKEY
try:
freesoundResponse = urllib.request.urlopen(url)
except Exception:
import traceback
print("ohno")
else:
jsonResponse = json.loads(freesoundResponse.read().decode("utf-8"))
# Metadata one-liners
self.sndTitleOrg = jsonResponse['original_filename']
self.sndTitle = jsonResponse['original_filename']
self.sndUserName = jsonResponse['user']['username']
self.sndUserUrl = jsonResponse['user']['url']
self.sndUrl = jsonResponse['url']
self.sndOggUrl = jsonResponse['preview-hq-ogg']
# License
self.sndLicenseUrl = jsonResponse['license']
self.license_construct()
self.attribution_construct()
f = open('credits.txt','a')
print(i[0] + ": " + self.sndAttribution + "\n", file=f)
# Creates license strings
def license_construct(self):
if self.sndLicenseUrl == "http://creativecommons.org/licenses/by/3.0/":
self.sndLicenseName = "CC-BY 3.0"
elif self.sndLicenseUrl == "http://creativecommons.org/publicdomain/zero/1.0/":
self.sndLicenseName = "CC0"
elif self.sndLicenseUrl == "http://creativecommons.org/licenses/by-nc/3.0/":
self.sndLicenseName = "CC-BY-NC 3.0"
else:
self.sndLicenseName = "CC-Sampling+"
self.sndLicense = self.sndLicenseName + ": " + self.sndLicenseUrl
# Creates attribution text
def attribution_construct(self):
self.sndAttribution = (
self.sndTitleOrg +
" by " +
self.sndUserName +
" " +
self.sndUserUrl +
"\n" +
self.sndUrl +
"\n" +
self.sndLicense
)
app = App()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment