Пример #1
0
def update_pip_package(prog, package):
    """
    update pip 'package' with 'prog'
    """
    try:
        print_try_update(package, prog)
        params = [
            prog,
            "install",
            "--upgrade",
            package,
        ]
        print_debug("full trace pip")
        output = subprocess.check_output(params)
        # print(output)
        for line in output.decode("utf-8").split("\n"):
            if is_verbose():
                print(line.strip(" "))
            elif "Successfully" in line:
                print(line.strip(" "))
            elif ("Requirement already satisfied: " + package) in line or (
                    "Requirement already up-to-date: " + package) in line:
                print(line.strip(" "))
        print("Update ok")
        return True
    except Exception:
        print_error_update_package()
        return False
Пример #2
0
def print_error_update_package():
    """
    print the error message with minimal informations
    """
    if is_verbose():
        print(my_colored(DEBUG_HEADER, "yellow"))
        print(my_colored(traceback.format_exc(), "yellow"))
    print(my_colored(EXCEPTION_UPDATE, "red"))
Пример #3
0
def print_error():
    """
    print the error message with additional informations
    """
    if is_verbose():
        print(my_colored(DEBUG_HEADER, "yellow"))
        print(my_colored(traceback.format_exc(), "yellow"))
    print(my_colored(EXCEPTION, "red"))
    print_addtional_informations()
Пример #4
0
def print_addtional_informations():
    """
    print footer informations
    """
    if is_verbose():
        print_version_ytdlmusic()
        print_version_dependencies()
        print(my_colored(BUG_MESSSAGE_DEBUG, "yellow"))
    else:
        print(my_colored(BUG_MESSSAGE, "yellow"))
Пример #5
0
def batch(params):
    """
    batch job
    """
    file_path = params[0]
    has_header = params[1]
    separator = params[2]
    search = ""

    with open(file_path, "r", encoding="utf-8") as csvfile:
        reader = csv.reader(csvfile, delimiter=separator, quotechar="|")
        if has_header == "True":
            next(reader, None)
        for row in reader:
            search = ""
            if is_verbose():
                print_debug(str(reader.line_num) + " en cours : " + str(row))
            for element in str(params[3]).split("+"):
                search = search + " " + row[int(element) - 1]
            job(search.replace(" ", "", 1))
Пример #6
0
def download_song(song_url, filename):
    """
    download song with yt-dlp
    in filename
    from url song_url
    """

    print(
        my_colored_emoji("\U0001F4BE", "download " + song_url + " with yt_dlp", "green")
    )

    # m4a
    opts = {
        "outtmpl": name_without_extension(filename) + ".%(ext)s",
        "format": "m4a/best",
    }

    if extension(filename) == ".mp3":
        opts["format"] = "bestaudio/best"
        opts["postprocessors"] = [
            {
                "key": "FFmpegExtractAudio",
                "preferredcodec": "mp3",
                "preferredquality": "256",
            },
            {"key": "FFmpegMetadata"},
        ]
        if is_quality():
            opts.get("postprocessors")[0]["preferredquality"] = "320"

    if extension(filename) == ".ogg":
        opts["format"] = "bestaudio/best"
        opts["postprocessors"] = [
            {
                "key": "FFmpegExtractAudio",
                "preferredcodec": "vorbis",
            },
            {"key": "FFmpegMetadata"},
        ]

    if is_verbose():
        opts["verbose"] = "True"
        print_debug("debug yt-dlp is activated")
    if not is_quiet():
        print("start yt-dlp operation")
    elif is_quiet():
        opts["quiet"] = True
        opts["no_warnings"] = True
    with yt_dlp.YoutubeDL(opts) as ydl:
        ydl.extract_info(song_url, download=True)
    if not is_quiet():
        print("end yt-dlp operation")
    if not is_ffmpeg_installed() and not is_m4a() and not is_ogg():
        print(
            my_colored(
                "[warning] If you want MP3/OGG format, install ffmpeg.",
                "yellow",
            )
        )
        print(
            my_colored(
                "[warning] To disable this message activate -f",
                "yellow",
            )
        )
Пример #7
0
def print_debug(message):
    """
    print "[debug] " + message only if --verbose
    """
    if is_verbose():
        print("[debug] " + message)