def erase_files_from_play_out_prepare(sendung_art): """Dateien in Play-Out loeschen, Vorbereitung""" lib_cm.message_write_to_console(ac, u"erase_files_from_play_out_prepare") # Pfade if sendung_art == "Info-Time": path_sendung_source = db.ac_config_servpath_a[5] path_sendung_dest = db.ac_config_servpath_a[9] log_message = u"Infotime und Magazin in Play_Out loeschen..." if sendung_art == "Sendung normal": path_sendung_source = db.ac_config_servpath_a[6] path_sendung_dest = db.ac_config_servpath_a[10] log_message = u"Sendungen in Play_Out loeschen..." db.write_log_to_db(ac, log_message, "p") # pfad anpassen path_sendung_source = lib_cm.check_slashes(ac, path_sendung_source) path_sendung_dest = lib_cm.check_slashes(ac, path_sendung_dest) lib_cm.message_write_to_console(ac, path_sendung_source) lib_cm.message_write_to_console(ac, path_sendung_dest) # source: files in list try: files_sendung_source = os.listdir(path_sendung_source) except Exception, e: log_message = u"read_files_from_dir Error: %s" % str(e) lib_cm.message_write_to_console(ac, log_message) db.write_log_to_db(ac, log_message, "x") return None
def filepaths(sendung, base_path_source): """concatenate path and filenames""" success_file = True try: path_source = lib_cm.check_slashes(ac, base_path_source) path_file_source = (path_source + sendung[12]) # filename filename_dest = (sendung[2].strftime('%Y_%m_%d') + "_" + db.ac_config_1[4] + str(sendung[12][7:])) # Cloud path_dest_base = lib_cm.check_slashes(ac, db.ac_config_servpath_b[5]) path_cloud = (path_dest_base + lib_cm.check_slashes(ac, db.ac_config_1[5])) path_file_cloud = (path_cloud + filename_dest) # ftp path_ftp = lib_cm.check_slashes(ac, db.ac_config_1[6]) except Exception, e: log_message = (ac.app_errorslist[3] + "fuer: " + sendung[11].encode('ascii', 'ignore') + " " + str(e)) db.write_log_to_db_a(ac, log_message, "x", "write_also_to_console") success_file = None
def erase_files_prepaere(roboting_sgs): """prepaere erasing files""" date_back = (datetime.datetime.now() + datetime.timedelta(days=- int(db.ac_config_1[3]))) c_date_back = date_back.strftime("%Y_%m_%d") db.write_log_to_db_a(ac, u"Sendedatum muss aelter sein als: " + c_date_back, "t", "write_also_to_console") for item in roboting_sgs: if item[1].strip() == "T": # on Cloud msg = "Veraltete Dateien in Cloud loeschen: " + item[2] db.write_log_to_db_a(ac, msg, "p", "write_also_to_console") path_dest = lib_cm.check_slashes(ac, db.ac_config_servpath_b[5]) path_cloud = lib_cm.check_slashes(ac, item[2]) path_dest_cloud = (path_dest + path_cloud) try: files_sendung_dest = os.listdir(path_dest_cloud) except Exception, e: log_message = ac.app_errorslist[12] + item[2] + ": %s" % str(e) lib_cm.message_write_to_console(ac, log_message) db.write_log_to_db(ac, log_message, "x") return erase_files_from_cloud(path_dest_cloud, files_sendung_dest, c_date_back) if item[3].strip() == "T": # on ftp msg = "Veraltete Dateien auf ftp loeschen: " + item[4] db.write_log_to_db_a(ac, msg, "p", "write_also_to_console") path_dest = lib_cm.check_slashes(ac, db.ac_config_1[6]) path_ftp = lib_cm.check_slashes(ac, item[4]) path_dest_ftp = (path_dest + path_ftp) erase_files_from_ftp(path_dest_ftp, c_date_back)
def check_files_in_protokoll_completely(n_days_back): """ copy files, they in prev loops not had been copied """ lib_cm.message_write_to_console(ac, u"check_files_in_protokoll_completely") # Days back date_proto = (datetime.datetime.now() + datetime.timedelta(days=- n_days_back)) log_message = (u"Vollstaendigkeit der Protokolle pruefen fuer: " + str(date_proto)) lib_cm.message_write_to_console(ac, log_message) db.write_log_to_db(ac, log_message, "t") path_sendung_source = lib_cm.check_slashes(ac, db.ac_config_servpath_b[1]) path_sendung_dest = lib_cm.check_slashes(ac, db.ac_config_servpath_b[2]) path_sendung_dest += date_proto.strftime("%Y_%m_%d") path_sendung_dest = lib_cm.check_slashes(ac, path_sendung_dest) lib_cm.message_write_to_console(ac, path_sendung_source) lib_cm.message_write_to_console(ac, path_sendung_dest) # files from temp in list try: files_sendung_source = os.listdir(path_sendung_source) except Exception, e: log_message = u"read_files_from_dir Error: %s" % str(e) lib_cm.message_write_to_console(ac, log_message) db.write_log_to_db(ac, log_message, "x") return None
def concatenate_media(filename): """concatenate audio files""" lib_cm.message_write_to_console(ac, u"mp3-Files kombinieren") # use the right char-encoding for supprocesses cmd = db.ac_config_etools[2].encode(ac.app_encode_out_strings) #cmd = "sox" #news_file = lib_cm.extract_filename(ac, # db.ac_config_1[6]).replace("mp3", "wav") news_file = ac.app_file_orig_temp + ".wav" news_file_temp = news_file.replace(".wav", "_temp.wav") #source_path = lib_cm.check_slashes(ac, db.ac_config_1[10]) source_path = ac.app_homepath + lib_cm.check_slashes( ac, db.ac_config_1[10]) #source_file_intro = source_path + "News_ext_Automation_Intro.wav" source_file_intro = source_path + ac.app_file_intro #source_file_closer = source_path + "News_ext_Automation_Closer.wav" source_file_closer = source_path + ac.app_file_closer #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]) dest_path_file = dest_path + filename lib_cm.message_write_to_console(ac, cmd) # start subprocess try: p = subprocess.Popen([ cmd, u"-S", source_file_intro, news_file_temp, source_file_closer, u"-C" u"192.2", dest_path_file ], stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate() except Exception, e: log_message = ac.app_errorslist[7] + u": %s" % str(e) db.write_log_to_db_a(ac, log_message, "x", "write_also_to_console") return None
def write_files_to_archive_prepare(sendung_art): """prepaering for archiving""" lib_cm.message_write_to_console(ac, u"write_files_to_archive_prepare") # paths if sendung_art == "Info-Time": path_sendung_source = db.ac_config_servpath_a[5] path_sendung_dest = db.ac_config_servpath_a[9] log_message = u"Infotime und Magazin archivieren..." if sendung_art == "Sendung normal": path_sendung_source = db.ac_config_servpath_a[6] path_sendung_dest = db.ac_config_servpath_a[10] log_message = u"Sendungen archivieren..." db.write_log_to_db(ac, log_message, "p") # check slashes path_sendung_source = lib_cm.check_slashes(ac, path_sendung_source) path_sendung_dest = lib_cm.check_slashes(ac, path_sendung_dest) lib_cm.message_write_to_console(ac, path_sendung_source) lib_cm.message_write_to_console(ac, path_sendung_dest) # read archive folders try: files_sendung_source = os.listdir(path_sendung_source) except Exception, e: log_message = u"read_files_from_dir Error: %s" % str(e) lib_cm.message_write_to_console(ac, log_message + path_sendung_source) db.write_log_to_db(ac, log_message, "x") return None
def concatenate_media(filename): """concatenate audio files""" lib_cm.message_write_to_console(ac, u"mp3-Files kombinieren") # use the right char-encoding for supprocesses cmd = db.ac_config_etools[2].encode(ac.app_encode_out_strings) #cmd = "sox" #news_file = lib_cm.extract_filename(ac, # db.ac_config_1[6]).replace("mp3", "wav") news_file = ac.app_file_orig_temp + ".wav" news_file_temp = news_file.replace(".wav", "_temp.wav") #source_path = lib_cm.check_slashes(ac, db.ac_config_1[10]) source_path = ac.app_homepath + lib_cm.check_slashes(ac, db.ac_config_1[10]) #source_file_intro = source_path + "News_ext_Automation_Intro.wav" source_file_intro = source_path + ac.app_file_intro #source_file_closer = source_path + "News_ext_Automation_Closer.wav" source_file_closer = source_path + ac.app_file_closer #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]) dest_path_file = dest_path + filename lib_cm.message_write_to_console(ac, cmd) # start subprocess try: p = subprocess.Popen([cmd, u"-S", source_file_intro, news_file_temp, source_file_closer, u"-C" u"192.2", dest_path_file], stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate() except Exception, e: log_message = ac.app_errorslist[7] + u": %s" % str(e) db.write_log_to_db_a(ac, log_message, "x", "write_also_to_console") return None
def write_files_to_protokoll(): """copy files in Protokoll-Archive""" lib_cm.message_write_to_console(ac, u"write_files_to_protokoll") # one hour back date_proto = datetime.datetime.now() + datetime.timedelta(hours=- 1) # Path slashes path_sendung_source = lib_cm.check_slashes(ac, db.ac_config_servpath_b[1]) path_sendung_dest = lib_cm.check_slashes(ac, db.ac_config_servpath_b[2]) path_sendung_dest += date_proto.strftime("%Y_%m_%d") path_sendung_dest = lib_cm.check_slashes(ac, path_sendung_dest) lib_cm.message_write_to_console(ac, path_sendung_source) lib_cm.message_write_to_console(ac, path_sendung_dest) if db.ac_config_1[2] == "WaveRecorder": file_source = (db.ac_config_1[5] + "_" + date_proto.strftime("%Y-%m-%d") + "_" + date_proto.strftime("%H.00.01") + "." + db.ac_config_1[6]) file_dest = (db.ac_config_1[5] + "_" + date_proto.strftime("%Y_%m_%d") + "_" + date_proto.strftime("%H.00.01") + "." + db.ac_config_1[6]) if db.ac_config_1[2] == "rotter": file_source = (db.ac_config_1[5] + "-" + date_proto.strftime("%Y-%m-%d") + "-" + date_proto.strftime("%H") + "." + db.ac_config_1[6]) file_dest = (db.ac_config_1[5] + "_" + date_proto.strftime("%Y_%m_%d") + "_" + date_proto.strftime("%H") + "." + db.ac_config_1[6]) lib_cm.message_write_to_console(ac, file_source) lib_cm.message_write_to_console(ac, file_dest) path_file_source = path_sendung_source + file_source path_file_destination = path_sendung_dest + file_dest lib_cm.message_write_to_console(ac, path_file_source) lib_cm.message_write_to_console(ac, path_file_destination) lib_cm.message_write_to_console(ac, u"kopieren: " + file_dest) try: if not os.path.exists(path_sendung_dest): log_message = u"anlegen Verzeichnis: " + path_sendung_dest lib_cm.message_write_to_console(ac, log_message) db.write_log_to_db(ac, log_message, "k") os.mkdir(path_sendung_dest) shutil.copy(path_file_source, path_file_destination) log_message = u"kopiert Protokoll: " + file_source db.write_log_to_db(ac, log_message, "k") except Exception, e: log_message = u"copy_files_to_dir Error: %s" % str(e) lib_cm.message_write_to_console(ac, log_message) db.write_log_to_db(ac, log_message, "x") return None
def filepaths(d_pattern, l_path_title, item, sendung): """concatenate paths and filenames""" success_file = True try: # Verschiebung von Datum Erstsendung new_date = sendung[2] + datetime.timedelta(days=-item[5]) lib_cm.message_write_to_console(ac, new_date.strftime(d_pattern)) if item[1].strip() == "T": # from dropbox path_source = lib_cm.check_slashes(ac, db.ac_config_servpath_b[5]) path_file_source = ( path_source + l_path_title[0] # + sendung[0][2].strftime('%Y_%m_%d') + l_path_title[1].rstrip()) + new_date.strftime(d_pattern) + l_path_title[1].rstrip() ) if item[3].strip() == "T": # from ftp # url_base = db.ac_config_1[3].encode(ac.app_encode_out_strings) # url_source_file = db.ac_config_1[7].encode(ac.app_encode_out_strings) path_source = lib_cm.check_slashes(ac, db.ac_config_1[3]) path_file_source = ( path_source + l_path_title[0] # + sendung[0][2].strftime('%Y_%m_%d') + l_path_title[1].rstrip()) + new_date.strftime(d_pattern) + l_path_title[1].rstrip() ) # it or mag else sendung if sendung[4].strip() == "T" or sendung[5].strip() == "T": path_dest = lib_cm.check_slashes(ac, db.ac_config_servpath_a[1]) else: path_dest = lib_cm.check_slashes(ac, db.ac_config_servpath_a[2]) # replace special char # replace_uchar_sonderzeichen_with_latein path_file_dest = ( path_dest + str(sendung[8]) + "_" + lib_cm.replace_sonderzeichen_with_latein(sendung[16]) + "_" + lib_cm.replace_sonderzeichen_with_latein(sendung[13]) # + lib_cm.replace_uchar_sonderzeichen_with_latein(sendung[0][13]) + ".mp3" ) except Exception, e: log_message = ac.app_errorslist[5] + "fuer: " + sendung[11].encode("ascii", "ignore") + " " + str(e) db.write_log_to_db_a(ac, log_message, "x", "write_also_to_console") success_file = None
def upload_file(podcast_sendung): """upload files""" lib_cm.message_write_to_console(ac, u"upload_file") # dest recoded file path_source = lib_cm.check_slashes(ac, db.ac_config_1[10]) c_source_file = path_source + podcast_sendung[0] lib_cm.message_write_to_console(ac, c_source_file) if not os.path.isfile(c_source_file): db.write_log_to_db_a(ac, ac.app_errorslist[3] + c_source_file, "x", "write_also_to_console") return None log_message = u"upload_file: " + c_source_file db.write_log_to_db(ac, log_message, "k") # switch protocol if db.ac_config_1[4] == "FTP": if ac.app_windows == "yes": f = open(c_source_file, "rb") else: f = open(c_source_file, "r") ftp = ftp_connect_and_dir() if ftp is None: return None c_ftp_cmd = "STOR " + podcast_sendung[0] ftp.storbinary(c_ftp_cmd, f) ftp.quit() f.close() if db.ac_config_1[4] == "SFTP": sftp, transport = sftp_connect() if sftp is None: return None path_remote = lib_cm.check_slashes(ac, db.ac_config_1[9]) file_remote = path_remote + podcast_sendung[0] # upload try: sftp.put(c_source_file, file_remote) db.write_log_to_db_a(ac, u"Podcast hochgeladen: " + podcast_sendung[0], "i", "write_also_to_console") except Exception as e: lib_cm.message_write_to_console(ac, e) db.write_log_to_db_a(ac, ac.app_errorslist[10], "x", "write_also_to_console") # Close sftp.close() transport.close() return "OK"
def write_files_to_archive(files_sendung_source, path_sendung_source, path_sendung_dest, dir_year, sendung_art): """write files to archive""" lib_cm.message_write_to_console(ac, u"write_files_to_archive " + dir_year) # Times lib_cm.message_write_to_console(ac, db.ac_config_1[2]) date_back = (datetime.datetime.now() + datetime.timedelta(days=-int(db.ac_config_1[2]))) lib_cm.message_write_to_console(ac, db.ac_config_1[4]) nr_of_files_to_archive = int(db.ac_config_1[4]) c_date_back = date_back.strftime("%Y-%m-%d") db.write_log_to_db_a(ac, u"Sendedatum muss vor " + c_date_back + " liegen", "t", "write_also_to_console") # pfad anpassen path_sendung_dest += lib_cm.check_slashes(ac, dir_year) log_message = u"Dateien archivieren nach: " + path_sendung_dest db.write_log_to_db(ac, log_message, "f") try: files_sendung_dest = os.listdir(path_sendung_dest) except Exception, e: log_message = u"read_files_from_dir Error: %s" % str(e) lib_cm.message_write_to_console(ac, log_message) db.write_log_to_db(ac, log_message, "x") return
def erase_files_from_play_out(files_sendung_source, path_sendung_source, path_sendung_dest, dir_year, sendung_art): """Dateien in Play-Out loeschen, Durchfuehrung""" lib_cm.message_write_to_console(ac, u"erase_files_from_play_out") # Times lib_cm.message_write_to_console(ac, db.ac_config_1[3]) date_back = (datetime.datetime.now() + datetime.timedelta(days=- int(db.ac_config_1[3]))) #date_back = datetime.datetime.now() + datetime.timedelta( days=-100 ) lib_cm.message_write_to_console(ac, db.ac_config_1[4]) nr_of_files_to_archive = int(db.ac_config_1[4]) # pfad anpassen path_sendung_dest += lib_cm.check_slashes(ac, dir_year) log_message = (u"Dateien von " + dir_year + u" loeschen aus: " + path_sendung_source) db.write_log_to_db(ac, log_message, "v") c_date_back = date_back.strftime("%Y-%m-%d") db.write_log_to_db_a(ac, u"Sendedatum muss vor " + c_date_back + " liegen", "t", "write_also_to_console") try: files_sendung_dest = os.listdir(path_sendung_dest) except Exception, e: log_message = u"read_files_from_dir Error: %s" % str(e) lib_cm.message_write_to_console(ac, log_message) db.write_log_to_db(ac, log_message, "x") return
def erase_files_from_play_out_old_year(files_sendung_source, path_sendung_source, path_sendung_dest, dir_year, sendung_art): """Dateien vorangegangener Jahre in Play-Out loeschen, Durchfuehrung""" lib_cm.message_write_to_console(ac, u"erase_files_from_play_out_old_year") # Zeiten lib_cm.message_write_to_console(ac, db.ac_config_1[3]) days_back = int(db.ac_config_1[3]) date_back = (datetime.datetime.now() + datetime.timedelta(days=- days_back)) #lib_cm.message_write_to_console(ac, db.ac_config_1[4]) nr_of_files_to_archive = int(db.ac_config_1[4]) # pfad anpassen path_sendung_dest += lib_cm.check_slashes(ac, dir_year) log_message = ("Dateien von " + dir_year + " loeschen, die in Folgejahren erneut gesendet wurden: " + path_sendung_source) db.write_log_to_db(ac, log_message, "v") c_date_back = date_back.strftime("%Y-%m-%d") db.write_log_to_db_a(ac, u"Wiederholungs-Sendedatum muss vor " + c_date_back + " liegen", "t", "write_also_to_console") try: files_sendung_dest = os.listdir(path_sendung_dest) except Exception, e: log_message = u"read_files_from_dir Error: %s" % str(e) lib_cm.message_write_to_console(ac, log_message) db.write_log_to_db(ac, log_message, "x") return
def erase_files_from_play_out(files_sendung_source, path_sendung_source, path_sendung_dest, dir_year, sendung_art): """Dateien in Play-Out loeschen, Durchfuehrung""" lib_cm.message_write_to_console(ac, u"erase_files_from_play_out") # Times lib_cm.message_write_to_console(ac, db.ac_config_1[3]) date_back = (datetime.datetime.now() + datetime.timedelta(days=-int(db.ac_config_1[3]))) #date_back = datetime.datetime.now() + datetime.timedelta( days=-100 ) lib_cm.message_write_to_console(ac, db.ac_config_1[4]) nr_of_files_to_archive = int(db.ac_config_1[4]) # pfad anpassen path_sendung_dest += lib_cm.check_slashes(ac, dir_year) log_message = (u"Dateien von " + dir_year + u" loeschen aus: " + path_sendung_source) db.write_log_to_db(ac, log_message, "v") c_date_back = date_back.strftime("%Y-%m-%d") db.write_log_to_db_a(ac, u"Sendedatum muss vor " + c_date_back + " liegen", "t", "write_also_to_console") try: files_sendung_dest = os.listdir(path_sendung_dest) except Exception, e: log_message = u"read_files_from_dir Error: %s" % str(e) lib_cm.message_write_to_console(ac, log_message) db.write_log_to_db(ac, log_message, "x") return
def write_files_to_archive(files_sendung_source, path_sendung_source, path_sendung_dest, dir_year, sendung_art): """write files to archive""" lib_cm.message_write_to_console(ac, u"write_files_to_archive " + dir_year) # Times lib_cm.message_write_to_console(ac, db.ac_config_1[2]) date_back = (datetime.datetime.now() + datetime.timedelta(days=- int(db.ac_config_1[2]))) lib_cm.message_write_to_console(ac, db.ac_config_1[4]) nr_of_files_to_archive = int(db.ac_config_1[4]) c_date_back = date_back.strftime("%Y-%m-%d") db.write_log_to_db_a(ac, u"Sendedatum muss vor " + c_date_back + " liegen", "t", "write_also_to_console") # pfad anpassen path_sendung_dest += lib_cm.check_slashes(ac, dir_year) log_message = u"Dateien archivieren nach: " + path_sendung_dest db.write_log_to_db(ac, log_message, "f") try: files_sendung_dest = os.listdir(path_sendung_dest) except Exception, e: log_message = u"read_files_from_dir Error: %s" % str(e) lib_cm.message_write_to_console(ac, log_message) db.write_log_to_db(ac, log_message, "x") return
def lets_rock(): """main funktion """ print "lets_rock " # load file list from ftp path_ftp = lib_cm.check_slashes(ac, db.ac_config_1[5]) files_online = load_files_ftp(path_ftp) if files_online is None: return # load old file list from db time_back = (datetime.datetime.now() + datetime.timedelta(seconds=- 3660)) #+ datetime.timedelta(seconds=- 600)) c_time_back = time_back.strftime("%Y-%m-%d %H:%M:%S") c_time_now = ac.time_target.strftime("%Y-%m-%d %H:%M:%S") filelist_db = load_filelist_from_log(c_time_back, c_time_now) if filelist_db is None: # write current list in db write_filelist_to_db(files_online) return db.write_log_to_db(ac, ac.app_desc + " Vergleich mit db-list der verg. Stunde..", "t") check_filelist(filelist_db, files_online) # write current list in db write_filelist_to_db(files_online) # delete old logs if datetime.datetime.now().hour == 0: delete_exchange_log_in_db_log()
def lets_rock(): """main funktion """ print "lets_rock " # load file list from ftp path_ftp = lib_cm.check_slashes(ac, db.ac_config_1[5]) files_online = load_files_ftp(path_ftp) if files_online is None: return # load old file list from db time_back = (datetime.datetime.now() + datetime.timedelta(seconds=-3660)) #+ datetime.timedelta(seconds=- 600)) c_time_back = time_back.strftime("%Y-%m-%d %H:%M:%S") c_time_now = ac.time_target.strftime("%Y-%m-%d %H:%M:%S") filelist_db = load_filelist_from_log(c_time_back, c_time_now) if filelist_db is None: # write current list in db write_filelist_to_db(files_online) return db.write_log_to_db( ac, ac.app_desc + " Vergleich mit db-list der verg. Stunde..", "t") check_filelist(filelist_db, files_online) # write current list in db write_filelist_to_db(files_online) # delete old logs if datetime.datetime.now().hour == 0: delete_exchange_log_in_db_log()
def erase_files_from_play_out_old_year(files_sendung_source, path_sendung_source, path_sendung_dest, dir_year, sendung_art): """Dateien vorangegangener Jahre in Play-Out loeschen, Durchfuehrung""" lib_cm.message_write_to_console(ac, u"erase_files_from_play_out_old_year") # Zeiten lib_cm.message_write_to_console(ac, db.ac_config_1[3]) days_back = int(db.ac_config_1[3]) date_back = (datetime.datetime.now() + datetime.timedelta(days=-days_back)) #lib_cm.message_write_to_console(ac, db.ac_config_1[4]) nr_of_files_to_archive = int(db.ac_config_1[4]) # pfad anpassen path_sendung_dest += lib_cm.check_slashes(ac, dir_year) log_message = ("Dateien von " + dir_year + " loeschen, die in Folgejahren erneut gesendet wurden: " + path_sendung_source) db.write_log_to_db(ac, log_message, "v") c_date_back = date_back.strftime("%Y-%m-%d") db.write_log_to_db_a( ac, u"Wiederholungs-Sendedatum muss vor " + c_date_back + " liegen", "t", "write_also_to_console") try: files_sendung_dest = os.listdir(path_sendung_dest) except Exception, e: log_message = u"read_files_from_dir Error: %s" % str(e) lib_cm.message_write_to_console(ac, log_message) db.write_log_to_db(ac, log_message, "x") return
def erase_files_from_cloud(c_date_back): """erase files from cloud""" db.write_log_to_db_a(ac, u"Veraltete Dateien in Cloud loeschen", "p", "write_also_to_console") # Paths path_sendung_dest_base = lib_cm.check_slashes(ac, db.ac_config_servpath_b[5]) path_sendung_dest = (path_sendung_dest_base + lib_cm.check_slashes(ac, db.ac_config_1[5])) lib_cm.message_write_to_console(ac, path_sendung_dest) try: files_sendung_dest = os.listdir(path_sendung_dest) except Exception, e: log_message = ac.app_errorslist[3] + u": %s" % str(e) lib_cm.message_write_to_console(ac, log_message) db.write_log_to_db(ac, log_message, "x") return
def filepaths(d_pattern, l_path_title, item, sendung): """concatenate paths and filenames""" success_file = True try: # Verschiebung von Datum Erstsendung new_date = sendung[2] + datetime.timedelta(days=-item[5]) lib_cm.message_write_to_console(ac, new_date.strftime(d_pattern)) if item[1].strip() == "T": # from dropbox path_source = lib_cm.check_slashes(ac, db.ac_config_servpath_b[5]) path_file_source = (path_source + l_path_title[0] #+ sendung[0][2].strftime('%Y_%m_%d') + l_path_title[1].rstrip()) + new_date.strftime(d_pattern) + l_path_title[1].rstrip()) if item[3].strip() == "T": # from ftp #url_base = db.ac_config_1[3].encode(ac.app_encode_out_strings) #url_source_file = db.ac_config_1[7].encode(ac.app_encode_out_strings) path_source = lib_cm.check_slashes(ac, db.ac_config_1[3]) path_file_source = (path_source + l_path_title[0] #+ sendung[0][2].strftime('%Y_%m_%d') + l_path_title[1].rstrip()) + new_date.strftime(d_pattern) + l_path_title[1].rstrip()) # it or mag else sendung if sendung[4].strip() == "T" or sendung[5].strip() == "T": path_dest = lib_cm.check_slashes(ac, db.ac_config_servpath_a[1]) else: path_dest = lib_cm.check_slashes(ac, db.ac_config_servpath_a[2]) # replace special char # replace_uchar_sonderzeichen_with_latein path_file_dest = (path_dest + str(sendung[8]) + "_" + lib_cm.replace_sonderzeichen_with_latein(sendung[16]) + "_" + lib_cm.replace_sonderzeichen_with_latein(sendung[13]) #+ lib_cm.replace_uchar_sonderzeichen_with_latein(sendung[0][13]) + ".mp3") except Exception, e: log_message = (ac.app_errorslist[5] + "fuer: " + sendung[11].encode('ascii', 'ignore') + " " + str(e)) db.write_log_to_db_a(ac, log_message, "x", "write_also_to_console") success_file = None
def lets_rock(): """main function """ print "lets_rock " # extendet params load_extended_params_ok = load_extended_params() if load_extended_params_ok is None: return lib_cm.message_write_to_console(ac, u"lets_rock check_and_work_on_files") path_source = lib_cm.check_slashes(ac, db.ac_config_servpath_b[3]) path_dest = lib_cm.check_slashes(ac, db.ac_config_servpath_b[4]) #lib_cm.message_write_to_console(ac, path_source) #lib_cm.message_write_to_console(ac, path_dest) # read mp3gain-folder try: files_source = os.listdir(path_source) except Exception, e: log_message = u"read_files_from_dir Error: %s" % str(e) lib_cm.message_write_to_console(ac, log_message + path_source) db.write_log_to_db(ac, log_message, "x") return None
def write_to_file_record_params(r_duration, list_live_sendungen): """write configfile for recorder""" log_message = ("Laenge des Mitschnitts: " + str(r_duration) + "Sekunden") db.write_log_to_db_a(ac, log_message, "t", "write_also_to_console") c_date_time_from = (str(ac.time_target.date()) + "_" + str(ac.time_target.hour).zfill(2)) file_recording_config = ac.app_homepath + db.ac_config_1[5] r_name = lib_cm.replace_uchar_sonderzeichen_with_latein( list_live_sendungen[0][15]).replace(" ", "") r_title = lib_cm.replace_uchar_sonderzeichen_with_latein( list_live_sendungen[0][11][0:8]).replace(" ", "") # home path of active stream-server if db.ac_config_server_active[3] == "A": r_path = ("/home/" + db.ac_config_servset[9] + lib_cm.check_slashes(ac, db.ac_config_1[6])) if db.ac_config_server_active[3] == "B": r_path = ("/home/" + db.ac_config_servset[10] + lib_cm.check_slashes(ac, db.ac_config_1[6])) r_path_file = (r_path + c_date_time_from + "_" + r_name + "_" + r_title + ".wav") # startdelay when transmitting begins not with 0 minute and 0 sec r_wait = list_live_sendungen[0][2].minute * 60 r_wait += list_live_sendungen[0][2].second # begin record a few seconds before transmitt begins r_wait -= int(db.ac_config_1[3]) # crotab starts record script in minute 59, so 60 sec must added r_wait += 60 try: f_r_conf = open(file_recording_config, 'w') except IOError as (errno, strerror): log_message = ( "write_to_file_record_params: I/O error({0}): {1}".format( errno, strerror) + ": " + file_recording_config) db.write_log_to_db(ac, log_message, "x") db.write_log_to_db_a(ac, ac.app_errorslist[1], "x", "write_also_to_console")
def write_to_file_record_params(r_duration, list_live_sendungen): """write configfile for recorder""" log_message = ("Laenge des Mitschnitts: " + str(r_duration) + "Sekunden") db.write_log_to_db_a(ac, log_message, "t", "write_also_to_console") c_date_time_from = (str(ac.time_target.date()) + "_" + str(ac.time_target.hour).zfill(2)) file_recording_config = ac.app_homepath + db.ac_config_1[5] r_name = lib_cm.replace_uchar_sonderzeichen_with_latein( list_live_sendungen[0][15]).replace(" ", "") r_title = lib_cm.replace_uchar_sonderzeichen_with_latein( list_live_sendungen[0][11][0:8]).replace(" ", "") # home path of active stream-server if db.ac_config_server_active[3] == "A": r_path = ("/home/" + db.ac_config_servset[9] + lib_cm.check_slashes(ac, db.ac_config_1[6])) if db.ac_config_server_active[3] == "B": r_path = ("/home/" + db.ac_config_servset[10] + lib_cm.check_slashes(ac, db.ac_config_1[6])) r_path_file = (r_path + c_date_time_from + "_" + r_name + "_" + r_title + ".wav") # startdelay when transmitting begins not with 0 minute and 0 sec r_wait = list_live_sendungen[0][2].minute * 60 r_wait += list_live_sendungen[0][2].second # begin record a few seconds before transmitt begins r_wait -= int(db.ac_config_1[3]) # crotab starts record script in minute 59, so 60 sec must added r_wait += 60 try: f_r_conf = open(file_recording_config, 'w') except IOError as (errno, strerror): log_message = ("write_to_file_record_params: I/O error({0}): {1}" .format(errno, strerror) + ": " + file_recording_config) db.write_log_to_db(ac, log_message, "x") db.write_log_to_db_a(ac, ac.app_errorslist[1], "x", "write_also_to_console")
def tag_file_id3(podcast_sendung): """tag files with id3""" lib_cm.message_write_to_console(ac, u"tag files with id3") # dest recoded file path_source = lib_cm.check_slashes(ac, db.ac_config_1[10]) c_source_file = path_source + podcast_sendung[0] db.write_log_to_db_a(ac, u"Podcast mit ID3 taggen: " + c_source_file, "k", "write_also_to_console") if os.path.isfile(c_source_file): id3_tag_present = False try: audio_id3_tag = ID3(c_source_file) id3_tag_present = True except ID3NoHeaderError: db.write_log_to_db_a(ac, u"Kein ID3 Tag vorhanden: " + podcast_sendung[0], "t", "write_also_to_console") if id3_tag_present: db.write_log_to_db_a(ac, u"ID3 Tag vorhanden: " + podcast_sendung[0], "t", "write_also_to_console") audio_id3_tag.delete() db.write_log_to_db_a(ac, u"ID3 Tag geloescht: " + podcast_sendung[0], "t", "write_also_to_console") id3_author_value_uni = podcast_sendung[2] + " " + podcast_sendung[3] #c_id3_author_value = id3_author_value_uni.encode("utf-8") #c_id3_title_value = podcast_sendung[1].encode("utf-8") #audio_id3_tag.add(TPE2(encoding=3, text=c_id3_author_value)) #audio_id3_tag.add(TIT2(encoding=3, text=c_id3_title_value)) audio_id3_tag.add(TPE1(encoding=3, text=id3_author_value_uni)) audio_id3_tag.add(TIT2(encoding=3, text=podcast_sendung[1])) audio_id3_tag.save() #audio = ID3(c_source_file) #print "Artist: %s" % audio['TPE2'].text[0] #print "Track: %s" % audio["TIT2"].text[0] db.write_log_to_db_a(ac, u"Podcast mit ID3 getaggt: " + podcast_sendung[0], "k", "write_also_to_console") else: db.write_log_to_db_a(ac, ac.app_errorslist[3] + c_source_file, "x", "write_also_to_console") return
def filepaths(): """concatenate path and filename""" #d_h_pattern, l_path_title = date_hour_pattern(db.ac_config_1[6]) path_source = lib_cm.check_slashes(ac, db.ac_config_servpath_b[5]) path_file_source_conf = path_source + db.ac_config_1[6] d_h_pattern, l_path_title = date_hour_pattern(path_file_source_conf) if d_h_pattern is None: return None, None #curr_date_hour = ac.time_target_start.strftime("%Y_%m_%d_%H") date_hour = ac.time_target_start.strftime("%Y_%m_%d_%H") #lib_cm.message_write_to_console(ac, curr_date_hour) #path_file_source = path_source + curr_date_hour + "_Elias_News_ohne.mp3" path_file_source = (l_path_title[0] + date_hour + l_path_title[1].rstrip()) lib_cm.message_write_to_console(ac, path_file_source) temp_orig_file = ac.app_file_orig_temp + ".mp3" return path_file_source, temp_orig_file
def erase_files_from_ftp(c_date_back): """erase files from ftp""" lib_cm.message_write_to_console(ac, "erase files from ftp") path_ftp = lib_cm.check_slashes(ac, db.ac_config_1[6]) ftp = ftp_connect_and_dir(path_ftp) if ftp is None: return files_online = [] try: files_online = ftp.nlst() except ftplib.error_perm, resp: if str(resp) == "550 No files found": lib_cm.message_write_to_console( ac, u"ftp: no files in this directory") else: log_message = (ac.app_errorslist[9]) db.write_log_to_db_a(ac, log_message, "x", "write_also_to_console") return None
def erase_files_from_ftp(c_date_back): """erase files from ftp""" lib_cm.message_write_to_console(ac, "erase files from ftp") path_ftp = lib_cm.check_slashes(ac, db.ac_config_1[6]) ftp = ftp_connect_and_dir(path_ftp) if ftp is None: return files_online = [] try: files_online = ftp.nlst() except ftplib.error_perm, resp: if str(resp) == "550 No files found": lib_cm.message_write_to_console(ac, u"ftp: no files in this directory") else: log_message = (ac.app_errorslist[9]) db.write_log_to_db_a(ac, log_message, "x", "write_also_to_console") return None
def write_to_info_file(filename_dest, item, sendung): """writing info-file""" success_write = True manuskript_data = load_manuskript(sendung) if manuskript_data is not None: manuskript_text = lib_cm.simple_cleanup_html(manuskript_data[0]) try: path_file_temp = (lib_cm.check_slashes(ac, db.ac_config_1[2]) + filename_dest.replace("mp3", "txt")) f_info_txt = open(path_file_temp, 'w') db.write_log_to_db_a(ac, "Info-Text schreiben " + path_file_temp, "v", "write_also_to_console") except IOError as (errno, strerror): log_message = ("write_to_file_record_params: I/O error({0}): {1}" .format(errno, strerror) + ": " + path_file_temp) db.write_log_to_db(ac, log_message, "x") db.write_log_to_db_a(ac, ac.app_errorslist[2], "x", "write_also_to_console") success_write = False
def write_to_info_file(filename_dest, sendung): """write info-file""" success_write = True manuskript_data = load_manuskript(sendung) if manuskript_data is not None: manuskript_text = lib_cm.simple_cleanup_html(manuskript_data[0]) try: path_file_temp = (lib_cm.check_slashes(ac, db.ac_config_1[2]) + filename_dest.replace("mp3", "txt")) f_info_txt = open(path_file_temp, 'w') db.write_log_to_db_a(ac, "Info-Text schreiben " + path_file_temp, "v", "write_also_to_console") except IOError as (errno, strerror): log_message = ("write_to_file_record_params: I/O error({0}): {1}" .format(errno, strerror) + ": " + path_file_temp) db.write_log_to_db(ac, log_message, "x") db.write_log_to_db_a(ac, ac.app_errorslist[2], "x", "write_also_to_console") success_write = False
def trim_bed(c_lenght): """trim soundbed to length of news""" lib_cm.message_write_to_console(ac, u"Soundbed auf News trimmen") # use the right char-encoding for supprocesses cmd = db.ac_config_etools[2].encode(ac.app_encode_out_strings) #cmd = "sox" lib_cm.message_write_to_console(ac, c_lenght) source_path = ac.app_homepath + lib_cm.check_slashes(ac, db.ac_config_1[10]) source_file = source_path + ac.app_file_bed dest_file = ac.app_file_bed_trim # start subprocess #silence 1 0.1 1% reverse silence 1 0.1 1% reverse l = c_lenght[0:7] try: p = subprocess.Popen([cmd, u"-S", source_file, dest_file, u"trim", u"0", l], stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate() except Exception, e: log_message = ac.app_errorslist[5] + u": %s" % str(e) db.write_log_to_db_a(ac, log_message, "x", "write_also_to_console") return None
def erase_files_from_protokoll(): """erase old archived file""" lib_cm.message_write_to_console(ac, u"erase_files_from_protokoll") path_sendung_dest = lib_cm.check_slashes(ac, db.ac_config_servpath_b[2]) lib_cm.message_write_to_console(ac, path_sendung_dest) # Days back days_back = int(db.ac_config_1[4]) date_proto_erase = (datetime.datetime.now() + datetime.timedelta(days=- days_back)) date_to_erase = date_proto_erase.strftime("%Y_%m_%d") lib_cm.message_write_to_console(ac, date_proto_erase) try: files_sendung_dest = os.listdir(path_sendung_dest) except Exception, e: log_message = u"read_files_from_dir Error: %s" % str(e) lib_cm.message_write_to_console(ac, log_message) db.write_log_to_db(ac, log_message, "x") return None
def trim_bed(c_lenght): """trim soundbed to length of news""" lib_cm.message_write_to_console(ac, u"Soundbed auf News trimmen") # use the right char-encoding for supprocesses cmd = db.ac_config_etools[2].encode(ac.app_encode_out_strings) #cmd = "sox" lib_cm.message_write_to_console(ac, c_lenght) source_path = ac.app_homepath + lib_cm.check_slashes( ac, db.ac_config_1[10]) source_file = source_path + ac.app_file_bed dest_file = ac.app_file_bed_trim # start subprocess #silence 1 0.1 1% reverse silence 1 0.1 1% reverse l = c_lenght[0:7] try: p = subprocess.Popen( [cmd, u"-S", source_file, dest_file, u"trim", u"0", l], stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate() except Exception, e: log_message = ac.app_errorslist[5] + u": %s" % str(e) db.write_log_to_db_a(ac, log_message, "x", "write_also_to_console") return None
def add_id3(sendung_data): """write id3-tag in mp3-file""" lib_cm.message_write_to_console(ac, u"id3-Tag in mp3-File schreiben") # use the right char-encoding for supprocesses cmd = db.ac_config_etools[4].encode(ac.app_encode_out_strings) #cmd = "id3v2" #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]) dest_path_file = dest_path + sendung_data[12] c_author = (sendung_data[15].encode(ac.app_encode_out_strings) + " " + sendung_data[16].encode(ac.app_encode_out_strings)) c_title = sendung_data[11].encode(ac.app_encode_out_strings) lib_cm.message_write_to_console(ac, cmd) # start subprocess try: p = subprocess.Popen( [cmd, u"-a", c_author, u"-t", c_title, dest_path_file], stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate() except Exception, e: log_message = ac.app_errorslist[8] + u": %s" % str(e) db.write_log_to_db_a(ac, log_message, "x", "write_also_to_console") return None
def erase_files_from_protokoll_temp(): """erase temp file""" lib_cm.message_write_to_console(ac, u"erase_files_from_protokoll_temp") file_ext = db.ac_config_1[6] #path_sendung_source = lib_cm.check_slashes(ac, db.ac_config_1[1]) path_sendung_source = lib_cm.check_slashes(ac, db.ac_config_servpath_b[1]) lib_cm.message_write_to_console(ac, path_sendung_source) # Days back days_back = int(db.ac_config_1[3][0:3]) date_proto_erase = (datetime.datetime.now() + datetime.timedelta(days=- days_back)) date_to_erase = date_proto_erase.strftime("%Y-%m-%d") lib_cm.message_write_to_console(ac, date_to_erase) try: files_sendung_temp = os.listdir(path_sendung_source) except Exception, e: log_message = u"read_proto_temp_files_from_dir Error: %s" % str(e) lib_cm.message_write_to_console(ac, log_message) db.write_log_to_db(ac, log_message, "x") return None
def add_id3(sendung_data): """write id3-tag in mp3-file""" lib_cm.message_write_to_console(ac, u"id3-Tag in mp3-File schreiben") # use the right char-encoding for supprocesses cmd = db.ac_config_etools[4].encode(ac.app_encode_out_strings) #cmd = "id3v2" #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]) dest_path_file = dest_path + sendung_data[12] c_author = (sendung_data[15].encode( ac.app_encode_out_strings) + " " + sendung_data[16].encode(ac.app_encode_out_strings)) c_title = sendung_data[11].encode(ac.app_encode_out_strings) lib_cm.message_write_to_console(ac, cmd) # start subprocess try: p = subprocess.Popen([cmd, u"-a", c_author, u"-t", c_title, dest_path_file], stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate() except Exception, e: log_message = ac.app_errorslist[8] + u": %s" % str(e) db.write_log_to_db_a(ac, log_message, "x", "write_also_to_console") return None
def filepaths(item, sendung): """concatenate path and filename""" lib_cm.message_write_to_console(ac, u"filepaths") success_file = True path_file_cloud = None path_ftp = None try: if sendung[4].strip() == "T" or sendung[5].strip() == "T": # IT or MAG path_source = lib_cm.check_slashes(ac, db.ac_config_servpath_a[1]) else: path_source = lib_cm.check_slashes(ac, db.ac_config_servpath_a[2]) path_file_source = (path_source + sendung[12]) filename_dest = (sendung[2].strftime('%Y_%m_%d') + "_" + db.ac_config_1[4] + str(sendung[12][7:])) if item[1].strip() == "T": # Cloud path_dest_cloud = lib_cm.check_slashes(ac, db.ac_config_servpath_b[5]) path_cloud = lib_cm.check_slashes(ac, item[2]) path_file_cloud = (path_dest_cloud + path_cloud + filename_dest) if item[3].strip() == "T": # FTP path_ftp_main = lib_cm.check_slashes(ac, db.ac_config_1[6]) path_ftp_sub = lib_cm.check_slashes(ac, item[4]) path_ftp = (path_ftp_main + path_ftp_sub) except Exception, e: log_message = (ac.app_errorslist[3] + " fuer - " + sendung[11].encode('ascii', 'ignore') + " - vielt. kein Ordner in autm. Sendung angegeben") db.write_log_to_db_a(ac, log_message, "x", "write_also_to_console") db.write_log_to_db_a(ac, str(e), "x", "write_also_to_console") success_file = False
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")
try: list_dirs = os.listdir(path_sendung_dest) except Exception, e: log_message = u"read_files_from_dir Error: %s" % str(e) lib_cm.message_write_to_console(ac, log_message + path_sendung_dest) db.write_log_to_db(ac, log_message, "x") return None lib_cm.message_write_to_console(ac, list_dirs) # check if new year folder is neccesarry current_year = str(datetime.datetime.now().year) # check slashes current_year_path = path_sendung_dest + lib_cm.check_slashes( ac, current_year) try: if not os.path.exists(current_year_path): # make new folder log_message = u"anlegen Archiv-Verzeichnis: " + current_year_path lib_cm.message_write_to_console(ac, log_message) db.write_log_to_db(ac, log_message, "k") os.mkdir(current_year_path) except Exception, e: log_message = u"anlegen Archiv-Verzeichnis Error: %s" % str(e) lib_cm.message_write_to_console(ac, log_message) db.write_log_to_db(ac, log_message, "x") return None
try: list_dirs = os.listdir(path_sendung_dest) except Exception, e: log_message = u"read_files_from_dir Error: %s" % str(e) lib_cm.message_write_to_console(ac, log_message + path_sendung_dest) db.write_log_to_db(ac, log_message, "x") return None lib_cm.message_write_to_console(ac, list_dirs) # check if new year folder is neccesarry current_year = str(datetime.datetime.now().year) # check slashes current_year_path = path_sendung_dest + lib_cm.check_slashes(ac, current_year) try: if not os.path.exists(current_year_path): # make new folder log_message = u"anlegen Archiv-Verzeichnis: " + current_year_path lib_cm.message_write_to_console(ac, log_message) db.write_log_to_db(ac, log_message, "k") os.mkdir(current_year_path) except Exception, e: log_message = u"anlegen Archiv-Verzeichnis Error: %s" % str(e) lib_cm.message_write_to_console(ac, log_message) db.write_log_to_db(ac, log_message, "x") return None
def encode_file(podcast_sendung): """recode mp3-files with lower rate""" lib_cm.message_write_to_console(ac, u"encode_file") # all cmds must be in the right charset c_lame_encoder = db.ac_config_etools[6].encode(ac.app_encode_out_strings) #lib_cm.message_write_to_console(ac, u"type c_lame_encoder") #lib_cm.message_write_to_console(ac, type(c_lame_encoder)) #lib_cm.message_write_to_console(ac, u"type podcast_sendung[1]") #lib_cm.message_write_to_console(ac, type(podcast_sendung[1])) c_id3_title = u"--tt".encode(ac.app_encode_out_strings) #lib_cm.message_write_to_console(ac, u"type( c_id3_title )") #lib_cm.message_write_to_console(ac, type(c_id3_title)) #c_id3_title_value = podcast_sendung[1].encode( ac.app_encode_out_strings ) c_id3_title_value_uni = (lib_cm.replace_sonderzeichen_with_latein( podcast_sendung[1])) c_id3_title_value = c_id3_title_value_uni.encode(ac.app_encode_out_strings) #lib_cm.message_write_to_console(ac, u"type( c_id3_title_value )") #lib_cm.message_write_to_console(ac, type(c_id3_title_value)) c_id3_author = u"--ta".encode(ac.app_encode_out_strings) #lib_cm.message_write_to_console(ac, u"type( c_id3_author )") #lib_cm.message_write_to_console(ac, type(c_id3_author)) id3_author_value_uni = (lib_cm.replace_sonderzeichen_with_latein( podcast_sendung[2]) + " " + lib_cm.replace_sonderzeichen_with_latein(podcast_sendung[3])) c_id3_author_value = id3_author_value_uni.encode(ac.app_encode_out_strings) #lib_cm.message_write_to_console(ac, u"type(c_id3_author_value )") #lib_cm.message_write_to_console(ac, type(c_id3_author_value)) # source sendung path_sendung_source = lib_cm.check_slashes(ac, db.ac_config_servpath_a[6]) c_source_file = (path_sendung_source.encode(ac.app_encode_out_strings) + podcast_sendung[0].encode(ac.app_encode_out_strings)) #lib_cm.message_write_to_console(ac, c_source_file) # source infotime und mag path_it_mg_source = lib_cm.check_slashes(ac, db.ac_config_servpath_a[5]) # infotime if podcast_sendung[4] == "T": #c_source_file = path_it_mg_source + podcast_sendung[0] c_source_file = (path_it_mg_source.encode(ac.app_encode_out_strings) + podcast_sendung[0].encode(ac.app_encode_out_strings)) # magazine if podcast_sendung[5] == "T": #c_source_file = path_it_mg_source + podcast_sendung[0] c_source_file = (path_it_mg_source.encode(ac.app_encode_out_strings) + podcast_sendung[0].encode(ac.app_encode_out_strings)) #lib_cm.message_write_to_console(ac, c_source_file) #lib_cm.message_write_to_console(ac, u"type(c_source_file)") #lib_cm.message_write_to_console(ac, type(c_source_file)) if not os.path.isfile(c_source_file): db.write_log_to_db_a(ac, ac.app_errorslist[5] + " " + podcast_sendung[0].encode(ac.app_encode_out_strings), "x", "write_also_to_console") return None # dest recoded file path_dest = lib_cm.check_slashes(ac, db.ac_config_1[10]) c_dest_file = (path_dest.encode(ac.app_encode_out_strings) + podcast_sendung[0].encode(ac.app_encode_out_strings)) #lib_cm.message_write_to_console(ac, c_dest_file) #lib_cm.message_write_to_console(ac, u"type(c_dest_file)") #lib_cm.message_write_to_console(ac, type(c_dest_file)) # das geht auch #p = subprocess.Popen([c_lame_encoder, "--add-id3v2", c_id3_title, #c_id3_title_value, #c_id3_author, c_id3_author_value, #c_source_file, c_dest_file ]).communicate() # ausgaben abfangen #p = subprocess.Popen([c_lame_encoder, "--add-id3v2", c_id3_title, #c_id3_title_value, c_id3_author, c_id3_author_value, #c_source_file, c_dest_file ], #stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate() p = subprocess.Popen([c_lame_encoder, u"--add-id3v2".encode( ac.app_encode_out_strings), c_id3_title, c_id3_title_value, c_id3_author, c_id3_author_value, c_source_file, c_dest_file], stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate() lib_cm.message_write_to_console(ac, u"returncode 0") lib_cm.message_write_to_console(ac, p[0]) lib_cm.message_write_to_console(ac, u"returncode 1") lib_cm.message_write_to_console(ac, p[1]) # search for success-mesg, if not found: -1 n_encode_percent = string.find(p[1], "(100%)") n_encode_percent_1 = string.find(p[1], "(99%)") lib_cm.message_write_to_console(ac, n_encode_percent) c_complete = "no" # by short files 100% will not be reached, # therefor also let's take 99% if n_encode_percent == -1: # 100% not reached if n_encode_percent_1 != -1: # but 99 c_complete = "yes" else: c_complete = "yes" if c_complete == "yes": log_message = u"recoded_file: " + c_source_file db.write_log_to_db(ac, log_message, "k") #lib_cm.message_write_to_console(ac, "ok") return c_dest_file else: db.write_log_to_db_a(ac, ac.app_errorslist[2] + c_source_file, "x", "write_also_to_console") return None
def delete_files_online_sftp(): """delete old files at Webspace""" lib_cm.message_write_to_console(ac, u"delete_files_online sftp") sftp, transport = sftp_connect() if sftp is None: return None # Get list try: files_online = sftp.listdir_attr(db.ac_config_1[9]) except Exception as e: files_online = None lib_cm.message_write_to_console(ac, e) db.write_log_to_db_a(ac, ac.app_errorslist[9], "x", "write_also_to_console") # Close sftp.close() transport.close() if files_online is None: return None if len(files_online) <= int(db.ac_config_1[2]): db.write_log_to_db_a(ac, u"Loeschen von Podcasts nicht noetig, zu wenige Dateien: " + str(len(files_online)), "c", "write_also_to_console") return "Nothing to do" else: number_of_files_to_delete = len(files_online) - int(db.ac_config_1[2]) # new list with modtime, filename files_online_1 = [] for item in files_online: # only play-out-files starting with numbers if (re.match("[0-9]{7}", item.filename) is not None): files_online_1.append((item.st_mtime, item.filename)) files_online_1.sort() db.write_log_to_db_a(ac, u"Podcasts auf Server vorhanden: " + str(len(files_online_1)), "t", "write_also_to_console") db.write_log_to_db_a(ac, u"Alte Podcasts auf Server loeschen...", "t", "write_also_to_console") sftp, transport = sftp_connect() if sftp is None: return None path_remote = lib_cm.check_slashes(ac, db.ac_config_1[9]) z = 0 for item in files_online_1: # delete try: sftp.remove(path_remote + item[1]) db.write_log_to_db_a(ac, u"Podcast online geloescht: " + item[1], "c", "write_also_to_console") z += 1 except Exception as e: lib_cm.message_write_to_console(ac, e) db.write_log_to_db_a(ac, ac.app_errorslist[11], "x", "write_also_to_console") break if number_of_files_to_delete == z: break sftp.close() transport.close() db.write_log_to_db_a(ac, u"Podcasts online geloescht: " + str(z), "t", "write_also_to_console") return number_of_files_to_delete
filename_nr = "no_nr" try: # der versuch den 2. splitt zu bekommen gibt fehler # wenn split-muster nicht gefunden filename_name = repeat_sendung[12].split("_")[1] except Exception, e: filename_name = "no_name" if filename_nr == repeat_sendung[8] and filename_name == repeat_sendung[16]: # Play-Out-Dateiname beginnt mit SG-Cont_Nr und Nachname lib_cm.message_write_to_console(ac, u"Filename aus db: " + repeat_sendung[12]) if repeat_sendung[4].strip() == "T" or repeat_sendung[5].strip() == "T": # InfoTime path_dest = lib_cm.check_slashes(ac, db.ac_config_servpath_a[1]) else: # Sendung path_dest = lib_cm.check_slashes(ac, db.ac_config_servpath_a[2]) file_dest = path_dest + repeat_sendung[12] else: # no Filename like SRB Pattern, make pattern lib_cm.message_write_to_console(ac, u"SRB-Muster-Filename nicht in db, zusammenbauen") if repeat_sendung[4].strip() == "T" or repeat_sendung[5].strip() == "T": # InfoTime path_dest = lib_cm.check_slashes(ac, db.ac_config_servpath_a[1]) else: # Sendung path_dest = lib_cm.check_slashes(ac, db.ac_config_servpath_a[2])