I'm using Jellyfin Desktop in TV mode. it simplifies the UI and reacts to cursors, enter, and esc for navigation. I got a bluetooth controller for android boxes I paired with my desktop and it emits those keys via InputRemapper. There's also a separate key used to start JD in TV fullscreen mode, with --scale-factor 2, got a 4K screen and the UI is tiny otherwise.

I always thought JD should be able to play youtube videos, but so far, no change on that front. So up until recently, I also ran macast as a DLNA sink so I can send it youtube videos and it would play them in fullscreen via mpv. Grabs focus, mpv's input.conf makes it react to the same keys I use for JD, exits when it's done.

But because I couldn't figure out how to pause JD if it's playing and resume after, because of the insane amount of log spam from macast, and because I needed a separate sending app on my android device (allcast) I tried to simplify the setup and came up with the following.

On my desktop I got this bash script:

#!/usr/bin/env bash

JELLYFIN_WAS_PLAYING=

case "$1" in

  *youtube*|*youtu.be* )
    case "$1" in
      *channel* ) : ;;            
      *)
        while IFS= read -r player; do
          [[ $player == JellyfinDesktop* ]] || continue

          if [[ $(playerctl -p "$player" status 2>/dev/null) == Playing ]]; then
            playerctl -p "$player" pause
            JELLYFIN_WAS_PLAYING=1
            export JELLYFIN_WAS_PLAYING
            break
          fi
        done < <(playerctl -l)

        mpv --fs --no-terminal "$1"
        mpv_status=$?

        if [[ $JELLYFIN_WAS_PLAYING == 1 ]]; then
          playerctl -p "$player" play
          unset JELLYFIN_WAS_PLAYING
        fi

        exit "$mpv_status"
        ;;
    esac
    ;;


  * )
    firefox --new-tab "$1" >/dev/null 2>&1 &

    ;;

esac

and I set it as default browser in Plasma.

So what I do now is just send the link via KDEConnect. Plasma sends it to my script, it checks if the URL is from youtube and plays the thing. If JD was playing at the time, it pauses it and resumes after mpv exits. If it's a normal URL, open it in firefox.

I'd prefer to use freetube to play the video, as I would like to save the URL to history, but I don't know how to make it play in fullscreen. So I figure, next best thing is to work out out how to add the URL to freetube's history.

Got any comments, suggestions, ways to improve it? Edge cases I haven't considered?

edit: typo in code

you are viewing a single comment's thread
view the rest of the comments
[–] 3 points 1 day ago (1 child)

my plan for something similar is to use ytdlp to grab the video and put it in a YouTube library and then play from there, but that’s way more manual than what you’ve done

  • source
  • hideshow 1 child comment
  • [–] [S] 2 points 1 day ago

    mpv uses yt-dlp to fetch videos. adding this would be like coupla lines of code before launching mpv, get it, store it, play it.

    but this gave me an idea, to figure out a handler to favorite or save video. usual scenario is checking out ephemeral stuff, not much value to storing everything. but, a way to mark the video as to be saved would be useful.

  • source
  • parent