Exemplo n.º 1
0
def record(r):
    util.lnp("recording %s" % r.data["title"])
    r.record()
    while not r.complete():
        time.sleep(10)
    r.tag()
    util.lnp("tagging %s" % r.data["title"])
Exemplo n.º 2
0
 def do_file(p, f):
     l = f.split("-")
     if len(l) >= 3:
         d = datetime(int(l[2]), int(l[0]), int(l[1]))
         now = datetime.today()
         if now - d > timedelta(days=120):
             util.lnp("Removing %s/%s" % (p, f))
             subprocess.Popen(["rm", f], cwd=p).wait()
Exemplo n.º 3
0
def fingerprint_stream():
    # I actually modified icecream so it takes seconds as an arg. Booya.
    now = datetime.today()
    util.lnp("Fingerprinting stream...")
    controls = {"file": now.strftime(settings.FILENAME), "runtime": "1min"}
    controls["filemp3"] = controls["file"] + ".mp3"
    od = "/tmp/"
    call = lambda x: Template(x).substitute(controls)
    cmd = map(call, settings.RIPPER_COMMAND)
    subprocess.Popen(cmd, cwd=od).wait()
    # Now we call the echoprint software...
    cmd = map(call, settings.ECHOPRINT_COMMAND)
    (stdout, stderr) = subprocess.Popen(cmd, cwd=od, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
    # Now, what we should see in stdout is some json with the current song:
    util.lnp(stdout)
    js = json.loads(stdout)
    util.lnp(json.dumps(js))
    subprocess.Popen(["rm", controls["filemp3"]], cwd=od)
    # data = urllib.urlencode({'query':json.dumps(js)})
    # Pack it up, and send it to the server
    url = Template(settings.ECHONEST_QUERYURL).substitute({"apikey": settings.ECHONEST_KEY, "code": js[0]["code"]})
    util.lnp(url)
    r = urllib2.urlopen(url)
    util.lnp(r.read())
Exemplo n.º 4
0
def main():
    p = None
    q = Queue()
    rt = []
    recordings = []
    fetch_task = None
    next_pull = None
    clean_task = None
    next_clean = None
    while 1:
        if clean_task == None and (next_clean == None or next_clean < datetime.today()):
            clean_task = tasks.clean.delay()
            next_clean = datetime.today() + timedelta(minutes=30)
            util.lnp("Next clean at %s" % str(next_clean))
    	elif clean_task != None:
            if clean_task.status == 'FAILURE':
                util.lnp("Cleaning Failed")
                clean_task = None
            elif clean_task.status == 'SUCCESS':
                util.lnp("Cleaning Worked!")
                clean_task = None
                 
        if fetch_task == None and (next_pull == None or next_pull < datetime.today()):
            fetch_task = tasks.fetch_recordings.delay()
            util.lnp("Fetching schedule")
        elif fetch_task != None:
            if fetch_task.status == 'FAILURE':
                util.lnp("Couldn't fetch schedule")
                fetch_task = None
            elif fetch_task.status == 'SUCCESS':
                recordings = fetch_task.result
                fetch_task = None
                next_pull = datetime.today() + timedelta(minutes=15)
                util.lnp("Next Update: %s" % next_pull)
                util.lnp("Loaded %s shows" % len(recordings))
		for r in recordings:
		    util.lnp("%s - %s" % (r.data['title'],r.next_recording()))
        
        for r in recordings:
            if r.ready() and r.id not in [ t[0] for t in rt ]:
                rt.append((r.id,tasks.record.delay(r)))
                util.lnp("Recording %s" % r.data['title'])
                time.sleep(60)

        if len(rt) > 0 and rt[0][1].ready():
            util.lnp("Cleaning up thread...");
            rt.pop(0)
            util.lnp("Done!")

        time.sleep(1) 
Exemplo n.º 5
0
def fetch_recordings():
    util.lnp("Fetching schedule..")
    return recording.load_from_web()