alexta69 / metube

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

Sponsorblock not working for non MP3 Files #410

Closed hoferbeck closed 3 months ago

hoferbeck commented 3 months ago

Hello,

Im using Metube to download songs to my music library .

Inspired by this Im trying to also add sponsorblock but it fails when i try to download a OPUS/M4A file (with MP3 its working)

I also try it manually via yt-dlp cli: yt-dlp https://www.youtube.com/watch?v=B7xai5u_tnk --sponsorblock-remove music_offtopic -f 140

i got the same HTTP400 error but it got downloaded anyways and cut the segment away

Example Video (the last few Seconds are cut(non music segement)

Docker Config:

metube:
    image: ghcr.io/alexta69/metube
    restart: unless-stopped
    volumes:
      - /mnt/sata/downloads-yt:/downloads
      - /opt/jellyfin/media/music:/downloads-music
      - AUDIO_DOWNLOAD_DIR=/downloads-music
      - YTDL_OPTIONS={"postprocessors":[{"key":"SponsorBlock","categories":["sponsor", "music_offtopic"]},{"key":"ModifyChapters","remove_sponsor_segments":["sponsor", "music_offtopic"]}]}

Docker Logs:

INFO:ytdl:adding https://www.youtube.com/watch?v=B7xai5u_tnk: quality='best' format='m4a' already=None folder=None custom_name_prefix=''
WARNING: [youtube] YouTube said: ERROR - Precondition check failed.
WARNING: [youtube] HTTP Error 400: Bad Request. Retrying (1/3)...
WARNING: [youtube] YouTube said: ERROR - Precondition check failed.
WARNING: [youtube] HTTP Error 400: Bad Request. Retrying (2/3)...
WARNING: [youtube] YouTube said: ERROR - Precondition check failed.
WARNING: [youtube] HTTP Error 400: Bad Request. Retrying (3/3)...
WARNING: [youtube] YouTube said: ERROR - Precondition check failed.
WARNING: [youtube] Unable to download API page: HTTP Error 400: Bad Request (caused by <HTTPError 400: Bad Request>); please report this issue on  https://github.com/yt-dlp/yt-dlp/issues?q= , filling out the appropriate issue template. Confirm you are on the latest version using  yt-dlp -U
INFO:ytdl:downloading TheFatRat - Monody (feat. Laura Brehm)
INFO:aiohttp.access:172.18.0.6 [14/Mar/2024:05:48:38 +0000] "POST /add HTTP/1.1" 200 267 "https://metube.hofer.onl/" "Mozilla/5.0 (X11; Linux x86_64; rv:123.0) Gecko/20100101 Firefox/123.0"
WARNING: [youtube] YouTube said: ERROR - Precondition check failed.
WARNING: [youtube] HTTP Error 400: Bad Request. Retrying (1/3)...
WARNING: [youtube] YouTube said: ERROR - Precondition check failed.
WARNING: [youtube] HTTP Error 400: Bad Request. Retrying (2/3)...
WARNING: [youtube] YouTube said: ERROR - Precondition check failed.
WARNING: [youtube] HTTP Error 400: Bad Request. Retrying (3/3)...
WARNING: [youtube] YouTube said: ERROR - Precondition check failed.
WARNING: [youtube] Unable to download API page: HTTP Error 400: Bad Request (caused by <HTTPError 400: Bad Request>); please report this issue on  https://github.com/yt-dlp/yt-dlp/issues?q= , filling out the appropriate issue template. Confirm you are on the latest version using  yt-dlp -U
INFO:aiohttp.access:172.18.0.6 [14/Mar/2024:05:48:43 +0000] "GET /ngsw.json?ngsw-cache-bust=0.3638474084427711 HTTP/1.1" 200 243 "https://metube.hofer.onl/custom-service-worker.js" "Mozilla/5.0 (X11; Linux x86_64; rv:123.0) Gecko/20100101 Firefox/123.0"
ERROR: Postprocessing: Error opening output files: Invalid argument
INFO:ytdl:waiting for item to download

Edit: I updated the Image the HTTP 400 Errors are now gone, but Post processing isnt still working:


INFO:ytdl:downloading TheFatRat - Monody (feat. Laura Brehm)
======== Running on http://0.0.0.0:8081 ========
(Press CTRL+C to quit)
INFO:aiohttp.access:172.18.0.6 [14/Mar/2024:06:28:33 +0000] "POST /add HTTP/1.1" 200 267 "https://metube.hofer.onl/" "Mozilla/5.0 (X11; Linux x86_64; rv:123.0) Gecko/20100101 Firefox/123.0"
ERROR: Postprocessing: Error opening output files: Invalid argument
INFO:ytdl:waiting for item to download
PikuZheng commented 3 months ago

try to delete AUDIO_DOWNLOAD_DIR=/downloads-music

or this may helpful

"postprocessors": [ {"key":"SponsorBlock", "categories":["music_offtopic"], "when": "after_filter"}, {"key": "ModifyChapters", "remove_sponsor_segments": {"music_offtopic"}} ]

hoferbeck commented 3 months ago

Hello,

i have commeted the AUDIO_DOWNLOAD_DIR variable, but i still get the same error.

if im trying the postprocessor from you i get this Docker error: services.metube.environment.[3]: unexpected type map[string]interface {}

PikuZheng commented 3 months ago
[B7xai5u_tnk].temp.m4a.concat':
  Duration: N/A, start: 0.000000, bitrate: 127 kb/s
  Stream #0:0(eng): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 127 kb/s
    Metadata:
      handler_name    : ISO Media file produced by Google Inc.
      vendor_id       : [0][0][0][0]
  Stream #0:1: Video: png, rgb24(pc), 1280x720, 90k tbr, 90k tbn                                       <-------- a png in m4a file
[ipod @ 0x7f8e75e15ac0] Could not find tag for codec png in stream #1, codec not currently supported in container
Could not write header for output file #0 (incorrect codec parameters ?): Invalid argument
Error initializing output stream 0:1 -- 
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #0:1 -> #0:1 (copy)
ERROR:   Stream #0:1 -> #0:1 (copy)
Traceback (most recent call last):
..........
yt_dlp.postprocessor.ffmpeg.FFmpegPostProcessorError:   Stream #0:1 -> #0:1 (copy)

yes there is an issue, which looks like m4a has an embed thumbnail and ffmpeg can't deal with it. I tried ffmpeg 5.2 to 6.1 and this issue exists. maybe we need to use ffmpeg to delete the png after download. but I don't know how, sorry

hoferbeck commented 3 months ago

Wouldn't it be possible to implement the --sponsorblock-remove music_offtopic argument into Metube? as its working flawless for me (even inside the metube container)

PikuZheng commented 3 months ago

Wouldn't it be possible to implement the --sponsorblock-remove music_offtopic argument into Metube? as its working flawless for me (even inside the metube container)

works for mp4 :joy:

hoferbeck commented 3 months ago

MP4 files are too big for my main use case

Hear the music on my phone/ car radio

PikuZheng commented 3 months ago
"writethumbnail":false,
 "postprocessors":[
  {"key": "FFmpegCopyStream"},
  {"key":"SponsorBlock","categories":["music_offtopic"],"when": "after_filter"},
  {"key": "ModifyChapters","remove_sponsor_segments": ["music_offtopic"]},

Using these parameters will not throw an error, but I don't know if it removes the sponsor block correctly.

hoferbeck commented 3 months ago

YTDL_OPTIONS='"writethumbnail":false,"postprocessors":[{"key":"FFmpegCopyStream"},{"key":"SponsorBlock","categories":["music_offtopic"],"when":"after_filter"},{"key":"ModifyChapters","remove_sponsor_segments":["music_offtopic"]}]'

seems you missed a ] in the and but now get the error "YTDL_OPTIONS is invalid" at start

PikuZheng commented 3 months ago

with a part of json, it should be fasle , which is I'm using. with a part of python, it should be False, maybe you should use it.

hoferbeck commented 3 months ago

I was able to get it running with a multi line string in the docker compose yaml. For some reason, I got the error mentioned before that config is invalid, when i do everything into one line


      YTDL_OPTIONS: >
        {"writethumbnail":false,
        "postprocessors":[
        {"key": "FFmpegCopyStream"},
        {"key":"SponsorBlock","categories":["music_offtopic"],"when": "after_filter"},
        {"key": "ModifyChapters","remove_sponsor_segments": ["music_offtopic"]}]}

In that case my "main" problem is closed, would be nice if it is somehow possible to get it working with a thumbnail (but that's a low importance for me