mirror of
https://github.com/ksyasuda/aniwrapper.git
synced 2025-02-06 11:33:12 -08:00
change name of logging function to not conflict with builtin
This commit is contained in:
parent
74d511b982
commit
ce2004e09c
122
ani-cli
122
ani-cli
@ -44,7 +44,7 @@ err() {
|
|||||||
printf "$c_red%s$c_reset\n" "$*" >&2
|
printf "$c_red%s$c_reset\n" "$*" >&2
|
||||||
}
|
}
|
||||||
|
|
||||||
logger() {
|
lg() {
|
||||||
# prints passed in args to stdout if $VERBOSE is set to 1
|
# prints passed in args to stdout if $VERBOSE is set to 1
|
||||||
[ "$VERBOSE" -eq 1 ] && printf "%s\n" "$*" >&2
|
[ "$VERBOSE" -eq 1 ] && printf "%s\n" "$*" >&2
|
||||||
}
|
}
|
||||||
@ -78,22 +78,22 @@ get_dpage_link() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
decrypt_link() {
|
decrypt_link() {
|
||||||
logger "BEGIN: decrypt_link()" > /dev/stderr
|
lg "BEGIN: decrypt_link()" > /dev/stderr
|
||||||
ajax_url="https://gogoplay.io/encrypt-ajax.php"
|
ajax_url="https://gogoplay.io/encrypt-ajax.php"
|
||||||
|
|
||||||
#get the id from the url
|
#get the id from the url
|
||||||
video_id=$(printf "$1" | cut -d\? -f2 | cut -d\& -f1 | sed 's/id=//g')
|
video_id=$(printf "$1" | cut -d\? -f2 | cut -d\& -f1 | sed 's/id=//g')
|
||||||
logger "video_id -> $video_id" > /dev/stderr
|
lg "video_id -> $video_id" > /dev/stderr
|
||||||
|
|
||||||
#construct ajax parameters
|
#construct ajax parameters
|
||||||
secret_key='3235373436353338353932393338333936373634363632383739383333323838'
|
secret_key='3235373436353338353932393338333936373634363632383739383333323838'
|
||||||
iv='34323036393133333738303038313335'
|
iv='34323036393133333738303038313335'
|
||||||
ajax=$(printf "$video_id" | openssl enc -aes256 -K "$secret_key" -iv "$iv" -a)
|
ajax=$(printf "$video_id" | openssl enc -aes256 -K "$secret_key" -iv "$iv" -a)
|
||||||
logger "ajax -> $ajax" > /dev/stderr
|
lg "ajax -> $ajax" > /dev/stderr
|
||||||
|
|
||||||
#send the request to the ajax url
|
#send the request to the ajax url
|
||||||
curl -s -H 'x-requested-with:XMLHttpRequest' "$ajax_url" -d "id=$ajax" -d "time=69420691337800813569" | jq -r '.source[].file'
|
curl -s -H 'x-requested-with:XMLHttpRequest' "$ajax_url" -d "id=$ajax" -d "time=69420691337800813569" | jq -r '.source[].file'
|
||||||
logger "END: decrypt_link()" > /dev/stderr
|
lg "END: decrypt_link()" > /dev/stderr
|
||||||
}
|
}
|
||||||
|
|
||||||
get_video_quality() {
|
get_video_quality() {
|
||||||
@ -131,7 +131,7 @@ notification() {
|
|||||||
if command -v "notify-send" > /dev/null; then
|
if command -v "notify-send" > /dev/null; then
|
||||||
notify-send -i "$ANIWRAPPER_ICON_PATH" "$msg"
|
notify-send -i "$ANIWRAPPER_ICON_PATH" "$msg"
|
||||||
else
|
else
|
||||||
logger "$msg"
|
lg "$msg"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -190,15 +190,15 @@ update_date() {
|
|||||||
datetime=$(date +'%Y-%m-%d %H:%M:%S')
|
datetime=$(date +'%Y-%m-%d %H:%M:%S')
|
||||||
stmt=""
|
stmt=""
|
||||||
if [[ "$1" == "directory" ]]; then
|
if [[ "$1" == "directory" ]]; then
|
||||||
logger "UPDATING FILE_HISTORY: directory='$2', filename='DIRECTORY', search_date='$datetime'"
|
lg "UPDATING FILE_HISTORY: directory='$2', filename='DIRECTORY', search_date='$datetime'"
|
||||||
stmt="UPDATE file_history SET watch_date = '$datetime' \
|
stmt="UPDATE file_history SET watch_date = '$datetime' \
|
||||||
WHERE directory = '$2' and filename = '$3';"
|
WHERE directory = '$2' and filename = '$3';"
|
||||||
elif [[ "$1" == "file" ]]; then
|
elif [[ "$1" == "file" ]]; then
|
||||||
logger "UPDATING FILE_HISTORY: directory='$2', filename='$3', search_date='$datetime'"
|
lg "UPDATING FILE_HISTORY: directory='$2', filename='$3', search_date='$datetime'"
|
||||||
stmt="UPDATE file_history SET watch_date = '$datetime' \
|
stmt="UPDATE file_history SET watch_date = '$datetime' \
|
||||||
WHERE directory = '$2' and filename = '$3';"
|
WHERE directory = '$2' and filename = '$3';"
|
||||||
elif [[ "$2" == "search" ]]; then
|
elif [[ "$2" == "search" ]]; then
|
||||||
logger "UPDATING SEARCH_HISTORY: anime_name='$1', search_date='$datetime'"
|
lg "UPDATING SEARCH_HISTORY: anime_name='$1', search_date='$datetime'"
|
||||||
stmt="UPDATE search_history SET search_date = '$datetime' \
|
stmt="UPDATE search_history SET search_date = '$datetime' \
|
||||||
WHERE anime_name = '$1';"
|
WHERE anime_name = '$1';"
|
||||||
elif [[ $# -ge 3 ]]; then
|
elif [[ $# -ge 3 ]]; then
|
||||||
@ -206,17 +206,17 @@ update_date() {
|
|||||||
[ -z "$temp_dt" ] && return 1
|
[ -z "$temp_dt" ] && return 1
|
||||||
hist_dt=$(run_stmt "SELECT watch_date FROM watch_history WHERE anime_name='$1' AND episode_number='$2';")
|
hist_dt=$(run_stmt "SELECT watch_date FROM watch_history WHERE anime_name='$1' AND episode_number='$2';")
|
||||||
hist_dt="${hist_dt// /:}"
|
hist_dt="${hist_dt// /:}"
|
||||||
logger "Checking if update is needed..."
|
lg "Checking if update is needed..."
|
||||||
if ! check_date "$hist_dt" "$temp_dt"; then
|
if ! check_date "$hist_dt" "$temp_dt"; then
|
||||||
logger "Passed in date is older or same than current date... doing nothing"
|
lg "Passed in date is older or same than current date... doing nothing"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
logger "UPDATING watch_history from sync. watch_date -> $temp_dt"
|
lg "UPDATING watch_history from sync. watch_date -> $temp_dt"
|
||||||
stmt="UPDATE watch_history SET watch_date = '$temp_dt' \
|
stmt="UPDATE watch_history SET watch_date = '$temp_dt' \
|
||||||
WHERE anime_name = '$1' \
|
WHERE anime_name = '$1' \
|
||||||
AND episode_number = $2;"
|
AND episode_number = $2;"
|
||||||
else
|
else
|
||||||
logger "UPDATING WATCH_HISTORY: anime_name='$1', episode_number='$2' search_date='$datetime'"
|
lg "UPDATING WATCH_HISTORY: anime_name='$1', episode_number='$2' search_date='$datetime'"
|
||||||
stmt="UPDATE watch_history SET watch_date = '$datetime' \
|
stmt="UPDATE watch_history SET watch_date = '$datetime' \
|
||||||
WHERE anime_name = '$1' \
|
WHERE anime_name = '$1' \
|
||||||
AND episode_number = $2;"
|
AND episode_number = $2;"
|
||||||
@ -229,15 +229,15 @@ update_date() {
|
|||||||
# check the anime_name/id
|
# check the anime_name/id
|
||||||
insert_history() {
|
insert_history() {
|
||||||
datetime=$(date +'%Y-%m-%d %H:%M:%S')
|
datetime=$(date +'%Y-%m-%d %H:%M:%S')
|
||||||
logger "Checking if ($*) exists in db"
|
lg "Checking if ($*) exists in db"
|
||||||
check_db "$@"
|
check_db "$@"
|
||||||
res="$?"
|
res="$?"
|
||||||
if [[ $res -gt 0 ]]; then
|
if [[ $res -gt 0 ]]; then
|
||||||
logger "Match found... Updating row in history db..."
|
lg "Match found... Updating row in history db..."
|
||||||
update_date "$@"
|
update_date "$@"
|
||||||
res=$?
|
res=$?
|
||||||
else
|
else
|
||||||
logger "Row not found in DB... inserting"
|
lg "Row not found in DB... inserting"
|
||||||
if [[ "$1" == "directory" ]]; then
|
if [[ "$1" == "directory" ]]; then
|
||||||
stmt="INSERT INTO file_history(directory, filename, watch_date) \
|
stmt="INSERT INTO file_history(directory, filename, watch_date) \
|
||||||
VALUES('$2', 'DIRECTORY', '$datetime');"
|
VALUES('$2', 'DIRECTORY', '$datetime');"
|
||||||
@ -252,7 +252,7 @@ insert_history() {
|
|||||||
watch_history(anime_name, episode_number, watch_date) \
|
watch_history(anime_name, episode_number, watch_date) \
|
||||||
VALUES('$1', '$2', '$datetime');"
|
VALUES('$1', '$2', '$datetime');"
|
||||||
fi
|
fi
|
||||||
logger "INSERT STATEMENT -> $stmt"
|
lg "INSERT STATEMENT -> $stmt"
|
||||||
wait # in case there's another insert/update still running in background
|
wait # in case there's another insert/update still running in background
|
||||||
run_stmt "$stmt"
|
run_stmt "$stmt"
|
||||||
res=$?
|
res=$?
|
||||||
@ -275,8 +275,8 @@ sync_search_history() {
|
|||||||
((++cnt))
|
((++cnt))
|
||||||
fi
|
fi
|
||||||
done < <(sqlite3 -list -noheader "$temp_db" "SELECT DISTINCT * FROM search_history")
|
done < <(sqlite3 -list -noheader "$temp_db" "SELECT DISTINCT * FROM search_history")
|
||||||
logger "$cnt rows inserted into search_history table"
|
lg "$cnt rows inserted into search_history table"
|
||||||
logger "$errs errors on insert"
|
lg "$errs errors on insert"
|
||||||
}
|
}
|
||||||
|
|
||||||
sync_watch_history() {
|
sync_watch_history() {
|
||||||
@ -295,8 +295,8 @@ sync_watch_history() {
|
|||||||
((++cnt))
|
((++cnt))
|
||||||
done < <(sqlite3 -list -noheader "$temp_db" "SELECT episode_number, watch_date FROM watch_history WHERE anime_name = '$anime_name'")
|
done < <(sqlite3 -list -noheader "$temp_db" "SELECT episode_number, watch_date FROM watch_history WHERE anime_name = '$anime_name'")
|
||||||
done < <(sqlite3 -list -noheader "$temp_db" "SELECT DISTINCT anime_name FROM watch_history")
|
done < <(sqlite3 -list -noheader "$temp_db" "SELECT DISTINCT anime_name FROM watch_history")
|
||||||
logger "$cnt rows inserted into watch_history table"
|
lg "$cnt rows inserted into watch_history table"
|
||||||
logger "$errs rows skipped on insert"
|
lg "$errs rows skipped on insert"
|
||||||
}
|
}
|
||||||
|
|
||||||
#####################
|
#####################
|
||||||
@ -305,13 +305,13 @@ sync_watch_history() {
|
|||||||
|
|
||||||
# opens the passed in file with $PLAYER_CMD
|
# opens the passed in file with $PLAYER_CMD
|
||||||
play_file() {
|
play_file() {
|
||||||
logger "Checking if file is playable"
|
lg "Checking if file is playable"
|
||||||
if [[ "$1" =~ ($playable)$ ]]; then
|
if [[ "$1" =~ ($playable)$ ]]; then
|
||||||
filename="${1##*/}"
|
filename="${1##*/}"
|
||||||
directory="${1%/*}"
|
directory="${1%/*}"
|
||||||
insert_history "file" "$directory" "$filename" &
|
insert_history "file" "$directory" "$filename" &
|
||||||
if [[ "$1" =~ .mp3 ]]; then
|
if [[ "$1" =~ .mp3 ]]; then
|
||||||
logger ".mp3 file found... playing without video"
|
lg ".mp3 file found... playing without video"
|
||||||
notification "Playing $1"
|
notification "Playing $1"
|
||||||
$PLAYER_CMD --no-video "$1"
|
$PLAYER_CMD --no-video "$1"
|
||||||
else
|
else
|
||||||
@ -334,7 +334,7 @@ get_directory_data() {
|
|||||||
directory="${directory##*/}"
|
directory="${directory##*/}"
|
||||||
[ -z "$inputlist" ] && inputlist="$directory" || inputlist="$inputlist|$directory"
|
[ -z "$inputlist" ] && inputlist="$directory" || inputlist="$inputlist|$directory"
|
||||||
if ! check_db "directory" "$search_dir/$directory"; then
|
if ! check_db "directory" "$search_dir/$directory"; then
|
||||||
logger "$search_dir/$directory opened before... adding $cnt to list" 1> /dev/stderr
|
lg "$search_dir/$directory opened before... adding $cnt to list" 1> /dev/stderr
|
||||||
[ -z "$watched" ] && watched="$cnt" || watched="$watched, $cnt"
|
[ -z "$watched" ] && watched="$cnt" || watched="$watched, $cnt"
|
||||||
fi
|
fi
|
||||||
((++cnt))
|
((++cnt))
|
||||||
@ -344,14 +344,14 @@ get_directory_data() {
|
|||||||
for filename in "$1"/*."{$playable_list}"; do
|
for filename in "$1"/*."{$playable_list}"; do
|
||||||
[ -z "$inputlist" ] && inputlist="$filename" || inputlist="$inputlist|$filename"
|
[ -z "$inputlist" ] && inputlist="$filename" || inputlist="$inputlist|$filename"
|
||||||
if ! check_db "file" "$search_dir" "$filename"; then
|
if ! check_db "file" "$search_dir" "$filename"; then
|
||||||
logger "$filename watched before... adding $cnt to list" 1> /dev/stderr
|
lg "$filename watched before... adding $cnt to list" 1> /dev/stderr
|
||||||
[ -z "$watched" ] && watched="$cnt" || watched="$watched, $cnt"
|
[ -z "$watched" ] && watched="$cnt" || watched="$watched, $cnt"
|
||||||
fi
|
fi
|
||||||
((++cnt))
|
((++cnt))
|
||||||
done
|
done
|
||||||
shopt -u nullglob
|
shopt -u nullglob
|
||||||
shopt -u nocaseglob
|
shopt -u nocaseglob
|
||||||
logger "INPUTLIST: $inputlist"
|
lg "INPUTLIST: $inputlist"
|
||||||
if [[ -n "$inputlist" && "$search_dir" != / ]]; then
|
if [[ -n "$inputlist" && "$search_dir" != / ]]; then
|
||||||
inputlist="../|$inputlist|Back|Quit"
|
inputlist="../|$inputlist|Back|Quit"
|
||||||
elif [[ -z "$inputlist" && "$search_dir" != / ]]; then
|
elif [[ -z "$inputlist" && "$search_dir" != / ]]; then
|
||||||
@ -359,8 +359,8 @@ get_directory_data() {
|
|||||||
elif [[ "$search_dir" = / ]]; then
|
elif [[ "$search_dir" = / ]]; then
|
||||||
inputlist="$inputlist|Back|Quit"
|
inputlist="$inputlist|Back|Quit"
|
||||||
fi
|
fi
|
||||||
logger "INPUT LIST: $inputlist" 1> /dev/stderr
|
lg "INPUT LIST: $inputlist" 1> /dev/stderr
|
||||||
logger "WATCHED LIST: $watched" 1> /dev/stderr
|
lg "WATCHED LIST: $watched" 1> /dev/stderr
|
||||||
}
|
}
|
||||||
|
|
||||||
# recursive function for finding path to video file given a starting directory
|
# recursive function for finding path to video file given a starting directory
|
||||||
@ -368,7 +368,7 @@ find_media() {
|
|||||||
inp="$1"
|
inp="$1"
|
||||||
[ -z "$inp" ] && die "No directory"
|
[ -z "$inp" ] && die "No directory"
|
||||||
# workaround to allow logging w/o affecting return output
|
# workaround to allow logging w/o affecting return output
|
||||||
logger "INPUT DIR: $inp" 1> /dev/stderr
|
lg "INPUT DIR: $inp" 1> /dev/stderr
|
||||||
|
|
||||||
# base case hit when a file is found
|
# base case hit when a file is found
|
||||||
if [ -f "$inp" ]; then
|
if [ -f "$inp" ]; then
|
||||||
@ -428,7 +428,7 @@ get_search_query() {
|
|||||||
-config "$ROFI_CFG" < <(run_stmt "$stmt"))
|
-config "$ROFI_CFG" < <(run_stmt "$stmt"))
|
||||||
# Remove the id from the query
|
# Remove the id from the query
|
||||||
query="${query//[1-9]*\. /}"
|
query="${query//[1-9]*\. /}"
|
||||||
logger "Query: $query"
|
lg "Query: $query"
|
||||||
elif [ "$is_rofi" -eq 0 ]; then
|
elif [ "$is_rofi" -eq 0 ]; then
|
||||||
printf "Search Anime: "
|
printf "Search Anime: "
|
||||||
read -r query
|
read -r query
|
||||||
@ -437,7 +437,7 @@ get_search_query() {
|
|||||||
|
|
||||||
search_anime() {
|
search_anime() {
|
||||||
# get anime name along with its id
|
# get anime name along with its id
|
||||||
logger "NUM ARGS: $#"
|
lg "NUM ARGS: $#"
|
||||||
if [[ $# -gt 1 ]]; then
|
if [[ $# -gt 1 ]]; then
|
||||||
# if multi-word query, concatenate into one string and replace spaces with '-'
|
# if multi-word query, concatenate into one string and replace spaces with '-'
|
||||||
search="$*"
|
search="$*"
|
||||||
@ -446,7 +446,7 @@ search_anime() {
|
|||||||
# if one word, remove leading or trailing whitespace
|
# if one word, remove leading or trailing whitespace
|
||||||
search="${1// /}"
|
search="${1// /}"
|
||||||
fi
|
fi
|
||||||
logger "Search Query: $search"
|
lg "Search Query: $search"
|
||||||
curl -s "$BASE_URL//search.html" \
|
curl -s "$BASE_URL//search.html" \
|
||||||
-G \
|
-G \
|
||||||
-d "keyword=$search" |
|
-d "keyword=$search" |
|
||||||
@ -489,10 +489,10 @@ anime_selection() {
|
|||||||
cnt=0
|
cnt=0
|
||||||
# Get the comma separated list of indexes of anime that has been searched before
|
# Get the comma separated list of indexes of anime that has been searched before
|
||||||
for anime in "${res[@]}"; do
|
for anime in "${res[@]}"; do
|
||||||
logger "ANIME: $anime"
|
lg "ANIME: $anime"
|
||||||
check_db "$anime" "search"
|
check_db "$anime" "search"
|
||||||
if [[ $? -gt 0 ]]; then
|
if [[ $? -gt 0 ]]; then
|
||||||
logger "$anime HAS BEEN SEARCHED BEFORE"
|
lg "$anime HAS BEEN SEARCHED BEFORE"
|
||||||
if [ -z "$searched" ]; then
|
if [ -z "$searched" ]; then
|
||||||
searched="$cnt"
|
searched="$cnt"
|
||||||
else
|
else
|
||||||
@ -501,7 +501,7 @@ anime_selection() {
|
|||||||
fi
|
fi
|
||||||
((++cnt))
|
((++cnt))
|
||||||
done
|
done
|
||||||
logger "SEARCHED: $searched"
|
lg "SEARCHED: $searched"
|
||||||
|
|
||||||
# get the anime from indexed list
|
# get the anime from indexed list
|
||||||
msg="$(generate_span "Query: $query")"
|
msg="$(generate_span "Query: $query")"
|
||||||
@ -513,7 +513,7 @@ anime_selection() {
|
|||||||
-mesg "$msg" -only-match)
|
-mesg "$msg" -only-match)
|
||||||
[ -z "$user_input" ] && return 1
|
[ -z "$user_input" ] && return 1
|
||||||
if [ "$(awk '{ print $NF }' <<< "$user_input")" = "Quit" ]; then
|
if [ "$(awk '{ print $NF }' <<< "$user_input")" = "Quit" ]; then
|
||||||
logger "QUITTING"
|
lg "QUITTING"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -541,7 +541,7 @@ anime_selection() {
|
|||||||
name="$anime_id"
|
name="$anime_id"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
logger "CHOICE: $choice"
|
lg "CHOICE: $choice"
|
||||||
|
|
||||||
if [ "$is_rofi" -eq 1 ]; then
|
if [ "$is_rofi" -eq 1 ]; then
|
||||||
# check both choice and name are set
|
# check both choice and name are set
|
||||||
@ -580,7 +580,7 @@ episode_selection() {
|
|||||||
ep_choice_start="1"
|
ep_choice_start="1"
|
||||||
if [ "$is_rofi" -eq 1 ]; then
|
if [ "$is_rofi" -eq 1 ]; then
|
||||||
# select episode number for anime
|
# select episode number for anime
|
||||||
logger "Anime ID: $anime_id"
|
lg "Anime ID: $anime_id"
|
||||||
stmt="SELECT DISTINCT episode_number \
|
stmt="SELECT DISTINCT episode_number \
|
||||||
FROM watch_history \
|
FROM watch_history \
|
||||||
WHERE anime_name = '$anime_id';"
|
WHERE anime_name = '$anime_id';"
|
||||||
@ -608,7 +608,7 @@ episode_selection() {
|
|||||||
)
|
)
|
||||||
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}')
|
||||||
logger "START: $ep_choice_start | END: $ep_choice_end"
|
lg "START: $ep_choice_start | END: $ep_choice_end"
|
||||||
elif [ $last_ep_number -gt 1 ]; then
|
elif [ $last_ep_number -gt 1 ]; then
|
||||||
[ $is_download -eq 1 ] &&
|
[ $is_download -eq 1 ] &&
|
||||||
printf "Range of episodes can be specified: start_number end_number\n"
|
printf "Range of episodes can be specified: start_number end_number\n"
|
||||||
@ -619,7 +619,7 @@ episode_selection() {
|
|||||||
fi
|
fi
|
||||||
# check for half episode
|
# check for half episode
|
||||||
if [ "$(echo "$ep_choice_start" | awk '{ printf substr($0, 1, 1) }')" = "h" ]; then
|
if [ "$(echo "$ep_choice_start" | awk '{ printf substr($0, 1, 1) }')" = "h" ]; then
|
||||||
logger "IS A HALF EPISODE"
|
lg "IS A HALF EPISODE"
|
||||||
half_ep=1
|
half_ep=1
|
||||||
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
|
||||||
@ -646,7 +646,7 @@ open_episode() {
|
|||||||
episode=$episode"-5"
|
episode=$episode"-5"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
logger "Getting data for episode $episode"
|
lg "Getting data for episode $episode"
|
||||||
|
|
||||||
# Don't update watch history if downloading episode
|
# Don't update watch history if downloading episode
|
||||||
if [ "$is_download" -eq 0 ]; then
|
if [ "$is_download" -eq 0 ]; then
|
||||||
@ -655,8 +655,8 @@ open_episode() {
|
|||||||
|
|
||||||
dpage_link=$(get_dpage_link "$anime_id" "$episode")
|
dpage_link=$(get_dpage_link "$anime_id" "$episode")
|
||||||
video_url=$(get_video_quality "$dpage_link")
|
video_url=$(get_video_quality "$dpage_link")
|
||||||
logger "Download link: $video_url"
|
lg "Download link: $video_url"
|
||||||
logger "Video url: $video_url"
|
lg "Video url: $video_url"
|
||||||
|
|
||||||
if [ $half_ep -eq 1 ]; then
|
if [ $half_ep -eq 1 ]; then
|
||||||
episode=$temp_ep
|
episode=$temp_ep
|
||||||
@ -673,7 +673,7 @@ open_episode() {
|
|||||||
printf "${c_green}\nVideo playing"
|
printf "${c_green}\nVideo playing"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
logger "Downloading episode $episode ..."
|
lg "Downloading episode $episode ..."
|
||||||
dl_dir="${ddir// /}/$anime_id"
|
dl_dir="${ddir// /}/$anime_id"
|
||||||
# add 0 padding to the episode name
|
# add 0 padding to the episode name
|
||||||
episode=$(printf "%03d" "$episode")
|
episode=$(printf "%03d" "$episode")
|
||||||
@ -694,20 +694,20 @@ open_episode() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
stream() {
|
stream() {
|
||||||
logger "Running stream()"
|
lg "Running stream()"
|
||||||
get_search_query
|
get_search_query
|
||||||
searched=0
|
searched=0
|
||||||
# check if anime has been searched before
|
# check if anime has been searched before
|
||||||
anime_id="${query// /}"
|
anime_id="${query// /}"
|
||||||
[ -z "$anime_id" ] && die "No anime selected or queried"
|
[ -z "$anime_id" ] && die "No anime selected or queried"
|
||||||
logger "Checking if anime: $anime_id has been searched before..."
|
lg "Checking if anime: $anime_id has been searched before..."
|
||||||
check_db "$anime_id" "search"
|
check_db "$anime_id" "search"
|
||||||
searched="$?"
|
searched="$?"
|
||||||
logger "Searched before: $searched"
|
lg "Searched before: $searched"
|
||||||
if [ "$searched" -eq 0 ]; then
|
if [ "$searched" -eq 0 ]; then
|
||||||
search_results=$(search_anime "$query")
|
search_results=$(search_anime "$query")
|
||||||
[ -z "$search_results" ] && die "No search results found"
|
[ -z "$search_results" ] && die "No search results found"
|
||||||
logger "SEARCH RESULTS: $search_results"
|
lg "SEARCH RESULTS: $search_results"
|
||||||
if ! anime_selection "$search_results"; then
|
if ! anime_selection "$search_results"; then
|
||||||
die "No anime selection found"
|
die "No anime selection found"
|
||||||
fi
|
fi
|
||||||
@ -741,7 +741,7 @@ parse_args() {
|
|||||||
d)
|
d)
|
||||||
is_download=1
|
is_download=1
|
||||||
download_dir="$OPTARG"
|
download_dir="$OPTARG"
|
||||||
logger "DOWNLOAD DIR: $download_dir"
|
lg "DOWNLOAD DIR: $download_dir"
|
||||||
;;
|
;;
|
||||||
H)
|
H)
|
||||||
scrape=history
|
scrape=history
|
||||||
@ -754,7 +754,7 @@ parse_args() {
|
|||||||
;;
|
;;
|
||||||
q)
|
q)
|
||||||
quality="$OPTARG"
|
quality="$OPTARG"
|
||||||
logger "passed in quality: $quality"
|
lg "passed in quality: $quality"
|
||||||
;;
|
;;
|
||||||
c)
|
c)
|
||||||
is_rofi=0
|
is_rofi=0
|
||||||
@ -809,23 +809,23 @@ parse_args() {
|
|||||||
die "$theme not a valid theme file. Themes: [$THEMES]"
|
die "$theme not a valid theme file. Themes: [$THEMES]"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
logger "Setting theme for ani-cli -> $ROFI_THEME"
|
lg "Setting theme for ani-cli -> $ROFI_THEME"
|
||||||
ROFI_CFG="$CFG_DIR/themes/$ROFI_THEME"
|
ROFI_CFG="$CFG_DIR/themes/$ROFI_THEME"
|
||||||
logger "ROFI_CFG: $ROFI_CFG"
|
lg "ROFI_CFG: $ROFI_CFG"
|
||||||
;;
|
;;
|
||||||
T)
|
T)
|
||||||
ROFI_CFG="$OPTARG"
|
ROFI_CFG="$OPTARG"
|
||||||
[ ! -f "$ROFI_CFG" ] && die "$ROFI_CFG does not exist"
|
[ ! -f "$ROFI_CFG" ] && die "$ROFI_CFG does not exist"
|
||||||
logger "CUSTOM ROFI_CFG: $ROFI_CFG"
|
lg "CUSTOM ROFI_CFG: $ROFI_CFG"
|
||||||
;;
|
;;
|
||||||
C)
|
C)
|
||||||
logger "Connecting to history database -> $CFG_DIR/history.sqlite3"
|
lg "Connecting to history database -> $CFG_DIR/history.sqlite3"
|
||||||
sqlite3 "$CFG_DIR/history.sqlite3"
|
sqlite3 "$CFG_DIR/history.sqlite3"
|
||||||
exit $?
|
exit $?
|
||||||
;;
|
;;
|
||||||
Q)
|
Q)
|
||||||
query="$OPTARG"
|
query="$OPTARG"
|
||||||
logger "DATABASE QUERY: $query"
|
lg "DATABASE QUERY: $query"
|
||||||
sqlite3 -line "$CFG_DIR/history.sqlite3" "$query"
|
sqlite3 -line "$CFG_DIR/history.sqlite3" "$query"
|
||||||
exit $?
|
exit $?
|
||||||
;;
|
;;
|
||||||
@ -856,7 +856,7 @@ main() {
|
|||||||
if ! anime_selection "${search_results[@]}"; then
|
if ! anime_selection "${search_results[@]}"; then
|
||||||
die "No anime selection found"
|
die "No anime selection found"
|
||||||
fi
|
fi
|
||||||
logger "SELECTION: $selection_id"
|
lg "SELECTION: $selection_id"
|
||||||
|
|
||||||
stmt="SELECT episode_number \
|
stmt="SELECT episode_number \
|
||||||
FROM watch_history \
|
FROM watch_history \
|
||||||
@ -864,7 +864,7 @@ main() {
|
|||||||
ORDER BY watch_date DESC \
|
ORDER BY watch_date DESC \
|
||||||
LIMIT 1"
|
LIMIT 1"
|
||||||
ep_choice_start=$(run_stmt "$stmt")
|
ep_choice_start=$(run_stmt "$stmt")
|
||||||
logger "Most recently watched episode: $ep_choice_start"
|
lg "Most recently watched episode: $ep_choice_start"
|
||||||
;;
|
;;
|
||||||
sync)
|
sync)
|
||||||
printf "%s" "Enter username for remote user: "
|
printf "%s" "Enter username for remote user: "
|
||||||
@ -899,7 +899,7 @@ main() {
|
|||||||
exit $?
|
exit $?
|
||||||
;;
|
;;
|
||||||
file)
|
file)
|
||||||
logger "STARTING DIR: $play_dir"
|
lg "STARTING DIR: $play_dir"
|
||||||
[ ! -d "$play_dir" ] && die "$play_dir does not exist"
|
[ ! -d "$play_dir" ] && die "$play_dir does not exist"
|
||||||
insert_history "directory" "$play_dir" &
|
insert_history "directory" "$play_dir" &
|
||||||
video_path=$(find_media "$play_dir")
|
video_path=$(find_media "$play_dir")
|
||||||
@ -909,7 +909,7 @@ main() {
|
|||||||
elif [ -z "$video_path" ]; then
|
elif [ -z "$video_path" ]; then
|
||||||
die "Something went wrong getting path... path is empty"
|
die "Something went wrong getting path... path is empty"
|
||||||
fi
|
fi
|
||||||
logger "VIDEO PATH: $video_path"
|
lg "VIDEO PATH: $video_path"
|
||||||
play_file "$video_path"
|
play_file "$video_path"
|
||||||
exit $?
|
exit $?
|
||||||
;;
|
;;
|
||||||
@ -923,7 +923,7 @@ main() {
|
|||||||
done
|
done
|
||||||
|
|
||||||
if [[ "$is_download" -eq 1 ]]; then
|
if [[ "$is_download" -eq 1 ]]; then
|
||||||
logger "Finished downloading episodes: $episodes for $selection_id... exiting"
|
lg "Finished downloading episodes: $episodes for $selection_id... exiting"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -974,7 +974,7 @@ main() {
|
|||||||
a)
|
a)
|
||||||
stream
|
stream
|
||||||
episode=$ep_choice_start
|
episode=$ep_choice_start
|
||||||
logger "NEW EPISODE: $selection_id - $episode"
|
lg "NEW EPISODE: $selection_id - $episode"
|
||||||
;;
|
;;
|
||||||
|
|
||||||
q)
|
q)
|
||||||
|
42
aniwrapper
42
aniwrapper
@ -51,7 +51,7 @@ Options:
|
|||||||
"
|
"
|
||||||
}
|
}
|
||||||
|
|
||||||
logger() {
|
lg() {
|
||||||
if [[ "$VERBOSE" -eq 1 ]]; then
|
if [[ "$VERBOSE" -eq 1 ]]; then
|
||||||
printf "%s\n" "$*"
|
printf "%s\n" "$*"
|
||||||
fi
|
fi
|
||||||
@ -93,7 +93,7 @@ get_quality() {
|
|||||||
printf "%s" "Enter quality [$QUALITIES]: "
|
printf "%s" "Enter quality [$QUALITIES]: "
|
||||||
read -r QUALITY
|
read -r QUALITY
|
||||||
fi
|
fi
|
||||||
logger "selected quality: $QUALITY"
|
lg "selected quality: $QUALITY"
|
||||||
}
|
}
|
||||||
|
|
||||||
# generates a span mesg for rofi given
|
# generates a span mesg for rofi given
|
||||||
@ -116,28 +116,28 @@ parse_args() {
|
|||||||
;;
|
;;
|
||||||
q)
|
q)
|
||||||
GET_QUALITY=1
|
GET_QUALITY=1
|
||||||
logger "Quality prompt enabled"
|
lg "Quality prompt enabled"
|
||||||
;;
|
;;
|
||||||
c)
|
c)
|
||||||
IS_ROFI=0
|
IS_ROFI=0
|
||||||
logger "Command-line (ani-cli) mode set"
|
lg "Command-line (ani-cli) mode set"
|
||||||
;;
|
;;
|
||||||
d)
|
d)
|
||||||
IS_DOWNLOAD=1
|
IS_DOWNLOAD=1
|
||||||
logger "Download flag set..."
|
lg "Download flag set..."
|
||||||
;;
|
;;
|
||||||
f)
|
f)
|
||||||
IS_PLAY_FROM_FILE=1
|
IS_PLAY_FROM_FILE=1
|
||||||
play_path="$OPTARG"
|
play_path="$OPTARG"
|
||||||
logger "Play from file flag set... skipping main menu"
|
lg "Play from file flag set... skipping main menu"
|
||||||
logger "PLAY_PATH: $play_path"
|
lg "PLAY_PATH: $play_path"
|
||||||
;;
|
;;
|
||||||
t)
|
t)
|
||||||
theme="$OPTARG"
|
theme="$OPTARG"
|
||||||
logger "custom theme provided: $theme"
|
lg "custom theme provided: $theme"
|
||||||
case "$theme" in
|
case "$theme" in
|
||||||
aniwrapper)
|
aniwrapper)
|
||||||
logger "Default theme chosen... doing nothing"
|
lg "Default theme chosen... doing nothing"
|
||||||
theme=default
|
theme=default
|
||||||
;;
|
;;
|
||||||
dracula)
|
dracula)
|
||||||
@ -168,13 +168,13 @@ parse_args() {
|
|||||||
CFG_FILE="$CFG_DIR/themes/$ROFI_THEME"
|
CFG_FILE="$CFG_DIR/themes/$ROFI_THEME"
|
||||||
;;
|
;;
|
||||||
C)
|
C)
|
||||||
logger "Connecting to history database -> $CFG_DIR/history.sqlite3"
|
lg "Connecting to history database -> $CFG_DIR/history.sqlite3"
|
||||||
sqlite3 "$CFG_DIR/history.sqlite3"
|
sqlite3 "$CFG_DIR/history.sqlite3"
|
||||||
exit $?
|
exit $?
|
||||||
;;
|
;;
|
||||||
Q)
|
Q)
|
||||||
query="$OPTARG"
|
query="$OPTARG"
|
||||||
logger "DATABASE QUERY: $query"
|
lg "DATABASE QUERY: $query"
|
||||||
sqlite3 -line "$CFG_DIR/history.sqlite3" "$query"
|
sqlite3 -line "$CFG_DIR/history.sqlite3" "$query"
|
||||||
exit $?
|
exit $?
|
||||||
;;
|
;;
|
||||||
@ -203,7 +203,7 @@ check_flags() {
|
|||||||
elif [[ "$IS_ROFI" -eq 0 ]] && [[ "$IS_DOWNLOAD" -eq 1 ]]; then
|
elif [[ "$IS_ROFI" -eq 0 ]] && [[ "$IS_DOWNLOAD" -eq 1 ]]; then
|
||||||
printf "%s" "Enter download dir: "
|
printf "%s" "Enter download dir: "
|
||||||
read -r dl_dir
|
read -r dl_dir
|
||||||
logger "Download dir: $dl_dir"
|
lg "Download dir: $dl_dir"
|
||||||
if [ ! -d "$dl_dir" ]; then
|
if [ ! -d "$dl_dir" ]; then
|
||||||
mkdir -p "$dl_dir" || seppuku "Error creating directory: $dl_dir"
|
mkdir -p "$dl_dir" || seppuku "Error creating directory: $dl_dir"
|
||||||
fi
|
fi
|
||||||
@ -234,14 +234,14 @@ main() {
|
|||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
# streaming
|
# streaming
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
logger "Streaming mode"
|
lg "Streaming mode"
|
||||||
run
|
run
|
||||||
;;
|
;;
|
||||||
2.)
|
2.)
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
# download
|
# download
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
logger "Download anime"
|
lg "Download anime"
|
||||||
dl_dir=$(rofi -dpi "$DPI" -dmenu -config "$CFG_FILE" \
|
dl_dir=$(rofi -dpi "$DPI" -dmenu -config "$CFG_FILE" \
|
||||||
-l 1 -p "Enter download dir:")
|
-l 1 -p "Enter download dir:")
|
||||||
# if dl_dir is none set to current directory
|
# if dl_dir is none set to current directory
|
||||||
@ -253,14 +253,14 @@ main() {
|
|||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
# continue
|
# continue
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
logger "Continue watching"
|
lg "Continue watching"
|
||||||
run -H
|
run -H
|
||||||
;;
|
;;
|
||||||
4.)
|
4.)
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
# play
|
# play
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
logger "Play from file selected"
|
lg "Play from file selected"
|
||||||
IS_PLAY_FROM_FILE=1
|
IS_PLAY_FROM_FILE=1
|
||||||
span=$(printf '%s\n%s\n' "$(generate_span "Provide a valid path to a directory or leave blank to go with the default: $HOME/Videos/sauce/")" "$(generate_span "The program will begin searching for media files from the supplied directory")")
|
span=$(printf '%s\n%s\n' "$(generate_span "Provide a valid path to a directory or leave blank to go with the default: $HOME/Videos/sauce/")" "$(generate_span "The program will begin searching for media files from the supplied directory")")
|
||||||
play_dir=$(rofi -dpi "$DPI" -dmenu -config "$CFG_FILE" \
|
play_dir=$(rofi -dpi "$DPI" -dmenu -config "$CFG_FILE" \
|
||||||
@ -274,7 +274,7 @@ main() {
|
|||||||
exit $?
|
exit $?
|
||||||
;;
|
;;
|
||||||
5.)
|
5.)
|
||||||
logger "Sync history database"
|
lg "Sync history database"
|
||||||
roficmd="rofi -dpi $DPI -dmenu -config $CFG_FILE -l 0 -p"
|
roficmd="rofi -dpi $DPI -dmenu -config $CFG_FILE -l 0 -p"
|
||||||
username=$($roficmd "Enter the username of the remote user:")
|
username=$($roficmd "Enter the username of the remote user:")
|
||||||
[ -z "$username" ] && seppuku "No username provided... exiting"
|
[ -z "$username" ] && seppuku "No username provided... exiting"
|
||||||
@ -284,10 +284,10 @@ main() {
|
|||||||
[ -z "$port" ] && port=22
|
[ -z "$port" ] && port=22
|
||||||
keypath=$($roficmd "Enter path to private key (leave blank if not needed or if unsure):")
|
keypath=$($roficmd "Enter path to private key (leave blank if not needed or if unsure):")
|
||||||
if ! printf "%s\n%s\n%d\n%s\n" "$username" "$host" "$port" "$keypath" | run -s; then
|
if ! printf "%s\n%s\n%d\n%s\n" "$username" "$host" "$port" "$keypath" | run -s; then
|
||||||
logger "Aniwrapper was unable to sync the databases..."
|
lg "Aniwrapper was unable to sync the databases..."
|
||||||
exit 1
|
exit 1
|
||||||
else
|
else
|
||||||
logger "Databases synced successfully"
|
lg "Databases synced successfully"
|
||||||
quit
|
quit
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
@ -304,7 +304,7 @@ main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
parse_args "$@"
|
parse_args "$@"
|
||||||
logger "CONFIG DIR: $CFG_DIR"
|
lg "CONFIG DIR: $CFG_DIR"
|
||||||
logger "ROFI CFG: $CFG_FILE"
|
lg "ROFI CFG: $CFG_FILE"
|
||||||
check_flags
|
check_flags
|
||||||
main
|
main
|
||||||
|
Loading…
x
Reference in New Issue
Block a user