diff --git a/README.org b/README.org index c890b4e..27ff362 100644 --- a/README.org +++ b/README.org @@ -18,7 +18,7 @@ If *strm* is configured to use the =media= directory, you can play the shortfilm e.g. with the following command: - : strm daily dweebs + : $ strm daily dweebs Every argument which is not assigned to an flag is interpreted as part of the query. The query arguments are interpreted as [[https://en.wikipedia.org/wiki/Glob_(programming)][glob patterns]], additionally surrounded by wildcards (=*=). @@ -28,9 +28,9 @@ The shortfilm from the example above could have also been played with one of the following commands: - : strm dweebs daily - : strm movies dwee - : strm d d 17 + : $ strm dweebs daily + : $ strm movies dwee + : $ strm d d 17 It is possible that multiple files are matched by one of the commands. All files are then played in the order of the configured media directories, followed by lexicographical order of the filepath. @@ -74,7 +74,7 @@ This project is also a [[https://nixos.wiki/wiki/Flakes][Nix flake]]. You can execute it with the following command if you have a recent version of [[https://nixos.org/][Nix]] installed and flakes are enabled: - : nix run github:Deleh/strm -- --help + : $ nix run github:Deleh/strm -- --help If you use it this way, mpv is started with *MPRIS* support by default. diff --git a/flake.lock b/flake.lock index 6702fbb..397cc5a 100644 --- a/flake.lock +++ b/flake.lock @@ -1,12 +1,15 @@ { "nodes": { "flake-utils": { + "inputs": { + "systems": "systems" + }, "locked": { - "lastModified": 1631561581, - "narHash": "sha256-3VQMV5zvxaVLvqqUrNz3iJelLw30mIVSfZmAaauM3dA=", + "lastModified": 1694529238, + "narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=", "owner": "numtide", "repo": "flake-utils", - "rev": "7e5bf3925f6fbdfaf50a2a7ca0be2879c4261d19", + "rev": "ff7b65b44d01cf9ba6a71320833626af21126384", "type": "github" }, "original": { @@ -17,15 +20,18 @@ }, "nixpkgs": { "locked": { - "lastModified": 1634115022, - "narHash": "sha256-K9DZMQ47VRrg9gtTPwex5p0E8LnwM/dDkNe7AQW0qj0=", - "path": "/nix/store/fjn0mcw4wcm7lkcn92bzq11f0mzv3xqv-source", - "rev": "564cb4d81d4f734dd068684adec5a60077397fe9", - "type": "path" + "lastModified": 1700794826, + "narHash": "sha256-RyJTnTNKhO0yqRpDISk03I/4A67/dp96YRxc86YOPgU=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "5a09cb4b393d58f9ed0d9ca1555016a8543c2ac8", + "type": "github" }, "original": { - "id": "nixpkgs", - "type": "indirect" + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" } }, "root": { @@ -33,6 +39,21 @@ "flake-utils": "flake-utils", "nixpkgs": "nixpkgs" } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } } }, "root": "root", diff --git a/flake.nix b/flake.nix index 16956ea..7c049e5 100644 --- a/flake.nix +++ b/flake.nix @@ -3,7 +3,10 @@ nixConfig.bash-prompt = "\[\\e[1mstrm-dev\\e[0m:\\w\]$ "; - inputs.flake-utils.url = "github:numtide/flake-utils"; + inputs = { + nixpkgs.url = github:nixos/nixpkgs/nixos-unstable; + flake-utils.url = github:numtide/flake-utils; + }; outputs = { self, nixpkgs, flake-utils }: @@ -13,7 +16,7 @@ pkgs = nixpkgs.legacyPackages.${system}; # Use mpv with scripts - mpv = (pkgs.mpv-with-scripts.override { + mpv = (pkgs.mpv.override { scripts = [ pkgs.mpvScripts.mpris ]; diff --git a/strm b/strm index c05d66d..413aa75 100755 --- a/strm +++ b/strm @@ -154,7 +154,7 @@ while (( "$#" )); do remote_arguments+=("$1") shift ;; - -*|--*=) + -*) error "Unsupported flag: $1" ;; *) @@ -170,7 +170,7 @@ if [ "$remote" != "" ]; then # Check if dependencies are fulfilled on remote if ! ssh "$remote" "command -v mpv strm tmux &>/dev/null"; then - error "make sure ${text_bold}$remote${text_reset} is accessible and mpv, strm and tmux are installed" + error "make sure ${text_bold}$remote${text_reset} is accessible and mpv, strm and tmux are installed" fi # Check if strm tmux session is already running @@ -190,7 +190,7 @@ if [ "$remote" != "" ]; then remote_arguments+=("--is-remote-call") # Execute strm on remote machine - ssh -o ConnectTimeout=10 -t "$remote" "DISPLAY=:0 tmux new-session -s strm 'tmux set-option status off; strm ${remote_arguments[@]}' &>/dev/null" + ssh -o ConnectTimeout=10 -t "$remote" "DISPLAY=:0 tmux new-session -s strm 'tmux set-option status off; strm ${remote_arguments[*]}' &>/dev/null" fi exit fi @@ -253,7 +253,7 @@ if [ "$list" == false ] && [ "$playback_directory" != "" ]; then # Add leading and trailing slash to directory if missing [[ "$directory" != /*/ ]] && directory="/$directory/" - echo -ne "Synchronizing playback directory with $text_bold$(basename $connection_string)$text_reset\n" + echo -ne "Synchronizing playback directory with $text_bold$(basename "$connection_string")$text_reset\n" # Make remote directory if not existent ssh -o ConnectTimeout=10 "$connection_string" "mkdir -p $directory" @@ -272,10 +272,10 @@ if [ "${#queries[@]}" == 0 ]; then fi # Read media directories -IFS="," read -a media_directories <<< "$media_directories" +IFS="," read -ar media_directories <<< "$media_directories" # Read ignore files -IFS="," read -a ignore_files <<< "$ignore_files" +IFS="," read -ar ignore_files <<< "$ignore_files" # Construct find argument array @@ -337,7 +337,7 @@ for media_directory in "${media_directories[@]}"; do # Add leading and trailing slash to directory if missing [[ "$directory" != /*/ ]] && directory="/$directory/" - echo -ne "Fetching results from $text_bold$(basename $directory)$text_reset on $text_bold$connection_string$text_reset\n" + echo -ne "Fetching results from $text_bold$(basename "$directory")$text_reset on $text_bold$connection_string$text_reset\n" # Get search results from remote # Look for paths matching given queries in visible directories, listing only filenames and links @@ -359,7 +359,7 @@ echo if [ "${#sftp_results[@]}" == 0 ]; then if [ "$is_remote_call" == true ]; then echo "No files found, press something to quit" - read -n 1 + read -nr 1 else echo "No files found" fi @@ -389,7 +389,7 @@ if [ "$list" == false ]; then # Save arguments for later call if [ "$playback_directory" != "" ]; then - echo "queries=(${queries[@]})" > "$HOME/.cache/strm/strm_later" + echo "queries=(${queries[*]})" > "$HOME/.cache/strm/strm_later" echo "or=$or" >> "$HOME/.cache/strm/strm_later" echo "shuffle=$shuffle" >> "$HOME/.cache/strm/strm_later" fi @@ -414,6 +414,12 @@ if [ "$list" == false ]; then fi if [ "$playback_directory" != "" ]; then mpv_arguments+=("--save-position-on-quit") + + # Save only the playback position if mpv version is at least 0.34.0 + [[ $(mpv --version | head -n 1) =~ [0-9]+.([0-9]+).[0-9]+ ]] + if [ "${BASH_REMATCH[1]}" -ge 34 ]; then + mpv_arguments+=("--watch-later-options-clr") + fi fi # Play all remote files @@ -441,7 +447,7 @@ if [ "$list" == false ]; then # Add leading and trailing slash to directory if missing [[ "$directory" != /*/ ]] && directory="/$directory/" - echo -ne "\nSynchronizing playback directory with $text_bold$(basename $connection_string)$text_reset" + echo -ne "\nSynchronizing playback directory with $text_bold$(basename "$connection_string")$text_reset" # Synchronize local to remote rsync -az --delete "$HOME/.cache/strm/" "$connection_string:$directory"