示例#1
0
def determine_finame_from_tag(filename):
    """
    determine final filename from metatags
    """
    print(my_colored("filename conversion with metadata", "green"))
    nom_genere = ""
    if not is_ffmpeg_installed() or is_m4a():
        print(
            my_colored(
                "[warning] If you want use metadata tags, install ffmpeg and use MP3 or OGG format.",
                "yellow",
            ))
        print(my_colored("[warning] keep the YouTube format.", "yellow"))
        return filename

    title, artist, album = obtain_tags(filename)

    if not title or not artist:
        print(my_colored("[warning] Not enough tags information", "yellow"))
        return filename
    if album:
        nom_genere = (unicode_and_trim(artist) + " - " +
                      unicode_and_trim(album) + " - " +
                      unicode_and_trim(title))
    else:
        nom_genere = (unicode_and_trim(artist) + " - " +
                      unicode_and_trim(title))
    print_debug("file name deduced from metadata : ")
    return find_unique_name(nom_genere + extension(filename))
示例#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 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",
            )
        )