mirror of
https://github.com/ksyasuda/aniwrapper.git
synced 2024-10-28 04:44:11 -07:00
clean up code and update readme to reflect
This commit is contained in:
parent
bf1a35f869
commit
987e84e9cd
111
README.md
111
README.md
@ -14,20 +14,16 @@ This is a fork of [Dink4n's ani-cli](https://github.com/Dink4n/ani-cli),
|
||||
which itself is a fork of
|
||||
pystardust's [old-ani-cli](https://github.com/pystardust/ani-cli/tree/old-ani-cli)
|
||||
|
||||
This fork is a wrapper around a modified version of ani-cli
|
||||
and uses [rofi](https://github.com/davatorium/rofi) to gather information and control the program
|
||||
|
||||
This fork is a wrapper around a modified version of ani-cli, which uses [rofi](https://github.com/davatorium/rofi)
|
||||
to gather information and control the program.
|
||||
In addition to `rofi`, I've also changed the way saving history works by
|
||||
integrating a local [sqlite3](https://www.sqlite.org/index.html) database with a table for
|
||||
search and watch history
|
||||
|
||||
It is built around Dink4n's fork of ani-cli since at the time of
|
||||
creation, this is the version that has downloading working correctly
|
||||
While this is a fork of a fork of pystardust's old-ani-cli, I would call this more of a light fork of the [the main ani-cli](https://github.com/pystardust/ani-cli).
|
||||
I have implemented most of the main features from the main script and continue to use the same scraping logic
|
||||
|
||||
This tool scrapes the site [gogoanime](https://gogoanime.vc).
|
||||
|
||||
It is intended to be called from the wrapper script `aniwrapper`,
|
||||
however using the ani-cli script itself is also possible
|
||||
This tool scrapes the site [gogoanime](https://gogoanime.cm).
|
||||
|
||||
<!-- markdown-toc start - Don't edit this section. Run M-x markdown-toc-refresh-toc -->
|
||||
|
||||
@ -53,7 +49,7 @@ however using the ani-cli script itself is also possible
|
||||
- [Option 3: Continue](#option-3-continue)
|
||||
- [Option 4: Play from File](#option-4-play-from-file)
|
||||
- [Option 5: Sync History](#option-5-sync-history)
|
||||
- [ani-cli Script](#ani-cli-script)
|
||||
- [ani-cli](#ani-cli)
|
||||
- [Screenshots](#screenshots)
|
||||
|
||||
<!-- markdown-toc end -->
|
||||
@ -62,14 +58,9 @@ however using the ani-cli script itself is also possible
|
||||
|
||||
These are the minimum dependences required to run `aniwrapper`
|
||||
|
||||
- grep
|
||||
- curl
|
||||
- sed
|
||||
- mpv
|
||||
- ffmpeg
|
||||
- rofi
|
||||
- meh.rasi (installed in setup.sh)
|
||||
- sqlite3
|
||||
```
|
||||
curl grep mpv rofi sed sqlite3
|
||||
```
|
||||
|
||||
## Skip Intro Script
|
||||
|
||||
@ -77,7 +68,7 @@ _This repo comes packaged with and will install the
|
||||
[skip-intro.lua](https://github.com/rui-ddc/skip-intro)
|
||||
script for MPV during setup if it is not already installed_
|
||||
|
||||
The script is activated with the `TAB` key
|
||||
**The script is activated with the `TAB` key**
|
||||
|
||||
Upon activation, the skip-intro script will try its best to skip the
|
||||
episode introduction by skipping to the next moment of silence in the video
|
||||
@ -164,30 +155,45 @@ The next menu is where you select the anime to watch from a narrowed down list.
|
||||
|
||||
## Episode Selection
|
||||
|
||||
In the episode selection menu, you can select an individual episode from the list, provide a single episode, or provide a range of episodes as two space separated integers `start_episode end_episode`. Like in the previous menu, any element with a blue border and text-color indicates that episode has been watched before
|
||||
> Half-episodes (ex. saihate-no-paladin episode 7.5) are selectable, however they will not show up in the episodes list.
|
||||
> To select half episodes add 'h' to the beginning for episodes like '7.5' -> 'h7' to select saihate-no-paladin episode 7.5
|
||||
|
||||
This menu will promt you to select the episode(s) to watch/download
|
||||
|
||||
Multiple episodes can be viewed/downloaded by giving the episode range like so
|
||||
|
||||
```
|
||||
Select Episode [1-13]: 1 6
|
||||
```
|
||||
|
||||
This would open/download episodes 1 2 3 4 5 6
|
||||
|
||||
Like in the previous menu, any element with a blue border and text-color indicates that episode has been watched before
|
||||
|
||||
# Usage
|
||||
|
||||
## aniwrapper
|
||||
|
||||
# Launch menu (default video quality: best)
|
||||
aniwrapper
|
||||
```
|
||||
# Launch menu (default video quality: best)
|
||||
aniwrapper
|
||||
|
||||
# Launch menu with quality selection
|
||||
aniwrapper -q
|
||||
# Launch menu with quality selection
|
||||
aniwrapper -q
|
||||
|
||||
# Enable verbose logging
|
||||
aniwrapper -v
|
||||
# Enable verbose logging
|
||||
aniwrapper -v
|
||||
|
||||
# Use ani-cli command-line mode (rofi disabled)
|
||||
aniwrapper -c
|
||||
# Use ani-cli command-line mode (rofi disabled)
|
||||
aniwrapper -c
|
||||
|
||||
# Download anime in command-line mode
|
||||
aniwrapper -d
|
||||
# Download anime in command-line mode
|
||||
aniwrapper -d
|
||||
|
||||
# All flags can be used in command-line mode as well
|
||||
# ex. The following command will launch aniwrapper in command-line download mode with quality selection
|
||||
aniwrapper -cqd
|
||||
# All flags can be used in command-line mode as well
|
||||
# ex. The following command will launch aniwrapper in command-line download mode with quality selection
|
||||
aniwrapper -cqd
|
||||
```
|
||||
|
||||
### Option 1: Streaming
|
||||
|
||||
@ -220,37 +226,24 @@ At the moment, the requirements are as follows:
|
||||
- The username must be the same across both devices
|
||||
- The `history.sqlite3` file must be in the default location: `$XDG_CONFIG_HOME/aniwrapper/history.sqlite3`
|
||||
|
||||
## ani-cli Script
|
||||
## ani-cli
|
||||
|
||||
# watch anime
|
||||
ani-cli <query>
|
||||
```
|
||||
# watch anime
|
||||
ani-cli <query>
|
||||
|
||||
# download anime
|
||||
ani-cli -d <download_directory>
|
||||
# download anime
|
||||
ani-cli -d <download_directory>
|
||||
|
||||
# resume watching anime
|
||||
ani-cli -H
|
||||
# resume watching anime
|
||||
ani-cli -H
|
||||
|
||||
# list searched anime
|
||||
ani-cli -l
|
||||
# sync history across devices
|
||||
ani-cli -s
|
||||
|
||||
# playlist mode
|
||||
ani-cli -P
|
||||
|
||||
# add to playlist
|
||||
ani-cli -a
|
||||
|
||||
# sync history across devices
|
||||
ani-cli -s
|
||||
|
||||
# run ani-cli in command-line mode (rofi disabled)
|
||||
ani-cli -c
|
||||
|
||||
Multiple episodes can be viewed/downloaded by giving the episode range like so
|
||||
|
||||
Choose episode [1-13]: 1 6
|
||||
|
||||
This would open/download episodes 1 2 3 4 5 6
|
||||
# run ani-cli in command-line mode (rofi disabled)
|
||||
ani-cli -c
|
||||
```
|
||||
|
||||
# Screenshots
|
||||
|
||||
|
186
ani-cli
186
ani-cli
@ -223,9 +223,11 @@ update_date() {
|
||||
datetime=$(date +'%Y-%m-%d %H:%M:%S')
|
||||
stmt=""
|
||||
if [[ "$2" == "search" ]]; then
|
||||
log "UPDATING SEARCH_HISTORY: anime_name='$1', search_date='$datetime'"
|
||||
stmt="UPDATE search_history SET search_date = '$datetime' \
|
||||
WHERE anime_name = '$1';"
|
||||
else
|
||||
log "UPDATING WATCH_HISTORY: anime_name='$1', episode_number='$2' search_date='$datetime'"
|
||||
stmt="UPDATE watch_history SET watch_date = '$datetime' \
|
||||
WHERE anime_name = '$1' \
|
||||
AND episode_number = $2;"
|
||||
@ -336,8 +338,6 @@ get_search_query() {
|
||||
-config "$CFG_DIR/${ROFI_CFG}" <<< "${hist[@]}")
|
||||
# Remove the id from the query
|
||||
query="${query//[1-9]*\. /}"
|
||||
# fixes '-' at end of selected anime, but removes spaces from queries
|
||||
# works with trailing '-' so remove for now
|
||||
# query="${query// /}"
|
||||
log "Query: $query"
|
||||
elif [ "$is_rofi" -eq 0 ]; then
|
||||
@ -426,7 +426,6 @@ anime_selection() {
|
||||
log "CHOICE: $choice"
|
||||
|
||||
if [ "$is_rofi" -eq 1 ]; then
|
||||
log "NAME: $name"
|
||||
# check both choice and name are set
|
||||
if [[ ! "$choice" ]] || [[ ! "$name" ]]; then
|
||||
die "Invalid choice... committing seppuku"
|
||||
@ -473,7 +472,7 @@ episode_selection() {
|
||||
FROM watch_history \
|
||||
WHERE anime_name = '$anime_id';"
|
||||
hist=$(run_stmt "$stmt")
|
||||
log "HISTORY: ${hist[*]}"
|
||||
# log "HISTORY: ${hist[*]}"
|
||||
|
||||
# Get Watch History for $anime_id as comma separated list
|
||||
watch_history=""
|
||||
@ -485,7 +484,6 @@ episode_selection() {
|
||||
fi
|
||||
done
|
||||
|
||||
log "WATCH HISTORY: %s\n" "$watch_history"
|
||||
# get user choice and set the start and end
|
||||
msg='<span foreground="peachpuff" style="italic" size="small" weight="light">Range of episodes can be provided as: START_EPISODE - END_EPISODE</span>'
|
||||
choice=$(
|
||||
@ -524,7 +522,6 @@ episode_selection() {
|
||||
ep_choice_end=""
|
||||
fi
|
||||
|
||||
# read ep_choice_start ep_choice_end
|
||||
printf "$c_reset"
|
||||
|
||||
}
|
||||
@ -539,24 +536,6 @@ open_episode() {
|
||||
episode=$episode"-5"
|
||||
fi
|
||||
|
||||
if [[ ! "$is_playlist" ]]; then
|
||||
# clear the screen
|
||||
printf '\x1B[2J\x1B[1;1H'
|
||||
if [[ $episode -lt 1 ]] || [[ $episode -gt $last_ep_number ]]; then
|
||||
err "Episode out of range"
|
||||
stmt="SELECT DISTINCT episode_number \
|
||||
FROM watch_history \
|
||||
WHERE anime_name = '$anime_id' \
|
||||
ORDER BY episode_number ASC;"
|
||||
hist=$(run_stmt "$stmt")
|
||||
log "HISTORY: ${hist[*]}"
|
||||
episode=$(printf "%s\n" "${hist[@]}" |
|
||||
rofi -dmenu -l 12 -p "Choose Episode:" \
|
||||
-config "$CFG_DIR/${ROFI_CFG}")
|
||||
printf "$c_reset"
|
||||
fi
|
||||
fi
|
||||
|
||||
log "Getting data for episode $episode"
|
||||
|
||||
# Don't update watch history if downloading episode
|
||||
@ -608,6 +587,36 @@ open_episode() {
|
||||
fi
|
||||
}
|
||||
|
||||
stream() {
|
||||
log "Running stream()"
|
||||
log "args: $*"
|
||||
get_search_query "$*"
|
||||
searched=0
|
||||
if [ $# -le 1 ]; then
|
||||
# check if anime has been searched before
|
||||
anime_id="${query// /}"
|
||||
log "Checking if anime: $anime_id has been searched before..."
|
||||
check_db "$anime_id" "search"
|
||||
searched="$?"
|
||||
log "Searched before: $searched"
|
||||
fi
|
||||
if [ "$searched" -eq 0 ]; then
|
||||
search_results=$(search_anime $query)
|
||||
[ -z "$search_results" ] && die "No search results found"
|
||||
if ! anime_selection "$search_results"; then
|
||||
die "No anime selection found"
|
||||
fi
|
||||
else
|
||||
# if the query is a previous search
|
||||
# skip search_anime function and assign $query
|
||||
anime_id="${query// /}"
|
||||
selection_id="$anime_id"
|
||||
insert_history "$anime_id" "search"
|
||||
read -r last_ep_number <<< "$(search_eps "$selection_id")"
|
||||
fi
|
||||
episode_selection
|
||||
}
|
||||
|
||||
############
|
||||
# Start Up #
|
||||
############
|
||||
@ -625,7 +634,7 @@ is_playlist=0
|
||||
playlist_remove=0
|
||||
playlist_add=0
|
||||
half_ep=0
|
||||
while getopts 'hd:Hpa:P:svq:c' OPT; do
|
||||
while getopts 'hd:Hsvq:c' OPT; do
|
||||
case "$OPT" in
|
||||
h)
|
||||
help_text
|
||||
@ -639,24 +648,6 @@ while getopts 'hd:Hpa:P:svq:c' OPT; do
|
||||
H)
|
||||
scrape=history
|
||||
;;
|
||||
p)
|
||||
scrape=playlist
|
||||
is_playlist=1
|
||||
;;
|
||||
a)
|
||||
is_add=1
|
||||
scrape=add
|
||||
playlist_file="${OPTARG/ //}"
|
||||
;;
|
||||
P)
|
||||
is_playlist=1
|
||||
# remove spaces from $OPTARG
|
||||
playlist_file="${OPTARG/ //}"
|
||||
[ -z "$playlist_file" ] && die "Enter in path to playlist"
|
||||
log "$playlist_file"
|
||||
$player_fn "$playlist_file"
|
||||
exit 0
|
||||
;;
|
||||
s)
|
||||
scrape=sync
|
||||
;;
|
||||
@ -679,7 +670,6 @@ done
|
||||
shift $((OPTIND - 1))
|
||||
|
||||
dep_ch "$player_fn" "curl" "sed" "grep" "sqlite3" "rofi" "git"
|
||||
# check_for_update
|
||||
|
||||
########
|
||||
# main #
|
||||
@ -687,31 +677,7 @@ dep_ch "$player_fn" "curl" "sed" "grep" "sqlite3" "rofi" "git"
|
||||
|
||||
case $scrape in
|
||||
query)
|
||||
get_search_query "$*"
|
||||
searched=0
|
||||
if [ $# -eq 1 ]; then
|
||||
# check if anime has been searched before
|
||||
anime_id="${query// /}"
|
||||
log "Checking if anime: $anime_id has been searched before..."
|
||||
check_db "$anime_id" "search"
|
||||
searched="$?"
|
||||
log "Searched before: $searched"
|
||||
fi
|
||||
if [ "$searched" -eq 0 ]; then
|
||||
search_results=$(search_anime $query)
|
||||
[ -z "$search_results" ] && die "No search results found"
|
||||
if ! anime_selection "$search_results"; then
|
||||
die "No anime selection found"
|
||||
fi
|
||||
else
|
||||
# if the query is a previous search
|
||||
# skip search_anime function and assign $query
|
||||
anime_id="${query// /}"
|
||||
selection_id="$anime_id"
|
||||
insert_history "$anime_id" "search"
|
||||
read -r last_ep_number <<< "$(search_eps "$selection_id")"
|
||||
fi
|
||||
episode_selection
|
||||
stream "$*"
|
||||
;;
|
||||
history)
|
||||
stmt="SELECT DISTINCT anime_name FROM watch_history ORDER BY watch_date DESC"
|
||||
@ -730,41 +696,6 @@ case $scrape in
|
||||
ep_choice_start=$(run_stmt "$stmt")
|
||||
log "Most recently watched episode: $ep_choice_start"
|
||||
;;
|
||||
playlist)
|
||||
lines=$(wc -l < "$playlist_file")
|
||||
log "Num lines in playlist: " "$lines"
|
||||
if [[ "$lines" -eq 0 ]]; then
|
||||
get_search_query "$*"
|
||||
search_results=$(search_anime "$query")
|
||||
[ -z "$search_results" ] && die "No search results found"
|
||||
if ! anime_selection "$search_results"; then
|
||||
die "No anime selection found"
|
||||
fi
|
||||
episode_selection
|
||||
else
|
||||
line=($(sed '1q;d' "$playlist_file"))
|
||||
if [[ "${#line[@]}" -ne 2 ]]; then
|
||||
die "Something went wrong with the playlist file... exiting"
|
||||
fi
|
||||
selection_id="${line[0]}"
|
||||
episodes=("$selection_id")
|
||||
ep_choice_start="${line[1]}"
|
||||
ep_choice_end=""
|
||||
read -r last_ep_number <<- EOF
|
||||
$(search_eps "$selection_id")
|
||||
EOF
|
||||
[ "$VERBOSE" -eq 1 ] && printf "Anime: %s Episode: %d\n" "$episodes" "$ep_choice_start"
|
||||
[ "$VERBOSE" -eq 1 ] && printf "Episodes: %s\n" "${episodes[@]}"
|
||||
fi
|
||||
;;
|
||||
add)
|
||||
get_search_query "$*"
|
||||
search_results=$(search_anime "$query")
|
||||
[ -z "$search_results" ] && die "No search results found"
|
||||
anime_selection "$search_results"
|
||||
[ $? -ne 0 ] && die "No anime selection found"
|
||||
episode_selection
|
||||
;;
|
||||
sync)
|
||||
printf "%s" "Enter username for remote user: "
|
||||
read -r username
|
||||
@ -803,23 +734,10 @@ check_input
|
||||
|
||||
# plays selected episode(s)
|
||||
for ep in $episodes; do
|
||||
if [[ "$is_add" -eq 1 ]]; then
|
||||
log "ID: $selection_id"
|
||||
log "EPISODES: $episodes"
|
||||
printf "%s\n" "$selection_id $ep" >> "$playlist_file"
|
||||
log "Added to playlist file"
|
||||
else
|
||||
open_episode "$selection_id" "$ep" "$download_dir"
|
||||
if [[ "$is_playlist" -eq 1 ]]; then
|
||||
sed -i '1d' "$playlist_file"
|
||||
fi
|
||||
fi
|
||||
open_episode "$selection_id" "$ep" "$download_dir"
|
||||
done
|
||||
|
||||
if [[ "$is_add" -eq 1 ]]; then
|
||||
log "Finished adding to playlist file... exiting"
|
||||
exit 0
|
||||
elif [[ "$is_download" -eq 1 ]]; then
|
||||
if [[ "$is_download" -eq 1 ]]; then
|
||||
log "Finished downloading episodes: $episodes for $selection_id... exiting"
|
||||
exit 0
|
||||
fi
|
||||
@ -869,33 +787,9 @@ while :; do
|
||||
episode=$((episode))
|
||||
;;
|
||||
a)
|
||||
# tput reset
|
||||
get_search_query
|
||||
|
||||
searched=0
|
||||
if [ $# -eq 1 ]; then
|
||||
# check if anime has been searched before
|
||||
anime_id="${query// /}"
|
||||
log "Checking if anime: $anime_id has been searched before..."
|
||||
check_db "$anime_id" "search"
|
||||
searched="$?"
|
||||
log "Searched before: $searched"
|
||||
fi
|
||||
if [ "$searched" -eq 0 ]; then
|
||||
search_results=$(search_anime $query)
|
||||
[ -z "$search_results" ] && die "No search results found"
|
||||
if ! anime_selection "$search_results"; then
|
||||
die "No anime selection found"
|
||||
fi
|
||||
else
|
||||
# if the query is a previous search
|
||||
# skip search_anime function and assign $query
|
||||
anime_id="${query// /}"
|
||||
selection_id="$anime_id"
|
||||
insert_history "$anime_id" "search"
|
||||
read -r last_ep_number <<< "$(search_eps "$selection_id")"
|
||||
fi
|
||||
episode_selection
|
||||
stream
|
||||
episode=$ep_choice_start
|
||||
log "NEW EPISODE: $selection_id - $episode"
|
||||
;;
|
||||
|
||||
q)
|
||||
|
Loading…
Reference in New Issue
Block a user