def check_and_work_on_files(roboting_sgs): """ - search audio files - if found, work on it """ lib_cm.message_write_to_console(ac, u"check_and_work_on_files") for item in roboting_sgs: lib_cm.message_write_to_console(ac, item[0].encode('ascii', 'ignore')) titel = item[0] # search shows sendungen = load_sg(titel) if sendungen is None: lib_cm.message_write_to_console(ac, "Keine Sendungen gefunden") continue for sendung in sendungen: db.write_log_to_db_a(ac, "Sendung fuer VP-Uebernahme gefunden: " + sendung[11].encode('ascii', 'ignore'), "t", "write_also_to_console") # path-file split with date-pattern if item[1].strip() == "T": d_pattern, l_path_title = date_pattern(item[2]) if item[3].strip() == "T": d_pattern, l_path_title = date_pattern(item[4]) if d_pattern is None: continue # concatenate path and filename success_file, path_file_source, path_file_dest = filepaths( d_pattern, l_path_title, item, sendung) if success_file is None: continue # check if file always in play-out file_in_play_out = check_file_dest_play_out(path_file_dest, sendung) if file_in_play_out is True: continue if item[1].strip() == "T": # check if file in dropbox file_in_cloud = check_file_source_cloud(path_file_source) if file_in_cloud is False: continue # In Play-Out kopieren success_copy = audio_copy(path_file_source, path_file_dest) if success_copy is None: continue if item[3].strip() == "T": # fetch file from ftp filename_ftp_temp = lib_cm.extract_filename(ac, path_file_source) file_from_ftp = (fetch_media_ftp( path_file_dest, path_file_source)) if file_from_ftp is None: continue copy_success = copy_media_to_play_out( filename_ftp_temp, path_file_dest) if copy_success is None: continue #audio_validate(path_file_dest) success_mp3validate = lib_au.validate_mp3( ac, db, lib_cm, path_file_dest) if success_mp3validate is None: db.write_log_to_db_a(ac, ac.app_errorslist[4], "x", "write_also_to_console") success_add_id3 = lib_au.add_id3( ac, db, lib_cm, sendung, path_file_dest) if success_add_id3 is None: db.write_log_to_db_a(ac, ac.app_errorslist[7], "x", "write_also_to_console") continue # mp3gain must proceed after id3-tag is written # python-rgain has an error if no id3-tag is present #audio_mp3gain(path_file_dest) #success_add_rgain = lib_au.add_replaygain( # ac, db, lib_cm, path_file_dest) #if success_add_rgain is None: # db.write_log_to_db_a(ac, ac.app_errorslist[3], # "x", "write_also_to_console") success_add_mp3gain = lib_au.add_mp3gain( ac, db, lib_cm, path_file_dest) if success_add_mp3gain is None: db.write_log_to_db_a(ac, ac.app_errorslist[3], "x", "write_also_to_console") reg_lenght(sendung, path_file_dest) # filename rechts von slash extrahieren if ac.app_windows == "no": filename = path_file_dest[string.rfind(path_file_dest, "/") + 1:] else: filename = path_file_dest[string.rfind(path_file_dest, "\\") + 1:] #db.write_log_to_db_a(ac, "VP bearbeitet: " + filename, "i", # "write_also_to_console") db.write_log_to_db_a(ac, "VP bearbeitet: " + filename, "n", "write_also_to_console")
def lets_rock(): """mainfunction """ print "lets_rock " # prepare path ac.app_homepath = "/home/" + socket.gethostname() sendung_data = load_sg() if sendung_data is None: return if db.ac_config_1[4] == "yes": # dropbox path_file_source, temp_orig_file = filepaths() copy_ok = copy_media_db(path_file_source, temp_orig_file) if copy_ok is None: return if db.ac_config_1[5] == "yes": # ftp temp_orig_file = ac.app_file_orig_temp + ".mp3" download_ok = fetch_media_ftp(temp_orig_file) if download_ok is None: return if db.ac_config_1[4] != "yes" and db.ac_config_1[5] != "yes": db.write_log_to_db_a(ac, ac.app_errorslist[10], "x", "write_also_to_console") return trim_ok = trim_silence(temp_orig_file) if trim_ok is None: collect_garbage(2) return compand_ok = compand_voice() if compand_ok is None: collect_garbage(2) return #source_file = lib_cm.extract_filename(ac, # db.ac_config_1[6]).replace("mp3", "wav") source_file = ac.app_file_orig_temp + ".wav" lenght_news = check_lenght(source_file) if lenght_news is None: return trim_bed_ok = trim_bed(lenght_news) if trim_bed_ok is None: collect_garbage(4) return mix_bed_ok = mix_bed() if mix_bed_ok is None: collect_garbage(4) return concatenate_ok = concatenate_media(sendung_data[0][12]) if concatenate_ok is None: collect_garbage(4) return #id3_ok = add_id3(sendung_data[0]) #if id3_ok is None: # return dest_path = lib_cm.check_slashes(ac, db.ac_config_servpath_a[1]) path_file = dest_path + sendung_data[0][12] success_add_id3 = lib_au.add_id3(ac, db, lib_cm, sendung_data[0], path_file) if success_add_id3 is None: db.write_log_to_db_a(ac, ac.app_errorslist[8], "x", "write_also_to_console") #dest_path = lib_cm.check_slashes(ac, db.ac_config_1[11]) dest_path = lib_cm.check_slashes(ac, db.ac_config_servpath_a[1]) source_file = dest_path + sendung_data[0][12] lenght_news = check_lenght(source_file) if lenght_news is None: return # Laenge eintragen sql_command = ("UPDATE SG_HF_MAIN " + "SET SG_HF_DURATION='" + lenght_news[0:8] + "' " + "WHERE SG_HF_ID='" + str(sendung_data[0][0]) + "'") db_ok = db.exec_sql(ac, db, sql_command) if db_ok is None: db.write_log_to_db_a(ac, ac.app_errorslist[9], "x", "write_also_to_console") else: log_message = u"Laenge der externen News in Buchung aktualisiert... " db.write_log_to_db_a(ac, log_message, "k", "write_also_to_console") collect_garbage(5)
def lets_rock(): """Mainfunction """ print "lets_rock " # extendet params load_extended_params_ok = load_extended_params() if load_extended_params_ok is None: return # load from db podcast_sendungen = load_podcast() if podcast_sendungen is None: db.write_log_to_db_a(ac, u"Zur Zeit kein neuer Podcast vorgesehen", "k", "write_also_to_console") return # check whats not online podcast_offline = check_files_online(podcast_sendungen) if podcast_offline is None: # Error 1 return if podcast_offline == "No files offline": db.write_log_to_db_a(ac, u"Alle Podcasts bereits online", "k", "write_also_to_console") return # take one item from offlines podcast_sendung = () for item in podcast_sendungen: if item[12] == podcast_offline: # take all values for id3 # insert one item to shift author in the tuple podcast_sendung_all = item[:14] + (" ",) + item[14:] # filename, titel, vorname, name, infotime, magazin podcast_sendung = (item[12], item[11], item[14], item[15], item[4].strip(), item[5].strip()) lib_cm.message_write_to_console(ac, podcast_sendung) podcast_sendung_temp = podcast_sendung # recode podcast_temp = encode_file(podcast_sendung) if podcast_temp is None: # try with next file # take one item from offlines podcast_sendung = () for item in podcast_sendungen: if item[12] == podcast_offline: # take all values for id3 # insert one item to shift author in the tuple podcast_sendung_all = item[:14] + (" ",) + item[14:] # nicht das vorige file nochmal print "podcast_sendung" print podcast_sendung if item[12] != podcast_sendung_temp[0]: # filename, titel, vorname, name, infotime, magazin podcast_sendung = (item[12], item[11], item[14], item[15], item[4].strip(), item[5].strip()) lib_cm.message_write_to_console(ac, podcast_sendung) if len(podcast_sendung) == 0: # nothing else to do return # recode nr 2. with next file podcast_temp_1 = encode_file(podcast_sendung) if podcast_temp_1 is None: # Error 2 db.write_log_to_db_a(ac, ac.app_errorslist[2], "x", "write_also_to_console") return # tagging file in utf-8 if db.ac_config_1[3] == "on": #tag_file_id3(podcast_sendung) path_source = lib_cm.check_slashes(ac, db.ac_config_1[10]) file_dest = path_source + podcast_sendung[0] success_add_id3 = lib_au.add_id3( ac, db, lib_cm, podcast_sendung_all, file_dest) if success_add_id3 is None: db.write_log_to_db_a(ac, ac.app_errorslist[3], "x", "write_also_to_console") # upload whats not online upload_ok = upload_file(podcast_sendung) if upload_ok is None: # Error 1 db.write_log_to_db_a(ac, ac.app_errorslist[1], "x", "write_also_to_console") return # delete temp_file from encode delete_temp_ok = lib_cm.erase_file_a(ac, db, podcast_temp, u"Temp-Podcast-Datei geloescht ") if delete_temp_ok is None: # Error 4 db.write_log_to_db_a(ac, ac.app_errorslist[4], "x", "write_also_to_console") # delete old online-files # switch protocol if db.ac_config_1[4] == "FTP": delete_ok = delete_files_online_ftp() if db.ac_config_1[4] == "SFTP": delete_ok = delete_files_online_sftp() if delete_ok is None: # Error 1 db.write_log_to_db_a(ac, ac.app_errorslist[1], "x", "write_also_to_console")
"write_also_to_console") log_message = u"copy_files_to_dir_retry Error: %s" % str(e) lib_cm.message_write_to_console(ac, log_message) db.write_log_to_db(ac, log_message, "x") return # audio-fx #audio_validate(file_dest) success_mp3validate = lib_au.validate_mp3( ac, db, lib_cm, file_dest) if success_mp3validate is None: db.write_log_to_db_a(ac, ac.app_errorslist[2], "x", "write_also_to_console") success_add_id3 = lib_au.add_id3( ac, db, lib_cm, repeat_sendung, file_dest) if success_add_id3 is None: db.write_log_to_db_a(ac, ac.app_errorslist[5], "x", "write_also_to_console") #audio_mp3gain(file_dest) #audio_id3tag(file_dest, #lib_cm.replace_uchar_sonderzeichen_with_latein(repeat_sendung[16]), #lib_cm.replace_uchar_sonderzeichen_with_latein(repeat_sendung[13])) success_add_mp3gain = lib_au.add_mp3gain(ac, db, lib_cm, file_dest) if success_add_mp3gain is None: db.write_log_to_db_a(ac, ac.app_errorslist[3], "x", "write_also_to_console")
if string.rfind(item, ".mp3") == -1: # no mp3: continue z += 1 path_file_source = path_source + item # extract filename right from slash #if ac.app_windows == "no": # filename = path_file_dest[string.rfind(path_file_dest, "/") + 1:] #else: # filename = path_file_dest[string.rfind(path_file_dest, "\\") + 1:] # first add id2, while replaygain has an error if no id3 tag is present sendung_data = ['0', '0', '0', '0', 'F', 'F', 'F', 'F', '0', '0', '0', 'Aktuell', item, 'Keywords', '0', 'Das', 'Radio'] success_add_id3 = lib_au.add_id3( ac, db, lib_cm, sendung_data, path_file_source) if success_add_id3 is None: db.write_log_to_db_a(ac, ac.app_errorslist[3], "x", "write_also_to_console") continue c_source_file = path_file_source.encode(ac.app_encode_out_strings) success_add_mp3gain = lib_au.add_mp3gain( ac, db, lib_cm, c_source_file) if success_add_mp3gain is None: db.write_log_to_db_a(ac, ac.app_errorslist[1], "x", "write_also_to_console") continue #c_source_file = path_file_source.encode(ac.app_encode_out_strings)
db.write_log_to_db_a(ac, ac.app_errorslist[1], "x", "write_also_to_console") log_message = u"copy_files_to_dir_retry Error: %s" % str(e) lib_cm.message_write_to_console(ac, log_message) db.write_log_to_db(ac, log_message, "x") return # audio-fx #audio_validate(file_dest) success_mp3validate = lib_au.validate_mp3(ac, db, lib_cm, file_dest) if success_mp3validate is None: db.write_log_to_db_a(ac, ac.app_errorslist[2], "x", "write_also_to_console") success_add_id3 = lib_au.add_id3(ac, db, lib_cm, repeat_sendung, file_dest) if success_add_id3 is None: db.write_log_to_db_a(ac, ac.app_errorslist[5], "x", "write_also_to_console") #audio_mp3gain(file_dest) #audio_id3tag(file_dest, #lib_cm.replace_uchar_sonderzeichen_with_latein(repeat_sendung[16]), #lib_cm.replace_uchar_sonderzeichen_with_latein(repeat_sendung[13])) success_add_mp3gain = lib_au.add_mp3gain(ac, db, lib_cm, file_dest) if success_add_mp3gain is None: db.write_log_to_db_a(ac, ac.app_errorslist[3], "x", "write_also_to_console")
def check_and_work_on_files(roboting_sgs): """ - search audio files - if found, work on it """ lib_cm.message_write_to_console(ac, u"check_and_work_on_files") for item in roboting_sgs: lib_cm.message_write_to_console(ac, item[0].encode("ascii", "ignore")) titel = item[0] # search shows sendungen = load_sg(titel) if sendungen is None: lib_cm.message_write_to_console(ac, "Keine Sendungen gefunden") continue for sendung in sendungen: db.write_log_to_db_a( ac, "Sendung fuer VP-Uebernahme gefunden: " + sendung[11].encode("ascii", "ignore"), "t", "write_also_to_console", ) # path-file split with date-pattern if item[1].strip() == "T": d_pattern, l_path_title = date_pattern(item[2]) if item[3].strip() == "T": d_pattern, l_path_title = date_pattern(item[4]) if d_pattern is None: continue # concatenate path and filename success_file, path_file_source, path_file_dest = filepaths(d_pattern, l_path_title, item, sendung) if success_file is None: continue # check if file always in play-out file_in_play_out = check_file_dest_play_out(path_file_dest, sendung) if file_in_play_out is True: continue if item[1].strip() == "T": # check if file in dropbox file_in_cloud = check_file_source_cloud(path_file_source) if file_in_cloud is False: continue # In Play-Out kopieren success_copy = audio_copy(path_file_source, path_file_dest) if success_copy is None: continue if item[3].strip() == "T": # fetch file from ftp filename_ftp_temp = lib_cm.extract_filename(ac, path_file_source) file_from_ftp = fetch_media_ftp(path_file_dest, path_file_source) if file_from_ftp is None: continue copy_success = copy_media_to_play_out(filename_ftp_temp, path_file_dest) if copy_success is None: continue # audio_validate(path_file_dest) success_mp3validate = lib_au.validate_mp3(ac, db, lib_cm, path_file_dest) if success_mp3validate is None: db.write_log_to_db_a(ac, ac.app_errorslist[4], "x", "write_also_to_console") success_add_id3 = lib_au.add_id3(ac, db, lib_cm, sendung, path_file_dest) if success_add_id3 is None: db.write_log_to_db_a(ac, ac.app_errorslist[7], "x", "write_also_to_console") continue # mp3gain must proceed after id3-tag is written # python-rgain has an error if no id3-tag is present # audio_mp3gain(path_file_dest) # success_add_rgain = lib_au.add_replaygain( # ac, db, lib_cm, path_file_dest) # if success_add_rgain is None: # db.write_log_to_db_a(ac, ac.app_errorslist[3], # "x", "write_also_to_console") success_add_mp3gain = lib_au.add_mp3gain(ac, db, lib_cm, path_file_dest) if success_add_mp3gain is None: db.write_log_to_db_a(ac, ac.app_errorslist[3], "x", "write_also_to_console") reg_lenght(sendung, path_file_dest) # filename rechts von slash extrahieren if ac.app_windows == "no": filename = path_file_dest[string.rfind(path_file_dest, "/") + 1 :] else: filename = path_file_dest[string.rfind(path_file_dest, "\\") + 1 :] # db.write_log_to_db_a(ac, "VP bearbeitet: " + filename, "i", # "write_also_to_console") db.write_log_to_db_a(ac, "VP bearbeitet: " + filename, "n", "write_also_to_console")