Exemplo n.º 1
0
def vote():

    vote_input = request.form["vote"]

    votes = vote_input.split(";")

    for vote in votes:

        params = urllib.urlencode({
            'q': vote.encode('utf-8'),
            'max-results': '1',
            'v': '2',
            'alt': 'jsonc'
        })

        url = "http://gdata.youtube.com/feeds/api/videos?%s" % params
        result = simplejson.load(urllib.urlopen(url))
        item = result['data']['items'][0]

        video_json = simplejson.dumps({
            "id": item['id'],
            "title": item['title']
        })

        radio_utils.append(
            radio_utils.get_path(RADIO_ROOT, 'to_process_votes'), video_json)

    return simplejson.dumps(current_status)
Exemplo n.º 2
0
def process_audio(vote_json_str):
    
    vote_json = simplejson.loads(vote_json_str)
    vote_id = vote_json['id']
    
    radio_utils.append(real_path('processing_votes'), vote_json_str)
    os.system(FFMPEG_LINE % (ICES_MODULE_ROOT, vote_id, MP3CACHE_ROOT, vote_id))
    
    audio = ID3("%s/%s.mp3" % (MP3CACHE_ROOT, vote_id))
    audio.add(TIT2(encoding=3, text=vote_json['title']))
    audio.save()
    
    vote_json_polled = radio_utils.poll(real_path('processing_votes'))
    
    if (vote_json_polled != vote_json_str) :
        print "There is a concurrency error."
    
    radio_utils.append(real_path('processed_votes'), 
                 os.path.join(MP3CACHE_ROOT, "%s.mp3" % vote_id))
Exemplo n.º 3
0
def perform_vote():
    # Quem sugeriu, o que sugeriu, quando sugeriu
    index = request.json["index"]
    item = session["current_results"]['data']['items'][int(index)]
    video_json = simplejson.dumps({
        "id": item['id'],
        "title": item['title'],
        "user": session["current_user"].rstrip()
    })
    last_requests = get_last_requests()
    if item['id'] in last_requests:
        return simplejson.dumps('{"error": "Already requested"}')
    with open('last_requests', 'a') as the_file:
        the_file.write('%s\n' % item['id'])
    radio_utils.append(radio_utils.get_path(RADIO_ROOT, 'to_process_votes'),
                       video_json)
    SUGGESTION_LOGGER.info("%s | %s" %
                           (session["current_user"], item['title'].rstrip()))
    return simplejson.dumps(current_status)
Exemplo n.º 4
0
def vote():
    
    vote_input = request.form["vote"]
    
    votes = vote_input.split(";")
    
    for vote in votes:
    
        params = urllib.urlencode({'q': vote.encode('utf-8'), 'max-results': '1', 'v': '2', 'alt': 'jsonc'})
        
        url = "http://gdata.youtube.com/feeds/api/videos?%s" % params
        result = simplejson.load(urllib.urlopen(url))
        item = result['data']['items'][0]
        
        video_json = simplejson.dumps({"id": item['id'], "title": item['title']})
        
        radio_utils.append(radio_utils.get_path(RADIO_ROOT, 'to_process_votes'), 
                           video_json)
    
    return simplejson.dumps(current_status)
Exemplo n.º 5
0
def process_audio(vote_json_str):
    LOGGER.info("Processamento!")
    vote_json = simplejson.loads(vote_json_str.split("|")[0])
    vote_id = vote_json['id']

    radio_utils.append(real_path('processing_votes'), vote_json_str)

    LOGGER.info("FFMPEG Conversion: %s" % (FFMPEG_LINE %
                                           (vote_id, MP3CACHE_ROOT, vote_id)))
    os.system(FFMPEG_LINE % (vote_id, MP3CACHE_ROOT, vote_id))

    audio = ID3("%s/%s.mp3" % (MP3CACHE_ROOT, vote_id))
    audio.add(TIT2(encoding=3, text=vote_json['title']))
    audio.save()

    vote_json_polled = radio_utils.poll(real_path('processing_votes'))

    if (vote_json_polled != vote_json_str):
        print "There is a concurrency error."

    LOGGER.info("End of Process for %s" % (vote_json['title']))
    radio_utils.append(real_path('processed_votes'),
                       os.path.join(MP3CACHE_ROOT, "%s.mp3" % vote_id))