mirror of
https://github.com/ksyasuda/aniwrapper.git
synced 2024-10-28 04:44:11 -07:00
Compare commits
No commits in common. "e851b922896804dcd4317151e264286544cac45e" and "f23586116d08a8149d15037e984670dc5612589d" have entirely different histories.
e851b92289
...
f23586116d
68
ani-cli
68
ani-cli
@ -11,7 +11,6 @@ DPI=96
|
||||
IS_ROFI=1
|
||||
VERBOSE=0
|
||||
SILENT=0
|
||||
FIRST_EP_NUMBER=1
|
||||
PLAYER_FN="mpv"
|
||||
|
||||
die() {
|
||||
@ -186,9 +185,6 @@ check_db() {
|
||||
watch | sync)
|
||||
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
|
||||
res=$(run_stmt "$stmt")
|
||||
return "$res"
|
||||
@ -233,10 +229,8 @@ update_date() {
|
||||
watch)
|
||||
stmt="UPDATE watch_history SET watch_date = '$datetime' WHERE anime_name = '$2' AND episode_number = $3;"
|
||||
;;
|
||||
anime)
|
||||
return
|
||||
;;
|
||||
esac
|
||||
wait # in case there's another insert/update still running in background?
|
||||
lg "UPDATE STMT -> $stmt"
|
||||
run_stmt "$stmt"
|
||||
}
|
||||
@ -270,11 +264,9 @@ insert_history() {
|
||||
sync)
|
||||
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
|
||||
lg "INSERT STATEMENT -> $stmt"
|
||||
wait # in case there's another insert/update still running in background
|
||||
run_stmt "$stmt"
|
||||
res=$?
|
||||
fi
|
||||
@ -328,7 +320,7 @@ play_file() {
|
||||
if [[ "$1" =~ (\.mp4|\.mkv|\.ts|\.webm)$ ]]; then
|
||||
filename="${1##*/}"
|
||||
directory="${1%/*}"
|
||||
insert_history "file" "$directory" "$filename"
|
||||
insert_history "file" "$directory" "$filename" &
|
||||
notification "Playing $1"
|
||||
case "$PLAYER_FN" in
|
||||
mpv)
|
||||
@ -476,26 +468,13 @@ search_anime() {
|
||||
|
||||
search_eps() {
|
||||
anime_id=$1
|
||||
if ! check_db "anime" "$anime_id"; then
|
||||
FIRST_EP_NUMBER="$(run_stmt "SELECT start_episode FROM anime WHERE anime_name = '$anime_id';")"
|
||||
LAST_EP_NUMBER="$(run_stmt "SELECT end_episode FROM anime WHERE anime_name = '$anime_id';")"
|
||||
else
|
||||
result=$(get_dpage_link "$anime_id" 0)
|
||||
FIRST_EP_NUMBER="${result:-1}"
|
||||
LAST_EP_NUMBER=$(curl -s "$BASE_URL/category/$anime_id" |
|
||||
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
|
||||
@ -526,7 +505,6 @@ anime_selection() {
|
||||
die "Quitting"
|
||||
elif ((choice == --cnt)); then
|
||||
stream
|
||||
return $?
|
||||
fi
|
||||
else
|
||||
count=1
|
||||
@ -551,14 +529,15 @@ anime_selection() {
|
||||
done <<< "$search_results"
|
||||
|
||||
[[ -z "$selection_id" ]] && die "Invalid number entered"
|
||||
insert_history "search" "$selection_id"
|
||||
lg "Selection: $selection_id"
|
||||
search_eps "$anime_id"
|
||||
return 0
|
||||
insert_history "search" "$selection_id" &
|
||||
|
||||
read -r last_ep_number < <(search_eps "$selection_id")
|
||||
}
|
||||
|
||||
episode_selection() {
|
||||
ep_choice_start=1
|
||||
ep_choice_start=1 first_ep_number=0
|
||||
result=$(get_dpage_link "$anime_id" "$first_ep_number")
|
||||
[[ -z "$result" ]] && first_ep_number=1
|
||||
if ((IS_ROFI == 1)); then
|
||||
lg "Anime ID: $anime_id"
|
||||
stmt="SELECT DISTINCT episode_number FROM watch_history WHERE anime_name = '$anime_id';"
|
||||
@ -575,21 +554,21 @@ episode_selection() {
|
||||
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")")
|
||||
choice=$(
|
||||
seq "$FIRST_EP_NUMBER" "$LAST_EP_NUMBER" |
|
||||
seq "$first_ep_number" "$last_ep_number" |
|
||||
rofi -dpi "$DPI" -dmenu -l 12 \
|
||||
-theme-str 'window {width: 45%;}' \
|
||||
-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' \
|
||||
-config "$ROFI_CFG"
|
||||
)
|
||||
ep_choice_start=$(printf '%s\n' "${choice}" | awk '{print $1}')
|
||||
ep_choice_end=$(printf '%s\n' "${choice}" | awk '{print $NF}')
|
||||
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 ]] &&
|
||||
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
|
||||
[[ -z "$ep_choice_end" ]] && ep_choice_end="$ep_choice_start"
|
||||
fi
|
||||
@ -599,7 +578,7 @@ episode_selection() {
|
||||
ep_choice_start=$(echo "$ep_choice_start" | awk '{ printf substr($0, 2) }')
|
||||
ep_choice_end=$ep_choice_start
|
||||
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"
|
||||
fi
|
||||
# if only one episode was entered, set ep_choice_end to empty string so only selected episode plays
|
||||
@ -618,7 +597,7 @@ open_episode() {
|
||||
fi
|
||||
|
||||
# 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"
|
||||
dpage_link=$(get_dpage_link "$anime_id" "$episode")
|
||||
@ -700,9 +679,10 @@ stream() {
|
||||
fi
|
||||
else
|
||||
selection_id="$anime_id"
|
||||
insert_history "search" "$anime_id"
|
||||
search_eps "$anime_id"
|
||||
insert_history "search" "$anime_id" &
|
||||
read -r last_ep_number < <(search_eps "$anime_id")
|
||||
fi
|
||||
lg "LAST EP NUMBER -> $last_ep_number"
|
||||
episode_selection
|
||||
}
|
||||
|
||||
@ -878,14 +858,14 @@ main() {
|
||||
episode=${ep_choice_end:-$ep_choice_start}
|
||||
choice=''
|
||||
while :; do
|
||||
inf "Currently playing $selection_id episode" "${episode// /}/$LAST_EP_NUMBER"
|
||||
if ((episode != LAST_EP_NUMBER)); then
|
||||
inf "Currently playing $selection_id episode" "${episode// /}/$last_ep_number"
|
||||
if ((episode != last_ep_number)); then
|
||||
menu_line_alternate "next episode" "n"
|
||||
fi
|
||||
if ((episode != FIRST_EP_NUMBER)); then
|
||||
if ((episode != first_ep_number)); then
|
||||
menu_line_alternate "previous episode" "p"
|
||||
fi
|
||||
if ((FIRST_EP_NUMBER != LAST_EP_NUMBER)); then
|
||||
if ((first_ep_number != last_ep_number)); then
|
||||
menu_line_alternate "select episode" "s"
|
||||
fi
|
||||
menu_line_alternate "replay current episode" "r"
|
||||
|
@ -395,11 +395,10 @@ main() {
|
||||
# -----------------------------------------------------------------
|
||||
[ -z "$THEMES" ] && seppuku "No themes provided... exiting"
|
||||
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' \
|
||||
-theme-str 'listview {columns: 2;} window {width: 45%;}' \
|
||||
-no-custom -l 5 -i -p "Choose theme: " -sep '|' \
|
||||
-theme-str 'listview {columns: 1;} window {width: 45%;}' \
|
||||
-no-custom -l 4 -i -p "Choose theme: " -sep '|' \
|
||||
-theme-str 'listview { columns: 2; }' \
|
||||
-a "$theme_idx" -selected-row "$theme_idx" <<< "$THEMES")
|
||||
theme=$(awk '{ print $1 }' <<< "$choice")
|
||||
set_theme "$theme"
|
||||
|
@ -72,7 +72,7 @@ Run a query on the history databse
|
||||
Enable silent mode (suppress all output) [cannot be used with
|
||||
\f[B]-v\f[R]]
|
||||
.TP
|
||||
\f[B]-t\f[R] \f[I]alter|aniwrapper (default)|dracula|doomone|fancy|flamingo|material|monokai|nord|onedark\f[R]
|
||||
\f[B]-t\f[R] \f[I]aniwrapper (default)|dracula|doomone|fancy|flamingo|material|nord|onedark\f[R]
|
||||
Choose theme from presets
|
||||
.TP
|
||||
\f[B]-T\f[R] \f[I]path_to_theme\f[R]
|
||||
|
@ -59,7 +59,7 @@ Defaults:
|
||||
**-S**
|
||||
: Enable silent mode (suppress all output) [cannot be used with **-v**]
|
||||
|
||||
**-t** _alter|aniwrapper (default)|dracula|doomone|fancy|flamingo|material|monokai|nord|onedark_
|
||||
**-t** _aniwrapper (default)|dracula|doomone|fancy|flamingo|material|nord|onedark_
|
||||
: Choose theme from presets
|
||||
|
||||
**-T** _path_to_theme_
|
||||
|
8
setup.sh
8
setup.sh
@ -43,9 +43,13 @@ run_setup() {
|
||||
log "Directory created"
|
||||
fi
|
||||
|
||||
log "CREATING HISTORY DATABASE IF NOT EXISTS"
|
||||
sqlite3 "$DIR/$DB" < sql/history.sql
|
||||
if [[ ! -f "$DIR/$DB" ]]; then
|
||||
log "CREATING HISTORY DATABASE"
|
||||
sqlite3 "$DIR/$DB" < sql/search_history_tbl.sql
|
||||
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"
|
||||
mkdir -p "$DIR/themes"
|
||||
|
12
sql/file_history.sql
Normal file
12
sql/file_history.sql
Normal file
@ -0,0 +1,12 @@
|
||||
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);
|
||||
|
@ -1,40 +0,0 @@
|
||||
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);
|
9
sql/search_history_tbl.sql
Normal file
9
sql/search_history_tbl.sql
Normal file
@ -0,0 +1,9 @@
|
||||
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);
|
||||
|
12
sql/watch_history_tbl.sql
Normal file
12
sql/watch_history_tbl.sql
Normal file
@ -0,0 +1,12 @@
|
||||
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