• etuomaala@sopuli.xyz
    link
    fedilink
    arrow-up
    5
    ·
    1 year ago

    That and you can just download opus from youtube using yt-dlp lol. It’s 100% great. Anybody transcoding youtube audio to mp3 is definitely doing it wrong lol

    • Willer@lemmy.world
      link
      fedilink
      arrow-up
      2
      ·
      1 year ago

      Thats why most of my yotuube downloads is .mka I found that matroska has better support than webm or ogg lol

      • etuomaala@sopuli.xyz
        link
        fedilink
        arrow-up
        1
        ·
        1 year ago
        I download opus .webm s,
            then use ffmpeg to convert to .opus,
            which I'm pretty sure is just ogg.
        IDK, works great in quodlibet.
        .webm can't be tagged, though.
        Tagging is critical, especially replay_gain tags.
        
        Here is my script:
        #!/usr/bin/env python
        
        # Youtube actually hosts audio-only opus tracks, but you can only get them
        # in the webm container, which many music players, including quodlibet, don't
        # know what to do with. This script downloads the track, then converts it with
        # zero loss to the opus container using ffmpeg's `-acodec copy` feature.
        
        import sys
        from subprocess import call
        from os.path import splitext
        from os import remove, walk, listdir
        from tempfile import TemporaryDirectory
        from shutil import move
        
        urls = sys.argv[1:]
        
        with TemporaryDirectory(prefix='yta-') as tempdir:
            # Do not raise exceptions, because yt-dlp counts failure of a single
            # download in the list as an overall failure, exit code wise.
            call(['env', '-C', tempdir, 'yt-dlp', '-if', 'bestaudio',
                '-o', '%(artist)s - %(title)s - %(id)s.%(ext)s', '--'] + urls)
        
            for tempdir, dirs, files in walk(tempdir):
                for fn in files:
                    path = tempdir+'/'+fn
                    name, ext = splitext(path)
                    if ext == '.webm':
                        if call([
                            'ffmpeg', '-hide_banner',
                            '-i', path,
                            '-acodec', 'copy',
                            name+'.opus'
                        ]) == 0:
                            remove(path)
        
            for node in listdir(tempdir):
                move(tempdir+'/'+node, '.')