mirror of
https://github.com/ksyasuda/aniwrapper.git
synced 2024-10-28 04:44:11 -07:00
Compare commits
6 Commits
f23586116d
...
e851b92289
Author | SHA1 | Date | |
---|---|---|---|
|
e851b92289 | ||
|
04cad2425b | ||
|
d390d0a683 | ||
|
3bfbaa7749 | ||
|
6137deb26b | ||
|
a56fe29a29 |
78
ani-cli
78
ani-cli
@ -11,6 +11,7 @@ DPI=96
|
|||||||
IS_ROFI=1
|
IS_ROFI=1
|
||||||
VERBOSE=0
|
VERBOSE=0
|
||||||
SILENT=0
|
SILENT=0
|
||||||
|
FIRST_EP_NUMBER=1
|
||||||
PLAYER_FN="mpv"
|
PLAYER_FN="mpv"
|
||||||
|
|
||||||
die() {
|
die() {
|
||||||
@ -185,6 +186,9 @@ check_db() {
|
|||||||
watch | sync)
|
watch | sync)
|
||||||
stmt="SELECT DISTINCT COUNT(*) FROM watch_history WHERE anime_name = '$2' AND episode_number = '$3';"
|
stmt="SELECT DISTINCT COUNT(*) FROM watch_history WHERE anime_name = '$2' AND episode_number = '$3';"
|
||||||
;;
|
;;
|
||||||
|
anime)
|
||||||
|
stmt="SELECT DISTINCT COUNT(*) FROM anime WHERE anime_name = '$2';"
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
res=$(run_stmt "$stmt")
|
res=$(run_stmt "$stmt")
|
||||||
return "$res"
|
return "$res"
|
||||||
@ -229,8 +233,10 @@ update_date() {
|
|||||||
watch)
|
watch)
|
||||||
stmt="UPDATE watch_history SET watch_date = '$datetime' WHERE anime_name = '$2' AND episode_number = $3;"
|
stmt="UPDATE watch_history SET watch_date = '$datetime' WHERE anime_name = '$2' AND episode_number = $3;"
|
||||||
;;
|
;;
|
||||||
|
anime)
|
||||||
|
return
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
wait # in case there's another insert/update still running in background?
|
|
||||||
lg "UPDATE STMT -> $stmt"
|
lg "UPDATE STMT -> $stmt"
|
||||||
run_stmt "$stmt"
|
run_stmt "$stmt"
|
||||||
}
|
}
|
||||||
@ -264,9 +270,11 @@ insert_history() {
|
|||||||
sync)
|
sync)
|
||||||
stmt="INSERT INTO watch_history(anime_name, episode_number, watch_date) VALUES('$2', '$3', '$4');"
|
stmt="INSERT INTO watch_history(anime_name, episode_number, watch_date) VALUES('$2', '$3', '$4');"
|
||||||
;;
|
;;
|
||||||
|
anime)
|
||||||
|
stmt="INSERT INTO anime(anime_name, start_episode, end_episode, data_date) VALUES('$2', $3, $4, '$datetime');"
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
lg "INSERT STATEMENT -> $stmt"
|
lg "INSERT STATEMENT -> $stmt"
|
||||||
wait # in case there's another insert/update still running in background
|
|
||||||
run_stmt "$stmt"
|
run_stmt "$stmt"
|
||||||
res=$?
|
res=$?
|
||||||
fi
|
fi
|
||||||
@ -320,7 +328,7 @@ play_file() {
|
|||||||
if [[ "$1" =~ (\.mp4|\.mkv|\.ts|\.webm)$ ]]; then
|
if [[ "$1" =~ (\.mp4|\.mkv|\.ts|\.webm)$ ]]; then
|
||||||
filename="${1##*/}"
|
filename="${1##*/}"
|
||||||
directory="${1%/*}"
|
directory="${1%/*}"
|
||||||
insert_history "file" "$directory" "$filename" &
|
insert_history "file" "$directory" "$filename"
|
||||||
notification "Playing $1"
|
notification "Playing $1"
|
||||||
case "$PLAYER_FN" in
|
case "$PLAYER_FN" in
|
||||||
mpv)
|
mpv)
|
||||||
@ -468,13 +476,26 @@ search_anime() {
|
|||||||
|
|
||||||
search_eps() {
|
search_eps() {
|
||||||
anime_id=$1
|
anime_id=$1
|
||||||
curl -s "$BASE_URL/category/$anime_id" |
|
if ! check_db "anime" "$anime_id"; then
|
||||||
sed -n -E '
|
FIRST_EP_NUMBER="$(run_stmt "SELECT start_episode FROM anime WHERE anime_name = '$anime_id';")"
|
||||||
/^[[:space:]]*<a href="#" class="active" ep_start/{
|
LAST_EP_NUMBER="$(run_stmt "SELECT end_episode FROM anime WHERE anime_name = '$anime_id';")"
|
||||||
s/.* '\''([0-9]*)'\'' ep_end = '\''([0-9]*)'\''.*/\2/p
|
else
|
||||||
q
|
result=$(get_dpage_link "$anime_id" 0)
|
||||||
}
|
FIRST_EP_NUMBER="${result:-1}"
|
||||||
'
|
LAST_EP_NUMBER=$(curl -s "$BASE_URL/category/$anime_id" |
|
||||||
|
sed -n -E '
|
||||||
|
/^[[:space:]]*<a href="#" class="active" ep_start/{
|
||||||
|
s/.* '\''([0-9]*)'\'' ep_end = '\''([0-9]*)'\''.*/\2/p
|
||||||
|
q
|
||||||
|
}
|
||||||
|
')
|
||||||
|
lg "Anime $anime_id not in anime database... inserting into database" > /dev/stderr
|
||||||
|
insert_history "anime" "$anime_id" "$FIRST_EP_NUMBER" "$LAST_EP_NUMBER"
|
||||||
|
fi
|
||||||
|
FIRST_EP_NUMBER="${FIRST_EP_NUMBER%% }"
|
||||||
|
LAST_EP_NUMBER="${LAST_EP_NUMBER%% }"
|
||||||
|
lg "FIRST EP NUMBER: $FIRST_EP_NUMBER"
|
||||||
|
lg "LAST EP NUMBER: $LAST_EP_NUMBER"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Select anime from query results
|
# Select anime from query results
|
||||||
@ -505,6 +526,7 @@ anime_selection() {
|
|||||||
die "Quitting"
|
die "Quitting"
|
||||||
elif ((choice == --cnt)); then
|
elif ((choice == --cnt)); then
|
||||||
stream
|
stream
|
||||||
|
return $?
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
count=1
|
count=1
|
||||||
@ -529,15 +551,14 @@ anime_selection() {
|
|||||||
done <<< "$search_results"
|
done <<< "$search_results"
|
||||||
|
|
||||||
[[ -z "$selection_id" ]] && die "Invalid number entered"
|
[[ -z "$selection_id" ]] && die "Invalid number entered"
|
||||||
insert_history "search" "$selection_id" &
|
insert_history "search" "$selection_id"
|
||||||
|
lg "Selection: $selection_id"
|
||||||
read -r last_ep_number < <(search_eps "$selection_id")
|
search_eps "$anime_id"
|
||||||
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
episode_selection() {
|
episode_selection() {
|
||||||
ep_choice_start=1 first_ep_number=0
|
ep_choice_start=1
|
||||||
result=$(get_dpage_link "$anime_id" "$first_ep_number")
|
|
||||||
[[ -z "$result" ]] && first_ep_number=1
|
|
||||||
if ((IS_ROFI == 1)); then
|
if ((IS_ROFI == 1)); then
|
||||||
lg "Anime ID: $anime_id"
|
lg "Anime ID: $anime_id"
|
||||||
stmt="SELECT DISTINCT episode_number FROM watch_history WHERE anime_name = '$anime_id';"
|
stmt="SELECT DISTINCT episode_number FROM watch_history WHERE anime_name = '$anime_id';"
|
||||||
@ -554,21 +575,21 @@ episode_selection() {
|
|||||||
msg2="Range of episodes can be provided as: START_EPISODE - END_EPISODE"
|
msg2="Range of episodes can be provided as: START_EPISODE - END_EPISODE"
|
||||||
[[ "$is_download" -eq 1 ]] && msg=$(printf "%s\n%s" "$(generate_span "$msg1")" "$(generate_span "$msg2")") || msg=$(printf "%s\n" "$(generate_span "$msg1")")
|
[[ "$is_download" -eq 1 ]] && msg=$(printf "%s\n%s" "$(generate_span "$msg1")" "$(generate_span "$msg2")") || msg=$(printf "%s\n" "$(generate_span "$msg1")")
|
||||||
choice=$(
|
choice=$(
|
||||||
seq "$first_ep_number" "$last_ep_number" |
|
seq "$FIRST_EP_NUMBER" "$LAST_EP_NUMBER" |
|
||||||
rofi -dpi "$DPI" -dmenu -l 12 \
|
rofi -dpi "$DPI" -dmenu -l 12 \
|
||||||
-theme-str 'window {width: 45%;}' \
|
-theme-str 'window {width: 45%;}' \
|
||||||
-a "$watch_history" \
|
-a "$watch_history" \
|
||||||
-p "Select Episode [$first_ep_number, $last_ep_number]:" \
|
-p "Select Episode [$FIRST_EP_NUMBER, $LAST_EP_NUMBER]:" \
|
||||||
-mesg "$msg" -window-title 'aniwrapper' \
|
-mesg "$msg" -window-title 'aniwrapper' \
|
||||||
-config "$ROFI_CFG"
|
-config "$ROFI_CFG"
|
||||||
)
|
)
|
||||||
ep_choice_start=$(printf '%s\n' "${choice}" | awk '{print $1}')
|
ep_choice_start=$(printf '%s\n' "${choice}" | awk '{print $1}')
|
||||||
ep_choice_end=$(printf '%s\n' "${choice}" | awk '{print $NF}')
|
ep_choice_end=$(printf '%s\n' "${choice}" | awk '{print $NF}')
|
||||||
lg "START: $ep_choice_start | END: $ep_choice_end"
|
lg "START: $ep_choice_start | END: $ep_choice_end"
|
||||||
elif ((last_ep_number > 1)); then
|
elif ((LAST_EP_NUMBER > 1)); then
|
||||||
[[ "$is_download" -eq 1 ]] &&
|
[[ "$is_download" -eq 1 ]] &&
|
||||||
inf "Range of episodes can be specified: start_number end_number"
|
inf "Range of episodes can be specified: start_number end_number"
|
||||||
prompt "Choose episode" "[$first_ep_number-$last_ep_number]"
|
prompt "Choose episode" "[$FIRST_EP_NUMBER-$LAST_EP_NUMBER]"
|
||||||
read -r ep_choice_start ep_choice_end
|
read -r ep_choice_start ep_choice_end
|
||||||
[[ -z "$ep_choice_end" ]] && ep_choice_end="$ep_choice_start"
|
[[ -z "$ep_choice_end" ]] && ep_choice_end="$ep_choice_start"
|
||||||
fi
|
fi
|
||||||
@ -578,7 +599,7 @@ episode_selection() {
|
|||||||
ep_choice_start=$(echo "$ep_choice_start" | awk '{ printf substr($0, 2) }')
|
ep_choice_start=$(echo "$ep_choice_start" | awk '{ printf substr($0, 2) }')
|
||||||
ep_choice_end=$ep_choice_start
|
ep_choice_end=$ep_choice_start
|
||||||
fi
|
fi
|
||||||
if (((ep_choice_start <= 0 || ep_choice_start > last_ep_number) || ep_choice_end < ep_choice_start || ep_choice_end > last_ep_number)); then
|
if (((ep_choice_start <= 0 || ep_choice_start > LAST_EP_NUMBER) || ep_choice_end < ep_choice_start || ep_choice_end > LAST_EP_NUMBER)); then
|
||||||
die "Invalid episode/range entered: ep_start -> $ep_choice_start | ep_end -> $ep_choice_end"
|
die "Invalid episode/range entered: ep_start -> $ep_choice_start | ep_end -> $ep_choice_end"
|
||||||
fi
|
fi
|
||||||
# if only one episode was entered, set ep_choice_end to empty string so only selected episode plays
|
# if only one episode was entered, set ep_choice_end to empty string so only selected episode plays
|
||||||
@ -597,7 +618,7 @@ open_episode() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Don't update watch history if downloading episode
|
# Don't update watch history if downloading episode
|
||||||
(("$is_download" == 0)) && insert_history "watch" "$anime_id" "$episode" &
|
(("$is_download" == 0)) && insert_history "watch" "$anime_id" "$episode"
|
||||||
|
|
||||||
lg "Getting data for episode $episode"
|
lg "Getting data for episode $episode"
|
||||||
dpage_link=$(get_dpage_link "$anime_id" "$episode")
|
dpage_link=$(get_dpage_link "$anime_id" "$episode")
|
||||||
@ -679,10 +700,9 @@ stream() {
|
|||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
selection_id="$anime_id"
|
selection_id="$anime_id"
|
||||||
insert_history "search" "$anime_id" &
|
insert_history "search" "$anime_id"
|
||||||
read -r last_ep_number < <(search_eps "$anime_id")
|
search_eps "$anime_id"
|
||||||
fi
|
fi
|
||||||
lg "LAST EP NUMBER -> $last_ep_number"
|
|
||||||
episode_selection
|
episode_selection
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -858,14 +878,14 @@ main() {
|
|||||||
episode=${ep_choice_end:-$ep_choice_start}
|
episode=${ep_choice_end:-$ep_choice_start}
|
||||||
choice=''
|
choice=''
|
||||||
while :; do
|
while :; do
|
||||||
inf "Currently playing $selection_id episode" "${episode// /}/$last_ep_number"
|
inf "Currently playing $selection_id episode" "${episode// /}/$LAST_EP_NUMBER"
|
||||||
if ((episode != last_ep_number)); then
|
if ((episode != LAST_EP_NUMBER)); then
|
||||||
menu_line_alternate "next episode" "n"
|
menu_line_alternate "next episode" "n"
|
||||||
fi
|
fi
|
||||||
if ((episode != first_ep_number)); then
|
if ((episode != FIRST_EP_NUMBER)); then
|
||||||
menu_line_alternate "previous episode" "p"
|
menu_line_alternate "previous episode" "p"
|
||||||
fi
|
fi
|
||||||
if ((first_ep_number != last_ep_number)); then
|
if ((FIRST_EP_NUMBER != LAST_EP_NUMBER)); then
|
||||||
menu_line_alternate "select episode" "s"
|
menu_line_alternate "select episode" "s"
|
||||||
fi
|
fi
|
||||||
menu_line_alternate "replay current episode" "r"
|
menu_line_alternate "replay current episode" "r"
|
||||||
|
@ -395,10 +395,11 @@ main() {
|
|||||||
# -----------------------------------------------------------------
|
# -----------------------------------------------------------------
|
||||||
[ -z "$THEMES" ] && seppuku "No themes provided... exiting"
|
[ -z "$THEMES" ] && seppuku "No themes provided... exiting"
|
||||||
theme_idx="$(get_theme_idx)"
|
theme_idx="$(get_theme_idx)"
|
||||||
|
lg "Theme index: $theme_idx"
|
||||||
|
lg "NUM THEMES: $NUM_THEMES"
|
||||||
choice=$(rofi -dmenu -config "$CFG_FILE" -dpi "$DPI" -window-title 'aniwrapper' \
|
choice=$(rofi -dmenu -config "$CFG_FILE" -dpi "$DPI" -window-title 'aniwrapper' \
|
||||||
-theme-str 'listview {columns: 1;} window {width: 45%;}' \
|
-theme-str 'listview {columns: 2;} window {width: 45%;}' \
|
||||||
-no-custom -l 4 -i -p "Choose theme: " -sep '|' \
|
-no-custom -l 5 -i -p "Choose theme: " -sep '|' \
|
||||||
-theme-str 'listview { columns: 2; }' \
|
|
||||||
-a "$theme_idx" -selected-row "$theme_idx" <<< "$THEMES")
|
-a "$theme_idx" -selected-row "$theme_idx" <<< "$THEMES")
|
||||||
theme=$(awk '{ print $1 }' <<< "$choice")
|
theme=$(awk '{ print $1 }' <<< "$choice")
|
||||||
set_theme "$theme"
|
set_theme "$theme"
|
||||||
|
@ -72,7 +72,7 @@ Run a query on the history databse
|
|||||||
Enable silent mode (suppress all output) [cannot be used with
|
Enable silent mode (suppress all output) [cannot be used with
|
||||||
\f[B]-v\f[R]]
|
\f[B]-v\f[R]]
|
||||||
.TP
|
.TP
|
||||||
\f[B]-t\f[R] \f[I]aniwrapper (default)|dracula|doomone|fancy|flamingo|material|nord|onedark\f[R]
|
\f[B]-t\f[R] \f[I]alter|aniwrapper (default)|dracula|doomone|fancy|flamingo|material|monokai|nord|onedark\f[R]
|
||||||
Choose theme from presets
|
Choose theme from presets
|
||||||
.TP
|
.TP
|
||||||
\f[B]-T\f[R] \f[I]path_to_theme\f[R]
|
\f[B]-T\f[R] \f[I]path_to_theme\f[R]
|
||||||
|
@ -59,7 +59,7 @@ Defaults:
|
|||||||
**-S**
|
**-S**
|
||||||
: Enable silent mode (suppress all output) [cannot be used with **-v**]
|
: Enable silent mode (suppress all output) [cannot be used with **-v**]
|
||||||
|
|
||||||
**-t** _aniwrapper (default)|dracula|doomone|fancy|flamingo|material|nord|onedark_
|
**-t** _alter|aniwrapper (default)|dracula|doomone|fancy|flamingo|material|monokai|nord|onedark_
|
||||||
: Choose theme from presets
|
: Choose theme from presets
|
||||||
|
|
||||||
**-T** _path_to_theme_
|
**-T** _path_to_theme_
|
||||||
|
10
setup.sh
10
setup.sh
@ -43,13 +43,9 @@ run_setup() {
|
|||||||
log "Directory created"
|
log "Directory created"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ ! -f "$DIR/$DB" ]]; then
|
log "CREATING HISTORY DATABASE IF NOT EXISTS"
|
||||||
log "CREATING HISTORY DATABASE"
|
sqlite3 "$DIR/$DB" < sql/history.sql
|
||||||
sqlite3 "$DIR/$DB" < sql/search_history_tbl.sql
|
log "FINISHED CREATING DB"
|
||||||
sqlite3 "$DIR/$DB" < sql/watch_history_tbl.sql
|
|
||||||
sqlite3 "$DIR/$DB" < sql/file_history.sql
|
|
||||||
log "FINISHED CREATING DB"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# log "themes directory does not exist in filesystem... Creating and moving themes"
|
# log "themes directory does not exist in filesystem... Creating and moving themes"
|
||||||
mkdir -p "$DIR/themes"
|
mkdir -p "$DIR/themes"
|
||||||
|
@ -1,12 +0,0 @@
|
|||||||
CREATE TABLE IF NOT EXISTS file_history (
|
|
||||||
id integer PRIMARY KEY AUTOINCREMENT,
|
|
||||||
directory varchar(200) NOT NULL,
|
|
||||||
filename varchar(200) NOT NULL,
|
|
||||||
watch_date DATETIME NOT NULL,
|
|
||||||
CHECK (LENGTH(directory) > 0),
|
|
||||||
CHECK (LENGTH(filename) > 0),
|
|
||||||
UNIQUE (directory, filename)
|
|
||||||
);
|
|
||||||
|
|
||||||
CREATE UNIQUE INDEX IF NOT EXISTS dir_filename_idx ON file_history (directory, filename);
|
|
||||||
|
|
40
sql/history.sql
Normal file
40
sql/history.sql
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
CREATE TABLE IF NOT EXISTS anime (
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
anime_name VARCHAR(255) NOT NULL UNIQUE,
|
||||||
|
start_episode INTEGER NOT NULL,
|
||||||
|
end_episode INTEGER NOT NULL,
|
||||||
|
data_date DATETIME NOT NULL,
|
||||||
|
CHECK(start_episode <= end_episode),
|
||||||
|
CHECK(LENGTH(anime_name) > 0)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS file_history (
|
||||||
|
id integer PRIMARY KEY AUTOINCREMENT,
|
||||||
|
directory varchar(200) NOT NULL,
|
||||||
|
filename varchar(200) NOT NULL,
|
||||||
|
watch_date DATETIME NOT NULL,
|
||||||
|
CHECK (LENGTH(directory) > 0),
|
||||||
|
CHECK (LENGTH(filename) > 0),
|
||||||
|
UNIQUE (directory, filename)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS watch_history (
|
||||||
|
id integer PRIMARY KEY AUTOINCREMENT,
|
||||||
|
anime_name varchar(200) NOT NULL,
|
||||||
|
episode_number integer NOT NULL,
|
||||||
|
watch_date DATETIME NOT NULL,
|
||||||
|
CHECK (LENGTH(anime_name) > 0),
|
||||||
|
CHECK (episode_number > 0),
|
||||||
|
UNIQUE (anime_name, episode_number, watch_date)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS search_history (
|
||||||
|
id integer PRIMARY KEY AUTOINCREMENT,
|
||||||
|
anime_name varchar(200) NOT NULL UNIQUE,
|
||||||
|
search_date DATETIME NOT NULL,
|
||||||
|
CHECK (LENGTH(anime_name) > 0)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE UNIQUE INDEX IF NOT EXISTS anime_search_idx ON search_history (anime_name, search_date);
|
||||||
|
CREATE UNIQUE INDEX IF NOT EXISTS watch_anime_episode_idx ON watch_history (anime_name, episode_number);
|
||||||
|
CREATE UNIQUE INDEX IF NOT EXISTS dir_filename_idx ON file_history (directory, filename);
|
@ -1,9 +0,0 @@
|
|||||||
CREATE TABLE search_history (
|
|
||||||
id integer PRIMARY KEY AUTOINCREMENT,
|
|
||||||
anime_name varchar(200) NOT NULL UNIQUE,
|
|
||||||
search_date DATETIME NOT NULL,
|
|
||||||
CHECK (LENGTH(anime_name) > 0)
|
|
||||||
);
|
|
||||||
|
|
||||||
CREATE UNIQUE INDEX anime_search_idx ON search_history (anime_name, search_date);
|
|
||||||
|
|
@ -1,12 +0,0 @@
|
|||||||
CREATE TABLE watch_history (
|
|
||||||
id integer PRIMARY KEY AUTOINCREMENT,
|
|
||||||
anime_name varchar(200) NOT NULL,
|
|
||||||
episode_number integer NOT NULL,
|
|
||||||
watch_date DATETIME NOT NULL,
|
|
||||||
CHECK (LENGTH(anime_name) > 0),
|
|
||||||
CHECK (episode_number > 0),
|
|
||||||
UNIQUE (anime_name, episode_number, watch_date)
|
|
||||||
);
|
|
||||||
|
|
||||||
CREATE UNIQUE INDEX IF NOT EXISTS watch_anime_episode_idx ON watch_history (anime_name, episode_number);
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user