-
Notifications
You must be signed in to change notification settings - Fork 2
/
moviecli.sh
executable file
·96 lines (77 loc) · 3.2 KB
/
moviecli.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/bin/bash
########################################################################################################
########################################### MovieCLI ###################################################
########################################################################################################
# Original script idea using fzf from Jake@Linux. Adapted by The Linux Cast for movie watching reasons.
#
# Updated to pull in movies from remote server using sshfs by Jereme Hancock (jeremehancock.com).
#
# Portions of this script were generated by ChatGPT.
#
# Dependencies: fzf, mpv, sshfs
########################################################################################################
########################################### Variables ##################################################
########################################################################################################
# Local base path for mounting drives (Be sure to include trailing slash)
LOCAL_BASE="/tmp/"
# Full base path for movie directories (Be sure to include trailing slash)
REMOTE_BASE="/home/username/plex/"
# Remote movie directories located inside the path defined in REMOTE_BASE (Be sure to not include any slashes)
MOVIE_DIRS=("movies" "movies-2")
# Remote server ex: username@hostname
SERVER="username@hostname"
########################################################################################################
################################### DO NOT EDIT ANYTHING BELOW #########################################
########################################################################################################
# Check dependencies
check_dependencies() {
local DEPENDENCIES=("fzf" "mpv" "sshfs")
for DEPENDENCY in "${DEPENDENCIES[@]}"; do
if ! command -v "$DEPENDENCY" >/dev/null 2>&1; then
echo "Error: $DEPENDENCY is required but not found. Please install it and try again." >&2
exit 1
fi
done
}
# Run dependency check
check_dependencies
# Mount movie directories if they are not already mounted
mount_movie_directories() {
for DIR in "${MOVIE_DIRS[@]}"; do
if ! mountpoint -q "$LOCAL_BASE$DIR"; then
sshfs -o default_permissions "$SERVER:$REMOTE_BASE$DIR" "$LOCAL_BASE$DIR"
fi
done
}
# Unmount movie directories if they are mounted
unmount_movie_directories() {
for DIR in "${MOVIE_DIRS[@]}"; do
if mountpoint -q "$LOCAL_BASE$DIR"; then
umount "$LOCAL_BASE$DIR" >/dev/null 2>&1
fi
done
}
# Create local mount points if they are not already created
create_movie_directories() {
for DIR in "${MOVIE_DIRS[@]}"; do
if [ ! -d "$LOCAL_BASE$DIR" ]; then
mkdir -p "$LOCAL_BASE$DIR"
fi
done
}
# Run create movie directories function
create_movie_directories
# Run movie directory mounting function
mount_movie_directories
# Create terminal menu
MENU=$(for DIR in "${MOVIE_DIRS[@]}"; do ls "$LOCAL_BASE$DIR"; done | sort | uniq -u | fzf --height=100% --reverse --header-first)
# Run mpv on the selected movie
if [[ -n "$MENU" ]]; then
for DIR in "${MOVIE_DIRS[@]}"; do
if mpv "$LOCAL_BASE$DIR/${MENU[@]/#/}" >/dev/null 2>&1; then
break
fi
done
fi
# Run movie directory unmounting function
unmount_movie_directories