def get_next(): file_path = radio_utils.poll(real_path('processed_votes')) lines_processed = radio_utils.lines(real_path('processed_votes')) lines_processing = radio_utils.lines(real_path('processing_votes')) to_process = PROCESSING_BUFFER_SIZE - lines_processed - lines_processing process(to_process) return file_path
def ices_get_next(): while (True) : pipe = open(ICES_PIPE, 'w') pipe.write('1') pipe.close() json_obj = radio_utils.poll(real_path('processed_votes')) LOGGER.info(json_obj) if json_obj: obj = jsonpickle.decode(json_obj) current_song = open("current_song", "w") current_song.write('{"song":"%s", "author":"%s"}' % (obj["title"].encode("UTF-8"),obj["user"].encode("UTF-8"))) current_song.close() return obj["path"] time.sleep(2)
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))
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))
#!/usr/bin/python # -*- coding: UTF-8 -*- import time import os import radio_utils import simplejson from radio_config import RADIO_ROOT, MP3CACHE_ROOT, ICES_MODULE_ROOT def real_path(path): return radio_utils.get_path(RADIO_ROOT, path) while True: print "Buscando arquivo para conversao" vote_json_str = radio_utils.poll(real_path('to_process_votes')) if vote_json_str: print 'python %s/conversion_script.py %s "%s" %s &' % (ICES_MODULE_ROOT, simplejson.loads(vote_json_str)["id"], simplejson.loads(vote_json_str)["title"].encode("UTF-8"),simplejson.loads(vote_json_str)["user"].encode("UTF-8")) os.system('python %s/conversion_script.py %s "%s" %s &' % (ICES_MODULE_ROOT, simplejson.loads(vote_json_str)["id"], simplejson.loads(vote_json_str)["title"].encode("UTF-8"),simplejson.loads(vote_json_str)["user"].encode("UTF-8"))) time.sleep(5)
def real_path(path): return radio_utils.get_path(RADIO_ROOT, path) 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)) if __name__ == "__main__": to_process = int(sys.argv[1]) for i in range(0, to_process) : vote_json_str = radio_utils.poll(real_path('to_process_votes')) if (vote_json_str) : process_audio(vote_json_str)