blob: ba747283d36cede811ab3e951820eadeb8447544 (
plain)
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
|
#!/bin/bash
BOOKMARKS_FILE="$HOME/.config/mpv/bookmarks.json"
MATH_RIKA_FILE="$HOME/.local/bin/mt_play"
COMP_SCI_FILE="$HOME/.local/bin/cs_play"
TVSHOW_FILE="$HOME/.local/bin/bookmarked_play"
ANIME_FILE="$HOME/.local/bin/anime_play"
MOVIE_FILE="$HOME/.local/bin/movie_play"
# Function to check if jq is installed
check_jq() {
if ! command -v jq &> /dev/null; then
echo "jq is not installed. Please install it to parse JSON."
exit 1
fi
}
# Function to get the last bookmark number
get_last_bookmark_number() {
if [ ! -f "$BOOKMARKS_FILE" ] || [ "$(jq 'keys | length' "$BOOKMARKS_FILE")" -eq 0 ]; then
echo "0"
else
jq 'keys | map(tonumber) | max' "$BOOKMARKS_FILE"
fi
}
# Function to get absolute path
get_absolute_path() {
local path="$1"
if [[ "$path" = /* ]]; then
echo "$path"
else
echo "$(pwd)/$path"
fi
}
# Function to add new bookmark to the bookmarks.json file
add_new_bookmark() {
local filepath="$1"
local title="$2"
local bookmark_num="$3"
local pos=0 # Starting position for new bookmarks
local filename="$(basename "$filepath")"
# Ensure bookmarks file exists
if [ ! -f "$BOOKMARKS_FILE" ]; then
echo "{}" > "$BOOKMARKS_FILE"
fi
jq --arg num "$bookmark_num" \
--arg filename "$filename" \
--arg filepath "$filepath" \
--arg title "$title" \
--argjson pos "$pos" \
'.[$num] = {filename: $filename, pos: $pos, filepath: $filepath, title: $title}' \
"$BOOKMARKS_FILE" > "${BOOKMARKS_FILE}.tmp" && mv "${BOOKMARKS_FILE}.tmp" "$BOOKMARKS_FILE"
echo "Bookmark details added to $BOOKMARKS_FILE"
}
# Main script
check_jq
if [ "$#" -ne 1 ]; then
echo "Usage: $0 <filename>"
exit 1
fi
filename="$1"
filepath=$(get_absolute_path "$filename")
title="$filename"
# Determine which category the file belongs to
if [[ "$filepath" == */Videos/maths_and_rika/* ]]; then
category="maths_and_rika"
elif [[ "$filepath" == */Videos/computer_science/* ]]; then
category="computer_science"
elif [[ "$filepath" == */Videos/variety_and_shows/* ]]; then
category="variety_and_shows"
elif [[ "$filepath" == */Videos/anime/* ]]; then
category="anime"
elif [[ "$filepath" == */Videos/movies/* ]]; then
category="movies"
else
category="other"
fi
# Create a bookmark if the file is in the specified directories
if [ "$category" != "other" ]; then
bookmark_num=$(get_last_bookmark_number)
bookmark_num=$((bookmark_num + 1))
echo "Added new bookmark with number $bookmark_num"
add_new_bookmark "$filepath" "$title" "$bookmark_num"
is_new_bookmark=1
else
# For files not in specified directories, do not create a bookmark
echo "File is not in a specified directory; not creating a bookmark."
is_new_bookmark=0
bookmark_num=""
fi
# Execute mpv based on the category
if [ "$category" == "maths_and_rika" ]; then
if [ "$is_new_bookmark" -eq 1 ]; then
echo "mpv_launcher --x11-name=mpv_2 --pause --script-opts=bookmarker-start_bookmark=$bookmark_num \"$filepath\" &" >> "$MATH_RIKA_FILE"
echo "Added to math and rika bookmarks file"
fi
mpv_launcher --x11-name=mpv_2 --script-opts=bookmarker-start_bookmark=$bookmark_num "$filepath" &
xdo activate -n mpv_2
elif [ "$category" == "computer_science" ]; then
if [ "$is_new_bookmark" -eq 1 ]; then
echo "mpv_launcher --x11-name=mpv_1 --pause --script-opts=bookmarker-start_bookmark=$bookmark_num \"$filepath\" &" >> "$COMP_SCI_FILE"
echo "Added to computer science bookmarks file"
fi
mpv_launcher --x11-name=mpv_1 --script-opts=bookmarker-start_bookmark=$bookmark_num "$filepath" &
xdo activate -n mpv_1
elif [ "$category" == "variety_and_shows" ]; then
if [ "$is_new_bookmark" -eq 1 ]; then
echo "mpv_launcher --x11-name=mpv_3 --pause --script-opts=bookmarker-start_bookmark=$bookmark_num \"$filepath\" &" >> "$TVSHOW_FILE"
echo "Added to TV shows bookmarks file"
fi
mpv_launcher --x11-name=mpv_3 --script-opts=bookmarker-start_bookmark=$bookmark_num "$filepath" &
xdo activate -n mpv_3
elif [ "$category" == "anime" ]; then
if [ "$is_new_bookmark" -eq 1 ]; then
echo "mpv_launcher --x11-name=mpv_4 --pause --script-opts=bookmarker-start_bookmark=$bookmark_num \"$filepath\" &" >> "$ANIME_FILE"
echo "Added to anime bookmarks file"
fi
mpv_launcher --x11-name=mpv_4 --script-opts=bookmarker-start_bookmark=$bookmark_num "$filepath" &
xdo activate -n mpv_4
elif [ "$category" == "movies" ]; then
if [ "$is_new_bookmark" -eq 1 ]; then
echo "mpv_launcher --x11-name=mpv_5 --pause --script-opts=bookmarker-start_bookmark=$bookmark_num \"$filepath\" &" >> "$MOVIE_FILE"
echo "Added to movies bookmarks file"
fi
mpv_launcher --x11-name=mpv_5 --script-opts=bookmarker-start_bookmark=$bookmark_num "$filepath" &
xdo activate -n mpv_5
else
# For files not in specified directories, use start_mpv without bookmarks
echo "Launching mpv without bookmarks."
start_mpv "$filepath" &
fi
echo "MPV launched with appropriate settings"
|