alexta69 / metube

Self-hosted YouTube downloader (web UI for youtube-dl / yt-dlp)
GNU Affero General Public License v3.0
5.31k stars 320 forks source link

Switching to use yt-dlp as youtube-dl seems to have stalled #41

Closed lenaxia closed 2 years ago

lenaxia commented 2 years ago

a la https://github.com/ytdl-org/youtube-dl/issues/29753 it seems youtube-dl may have stalled

It seems there are some throttling issues in youtube-dl anyway (https://github.com/ytdl-org/youtube-dl/issues/29361) which I've been hitting a lot of.

So there's another drop in replacement for youtube-dl here: https://github.com/yt-dlp/yt-dlp and wanted to suggest switching to using that instead.

Cheers

alexta69 commented 2 years ago

Thanks for the heads-up. I've tried yt-dlp and it doesn't quite work as a drop-in, the download crashes, there must be something different there. I'll try to find time to debug this. If you have some time you're also welcome to try it out of course.. If I get to it first, I'll let you know. Cheers!

lenaxia commented 2 years ago

I'm in the process of giving it a try as well, and likewise I also see the download crashing too. I'll see how far I can get to debug the crash.

alexta69 commented 2 years ago

Have you tried the new version now, after I pushed the changes? it's supposed to work with yt-dlp now. I did a little testing on it and it seems to work fine. Let me know if you're seeing problems with it.

lenaxia commented 2 years ago

Wow, that was fast. It works great. Looks like it defaults to webm format for download but thats something that can be managed on the user side.

Below are the changes I made. The first one outputs mp4 if you select best quality because Plex doesn't seem to be able to read video descriptions from .webm files. And the second block downloads the thumbnail and write the title and video description into the mp4 file itself for plex to pick up. Right now I'm just mounting a copy of the file with edits as a docker volume.

Edit: added so it does MP4 for all quality levels now

        if quality == 'best':
            self.format = f'bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best'
        elif quality in ('1440p', '1080p', '720p', '480p'):
            res = quality[:-1]
            self.format = f'bestvideo[height<={res}][ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best'

Edit: Added subtitles download too

ret = yt_dlp.YoutubeDL(params={                                                                                                                                                                                                                                                                                                                                            
  ...
  'writethumbnail': True,                                                                                                                                                                                                                                                                                                                                                         
  'postprocessors': [{                                                                                                                                                                                                                                                                                                                                                                 
  'key': 'FFmpegMetadata'                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       
    }],                        
  'writesubtitles': True,
  'subtitle': '--write-sub --sub-lang en --sub-format vtt --convert-subtitles srt',                                                                                                                                                                                                                                                                                                                                                    
  ...
 }).download([self.info.url])

Edit: I should also note, I was seeing a bunch of errors for AtomicParsley in the logs when I enabled metadata writing, so I also mount a copy of AtomicParsley into the docker container. For the fullity of things, here's a copy of my docker compose:

  youtube-dl:
    image: "alexta69/metube"
    container_name: youtube-dl
    volumes:
      - "/mnt/downloads/[Plex Temp Library]/YouTube:/downloads"
      - $DOCKERDIR/youtube-dl/ytdl.py:/app/app/ytdl.py
      - $DOCKERDIR/youtube-dl/AtomicParsley:/usr/local/bin/AtomicParsley
    restart: unless-stopped
    user: "${PUID}:${PGID}"
    environment:
      - OUTPUT_TEMPLATE=%(upload_date)s - %(title)s [%(id)s].%(ext)s
alexta69 commented 2 years ago

Thanks! I liked the idea of preferring mp4, so I pushed the qualities change now. Note that in your example it seems, unless I'm missing something, that when you select a resolution it might still download the highest one. I pushed this, I hope it's correct (haven't tested, to be frank):

        elif quality in ('1440p', '1080p', '720p', '480p'):
            res = quality[:-1]
            self.format = f'bestvideo[height<={res}][ext=mp4]+bestaudio[ext=m4a]/best[height<={res}][ext=mp4]/best[height<={res}]'

I won't push the subtitle changes, because I feel the use case is too narrow and also AtomicParsley seems to be archeological -- it was last updated in 2005...

Thanks for your ideas!

lenaxia commented 2 years ago

I thought the same when I put that line of code in but I tried downloading a 480p version and it downloaded the right one so I left it as is. Can always strip out the end of the line if it does cause issues later.

And yeah, the subtitles and AtomicParsley may cause issues for others so totally get not inculding them.

Happy to help! metube has been the best youtube-dl interface that I've found. It's simple and gets the job done well, so been super happy with it.