clean up code a bit

This commit is contained in:
ksyasuda 2022-01-02 23:18:27 -08:00
parent f29733d867
commit d48c702db1
2 changed files with 8 additions and 24 deletions

23
ani-cli
View File

@ -1,20 +1,13 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# Set config directory if not already set
if [[ -z "$XDG_CONFIG_HOME" ]]; then
XDG_CONFIG_HOME="$HOME/.config"
fi
VERBOSE=0 VERBOSE=0
# BASE_URL="https://www2.gogoanime.cm/"
BASE_URL=$(curl -s -L -o /dev/null -w "%{url_effective}\n" https://gogoanime.cm)
CFG_DIR="$XDG_CONFIG_HOME/aniwrapper"
ROFI_CFG="meh.rasi"
ANIWRAPPER_ICON_PATH="$CFG_DIR/icons/icon-64.png" ANIWRAPPER_ICON_PATH="$CFG_DIR/icons/icon-64.png"
BASE_URL=$(curl -s -L -o /dev/null -w "%{url_effective}\n" https://gogoanime.cm)
CFG_DIR="${XDG_CONFIG_HOME:-$HOME/.config}/aniwrapper"
HISTORY_DB="${XDG_CONFIG_HOME:-$HOME/.config}/aniwrapper/history.sqlite3"
MAISAN_ICON_PATH="$CFG_DIR/icons/MYsan.png" MAISAN_ICON_PATH="$CFG_DIR/icons/MYsan.png"
ROFI_CFG="aniwrapper.rasi"
HISTORY_DB="$XDG_CONFIG_HOME/aniwrapper/history.sqlite3"
# dependencies: grep, sed, curl, video_player, rofi, sqlite3 # dependencies: grep, sed, curl, video_player, rofi, sqlite3
# video_player ( needs to be able to play urls ) # video_player ( needs to be able to play urls )
@ -81,7 +74,6 @@ search_anime() {
# if one word, remove leading or trailing whitespace # if one word, remove leading or trailing whitespace
search="${1// /}" search="${1// /}"
fi fi
# search=${1// /-}
log "Search Query: $search" log "Search Query: $search"
titlepattern='<a href="/category/' titlepattern='<a href="/category/'
curl -s "$BASE_URL//search.html" \ curl -s "$BASE_URL//search.html" \
@ -238,7 +230,6 @@ update_date() {
insert_history() { insert_history() {
# inserts into search/watch history db # inserts into search/watch history db
# check the anime_name/id # check the anime_name/id
if ! check_anime_name "$1"; then if ! check_anime_name "$1"; then
log "ERROR: Anime name is none... exiting" log "ERROR: Anime name is none... exiting"
return 1 return 1
@ -293,9 +284,7 @@ sync_watch_history() {
episodes=$(sqlite3 -noheader "$temp_db" "SELECT episode_number, watch_date FROM watch_history WHERE anime_name = '$anime_name'") episodes=$(sqlite3 -noheader "$temp_db" "SELECT episode_number, watch_date FROM watch_history WHERE anime_name = '$anime_name'")
# for each episode of $anime_name on the remote machine, check local # for each episode of $anime_name on the remote machine, check local
while read -r ep; do while read -r ep; do
# log "EP: $ep"
episode_num=$(awk -F '|' '{print $1}' <<< "$ep") episode_num=$(awk -F '|' '{print $1}' <<< "$ep")
# log "EPISODE NUMBER: $episode_num"
check_db "$anime_name" "$episode_num" check_db "$anime_name" "$episode_num"
num=$? num=$?
log "COUNT for $anime_name - episode $episode_num: $num" log "COUNT for $anime_name - episode $episode_num: $num"
@ -718,9 +707,9 @@ case $scrape in
temp_db="/tmp/aniwrapper_tmp_history.sqlite3" temp_db="/tmp/aniwrapper_tmp_history.sqlite3"
if [[ -z "$key_path" ]]; then if [[ -z "$key_path" ]]; then
scp -P "$PORT" "$connection_str:$XDG_CONFIG_HOME/aniwrapper/history.sqlite3" "$temp_db" scp -P "$PORT" "$connection_str:$HISTORY_DB" "$temp_db"
else else
scp -P "$PORT" -i "$key_path" "$connection_str:$XDG_CONFIG_HOME/aniwrapper/history.sqlite3" "$temp_db" scp -P "$PORT" -i "$key_path" "$connection_str:$HISTORY_DB" "$temp_db"
fi fi
if [[ "$?" -ne 0 ]]; then if [[ "$?" -ne 0 ]]; then
die "Error getting database file from remote host" die "Error getting database file from remote host"

View File

@ -5,12 +5,11 @@ set -Eeo pipefail
############# #############
# Globals # # Globals #
############# #############
[ -z "$XDG_CONFIG_HOME" ] && XDG_CONFIG_HOME="$HOME/.config"
CMD="/usr/bin/ani-cli" CMD="/usr/bin/ani-cli"
DEFAULT_DOWNLOAD="$HOME/Videos/sauce" DEFAULT_DOWNLOAD="$HOME/Videos/sauce"
CFG_DIR="$XDG_CONFIG_HOME/aniwrapper" CFG_DIR="${XDG_CONFIG_HOME:-$HOME/.config}/aniwrapper"
DEFAULT_PLAYLIST="$CFG_DIR/playlists/playlist.txt" DEFAULT_PLAYLIST="$CFG_DIR/playlists/playlist.txt"
CFG_FILE="meh.rasi" CFG_FILE="aniwrapper.rasi"
QUALITIES="1. best (default)|2. 1080p|3. 720p|4. 480p|5. 360p|6. worst" QUALITIES="1. best (default)|2. 1080p|3. 720p|4. 480p|5. 360p|6. worst"
QUALITY="best" QUALITY="best"
PLAYER_CMD="mpv" PLAYER_CMD="mpv"
@ -36,9 +35,6 @@ get_quality() {
read -r QUALITY read -r QUALITY
fi fi
log "selected quality: $QUALITY" log "selected quality: $QUALITY"
# if [[ "$QUALITY" != 'best' ]] && [[ "$QUALITY" != 'worst' ]]; then
# seppuku "Something went wrong getting the quality: $QUALITY... exiting"
# fi
} }
seppuku() { seppuku() {
@ -99,7 +95,6 @@ check_path() {
find_videos() { find_videos() {
# recursive function for finding path to video file given a starting directory # recursive function for finding path to video file given a starting directory
inp="$1" inp="$1"
# log "INPUT: $inp"
if [ -f "$inp" ]; then if [ -f "$inp" ]; then
echo "$inp" echo "$inp"
return 0 return 0