Exemple #1
0
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")
    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")

    # extract filename
    if ac.app_windows == "no":
        filename = file_dest[string.rfind(file_dest, "/") + 1:]
    else:
        filename = file_dest[string.rfind(file_dest, "\\") + 1:]

    # in sendeanmeldung filename ersetzen
    sql_command = ("UPDATE SG_HF_CONTENT SET SG_HF_CONT_FILENAME ='"
        + filename + "' where SG_HF_CONT_ID='" + str(repeat_sendung[8]) + "'")
    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")

    # extract filename
    if ac.app_windows == "no":
        filename = file_dest[string.rfind(file_dest, "/") + 1:]
    else:
        filename = file_dest[string.rfind(file_dest, "\\") + 1:]

    # in sendeanmeldung filename ersetzen
    sql_command = ("UPDATE SG_HF_CONTENT SET SG_HF_CONT_FILENAME ='" +
                   filename + "' where SG_HF_CONT_ID='" +
                   str(repeat_sendung[8]) + "'")
        #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)
        #success_add_rgain = lib_au.add_replaygain(
        #                        ac, db, lib_cm, c_source_file)

        #if success_add_rgain is None:
        #    db.write_log_to_db_a(ac, ac.app_errorslist[1],
        #                                "x", "write_also_to_console")
        #    continue
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")