soundcloud python/php apis, recorder python script so far.
This commit is contained in:
parent
b3e111b0a0
commit
f68a8f67ea
109 changed files with 24297 additions and 10 deletions
8
python_apps/show-recorder/config.cfg
Normal file
8
python_apps/show-recorder/config.cfg
Normal file
|
@ -0,0 +1,8 @@
|
|||
# Hostname
|
||||
base_url = 'http://campcaster.dev/'
|
||||
|
||||
# URL to get the version number of the server API
|
||||
show_schedule_url = 'Recorder/get-show-schedule/format/json'
|
||||
|
||||
# base path to store recordered shows at
|
||||
base_recorded_files = '/home/naomi/Music/'
|
118
python_apps/show-recorder/testrecordscript.py
Normal file
118
python_apps/show-recorder/testrecordscript.py
Normal file
|
@ -0,0 +1,118 @@
|
|||
#!/usr/local/bin/python
|
||||
import urllib
|
||||
import logging
|
||||
import json
|
||||
import time
|
||||
import datetime
|
||||
|
||||
from eci import *
|
||||
from configobj import ConfigObj
|
||||
import subprocess
|
||||
|
||||
# loading config file
|
||||
try:
|
||||
config = ConfigObj('config.cfg')
|
||||
except Exception, e:
|
||||
print 'Error loading config file: ', e
|
||||
sys.exit()
|
||||
|
||||
shows_to_record = {}
|
||||
|
||||
|
||||
def record_show(filelength, filename, filetype="mp3"):
|
||||
|
||||
length = str(filelength)+".0"
|
||||
filename = filename.replace(" ", "-")
|
||||
filepath = "%s%s.%s" % (config["base_recorded_files"], filename, filetype)
|
||||
|
||||
e = ECI()
|
||||
|
||||
e("cs-add play_chainsetup")
|
||||
e("c-add 1st_chain")
|
||||
e("ai-add alsa")
|
||||
e("ao-add "+filepath)
|
||||
e("cs-set-length "+length)
|
||||
e("cop-select 1")
|
||||
e("cs-connect")
|
||||
e("start")
|
||||
|
||||
while 1:
|
||||
time.sleep(1)
|
||||
|
||||
if e("engine-status") != "running":
|
||||
break
|
||||
|
||||
e("stop")
|
||||
e("cs-disconnect")
|
||||
|
||||
return filepath
|
||||
|
||||
|
||||
def getDateTimeObj(time):
|
||||
|
||||
timeinfo = time.split(" ")
|
||||
date = timeinfo[0].split("-")
|
||||
time = timeinfo[1].split(":")
|
||||
|
||||
return datetime.datetime(int(date[0]), int(date[1]), int(date[2]), int(time[0]), int(time[1]), int(time[2]))
|
||||
|
||||
def process_shows(shows):
|
||||
|
||||
for show in shows:
|
||||
show_starts = getDateTimeObj(show[u'starts'])
|
||||
show_end = getDateTimeObj(show[u'ends'])
|
||||
time_delta = show_end - show_starts
|
||||
|
||||
shows_to_record[show[u'starts']] = time_delta
|
||||
|
||||
|
||||
def check_record():
|
||||
|
||||
tnow = datetime.datetime.now()
|
||||
sorted_show_keys = sorted(shows_to_record.keys())
|
||||
start_time = sorted_show_keys[0]
|
||||
next_show = getDateTimeObj(start_time)
|
||||
|
||||
#print tnow, next_show
|
||||
|
||||
#tnow = getDateTimeObj("2011-03-04 16:00:00")
|
||||
#next_show = getDateTimeObj("2011-03-04 16:00:01")
|
||||
|
||||
delta = next_show - tnow
|
||||
|
||||
if delta <= datetime.timedelta(seconds=60):
|
||||
time.sleep(delta.seconds)
|
||||
|
||||
show_length = shows_to_record[start_time]
|
||||
filepath = record_show(show_length.seconds, start_time)
|
||||
#filepath = record_show(10, "2011-03-04 16:00:00")
|
||||
|
||||
command = "%s -c %s" %("../../utils/airtime-import", filepath)
|
||||
subprocess.call([command],shell=True)
|
||||
|
||||
|
||||
def get_shows():
|
||||
|
||||
url = config["base_url"] + config["show_schedule_url"]
|
||||
#url = url.replace("%%from%%", "2011-03-13 20:00:00")
|
||||
#url = url.replace("%%to%%", "2011-04-17 21:00:00")
|
||||
|
||||
response = urllib.urlopen(url)
|
||||
data = response.read()
|
||||
response_json = json.loads(data)
|
||||
shows = response_json[u'shows']
|
||||
print shows
|
||||
|
||||
if len(shows):
|
||||
process_shows(shows)
|
||||
check_record()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
while True:
|
||||
get_shows()
|
||||
time.sleep(30)
|
||||
|
||||
|
||||
|
59
python_apps/show-recorder/testsoundcloud.py
Normal file
59
python_apps/show-recorder/testsoundcloud.py
Normal file
|
@ -0,0 +1,59 @@
|
|||
import webbrowser
|
||||
import scapi
|
||||
|
||||
# the host to connect to. Normally, this
|
||||
# would be api.soundcloud.com
|
||||
API_HOST = "api.soundcloud.com"
|
||||
|
||||
# This needs to be the consumer ID you got from
|
||||
# http://soundcloud.com/settings/applications/new
|
||||
CONSUMER = "2CLCxcSXYzx7QhhPVHN4A"
|
||||
# This needs to be the consumer secret password you got from
|
||||
# http://soundcloud.com/settings/applications/new
|
||||
CONSUMER_SECRET = "pZ7beWmF06epXLHVUP1ufOg2oEnIt9XhE8l8xt0bBs"
|
||||
|
||||
# first, we create an OAuthAuthenticator that only knows about consumer
|
||||
# credentials. This is done so that we can get an request-token as
|
||||
# first step.
|
||||
oauth_authenticator = scapi.authentication.OAuthAuthenticator(CONSUMER,
|
||||
CONSUMER_SECRET,
|
||||
None,
|
||||
None)
|
||||
|
||||
# The connector works with the authenticator to create and sign the requests. It
|
||||
# has some helper-methods that allow us to do the OAuth-dance.
|
||||
connector = scapi.ApiConnector(host=API_HOST, authenticator=oauth_authenticator)
|
||||
|
||||
# First step is to get a request-token, and to let the user authorize that
|
||||
# via the browser.
|
||||
token, secret = connector.fetch_request_token()
|
||||
authorization_url = connector.get_request_token_authorization_url(token)
|
||||
webbrowser.open(authorization_url)
|
||||
oauth_verifier = raw_input("please enter verifier code as seen in the browser:")
|
||||
|
||||
# Now we create a new authenticator with the temporary token & secret we got from
|
||||
# the request-token. This will give us the access-token
|
||||
oauth_authenticator = scapi.authentication.OAuthAuthenticator(CONSUMER,
|
||||
CONSUMER_SECRET,
|
||||
token,
|
||||
secret)
|
||||
|
||||
# we need a new connector with the new authenticator!
|
||||
connector = scapi.ApiConnector(API_HOST, authenticator=oauth_authenticator)
|
||||
token, secret = connector.fetch_access_token(oauth_verifier)
|
||||
|
||||
|
||||
# now we are finally ready to go - with all four parameters OAuth requires,
|
||||
# we can setup an authenticator that allows for actual API-calls.
|
||||
oauth_authenticator = scapi.authentication.OAuthAuthenticator(CONSUMER,
|
||||
CONSUMER_SECRET,
|
||||
token,
|
||||
secret)
|
||||
|
||||
# we pass the connector to a Scope - a Scope is essentially a path in the REST-url-space.
|
||||
# Without any path-component, it's the root from which we can then query into the
|
||||
# resources.
|
||||
root = scapi.Scope(scapi.ApiConnector(host=API_HOST, authenticator=oauth_authenticator))
|
||||
|
||||
# Hey, nice meeting you! Connected to SoundCloud using OAuth will allow you to access protected resources, like the current user's name.
|
||||
print "Hello, %s" % root.me().username
|
Loading…
Add table
Add a link
Reference in a new issue