mirror of
https://github.com/ksyasuda/aniwrapper.git
synced 2024-10-28 04:44:11 -07:00
update code formatting
This commit is contained in:
parent
37f60ffb21
commit
55470e87e9
66
ani-cli
66
ani-cli
@ -34,7 +34,7 @@ c_reset="\033[0m"
|
|||||||
help_text() {
|
help_text() {
|
||||||
while IFS= read -r line; do
|
while IFS= read -r line; do
|
||||||
printf "%s\n" "$line"
|
printf "%s\n" "$line"
|
||||||
done <<-EOF
|
done <<- EOF
|
||||||
USAGE: $prog <query>
|
USAGE: $prog <query>
|
||||||
-h show this help text
|
-h show this help text
|
||||||
-d download episode
|
-d download episode
|
||||||
@ -92,10 +92,10 @@ search_eps() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
check_input() {
|
check_input() {
|
||||||
[ "$ep_choice_start" -eq "$ep_choice_start" ] 2>/dev/null || die "Invalid number entered"
|
[ "$ep_choice_start" -eq "$ep_choice_start" ] 2> /dev/null || die "Invalid number entered"
|
||||||
episodes=$ep_choice_start
|
episodes=$ep_choice_start
|
||||||
if [ -n "$ep_choice_end" ]; then
|
if [ -n "$ep_choice_end" ]; then
|
||||||
[ "$ep_choice_end" -eq "$ep_choice_end" ] 2>/dev/null || die "Invalid number entered"
|
[ "$ep_choice_end" -eq "$ep_choice_end" ] 2> /dev/null || die "Invalid number entered"
|
||||||
# create list of episodes to download/watch
|
# create list of episodes to download/watch
|
||||||
episodes=$(seq $ep_choice_start $ep_choice_end)
|
episodes=$(seq $ep_choice_start $ep_choice_end)
|
||||||
fi
|
fi
|
||||||
@ -124,7 +124,7 @@ get_links() {
|
|||||||
|
|
||||||
get_video_quality() {
|
get_video_quality() {
|
||||||
get_links
|
get_links
|
||||||
video_quality=$(curl -s get_links "$video_url" | grep -oE "(http|https):\/\/.*com\/cdn.*expiry=[0-9]*"| sort -V | sed 's/amp;//')
|
video_quality=$(curl -s get_links "$video_url" | grep -oE "(http|https):\/\/.*com\/cdn.*expiry=[0-9]*" | sort -V | sed 's/amp;//')
|
||||||
case $quality in
|
case $quality in
|
||||||
best)
|
best)
|
||||||
play_link=$(echo "$video_quality" | sort -V | tail -n 1)
|
play_link=$(echo "$video_quality" | sort -V | tail -n 1)
|
||||||
@ -146,7 +146,7 @@ get_video_quality() {
|
|||||||
|
|
||||||
dep_ch() {
|
dep_ch() {
|
||||||
for dep; do
|
for dep; do
|
||||||
if ! command -v "$dep" >/dev/null; then
|
if ! command -v "$dep" > /dev/null; then
|
||||||
die "Program \"$dep\" not found. Please install it."
|
die "Program \"$dep\" not found. Please install it."
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
@ -241,17 +241,17 @@ insert_history() {
|
|||||||
sync_search_history() {
|
sync_search_history() {
|
||||||
cnt=0
|
cnt=0
|
||||||
while read -r line; do
|
while read -r line; do
|
||||||
anime_name=$(awk -F '|' '{print $2}' <<<"$line")
|
anime_name=$(awk -F '|' '{print $2}' <<< "$line")
|
||||||
res=$(sqlite3 -noheader "$HISTORY_DB" "SELECT COUNT(*) FROM search_history WHERE anime_name = '$anime_name'")
|
res=$(sqlite3 -noheader "$HISTORY_DB" "SELECT COUNT(*) FROM search_history WHERE anime_name = '$anime_name'")
|
||||||
if [[ "$res" -eq 0 ]]; then
|
if [[ "$res" -eq 0 ]]; then
|
||||||
search_date=$(awk -F '|' '{print $3}' <<<"$line")
|
search_date=$(awk -F '|' '{print $3}' <<< "$line")
|
||||||
log "Adding ($anime_name|$search_date) to search history..."
|
log "Adding ($anime_name|$search_date) to search history..."
|
||||||
if ! sqlite3 "$HISTORY_DB" "INSERT INTO search_history(anime_name, search_date) VALUES('$anime_name', '$search_date')"; then
|
if ! sqlite3 "$HISTORY_DB" "INSERT INTO search_history(anime_name, search_date) VALUES('$anime_name', '$search_date')"; then
|
||||||
err "Error inserting row $line"
|
err "Error inserting row $line"
|
||||||
fi
|
fi
|
||||||
((++cnt))
|
((++cnt))
|
||||||
fi
|
fi
|
||||||
done <<<"$(sqlite3 -noheader "$temp_db" "SELECT DISTINCT * FROM search_history")"
|
done <<< "$(sqlite3 -noheader "$temp_db" "SELECT DISTINCT * FROM search_history")"
|
||||||
log "Inserted $cnt rows into search_history table"
|
log "Inserted $cnt rows into search_history table"
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -265,14 +265,14 @@ sync_watch_history() {
|
|||||||
# 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"
|
# log "EP: $ep"
|
||||||
episode_num=$(awk -F '|' '{print $1}' <<<"$ep")
|
episode_num=$(awk -F '|' '{print $1}' <<< "$ep")
|
||||||
# log "EPISODE NUMBER: $episode_num"
|
# 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"
|
||||||
if [[ "$num" -eq 0 ]]; then
|
if [[ "$num" -eq 0 ]]; then
|
||||||
log "$anime_name - E$episode_num NOT IN DB"
|
log "$anime_name - E$episode_num NOT IN DB"
|
||||||
watch_date=$(awk -F '|' '{print $NF}' <<<"$ep")
|
watch_date=$(awk -F '|' '{print $NF}' <<< "$ep")
|
||||||
log "Adding ($anime_name|$episode_num|$watch_date) to watch history..."
|
log "Adding ($anime_name|$episode_num|$watch_date) to watch history..."
|
||||||
if ! sqlite3 "$HISTORY_DB" "INSERT INTO watch_history(anime_name, episode_number, watch_date) VALUES('$anime_name', '$episode_num', '$watch_date')"; then
|
if ! sqlite3 "$HISTORY_DB" "INSERT INTO watch_history(anime_name, episode_number, watch_date) VALUES('$anime_name', '$episode_num', '$watch_date')"; then
|
||||||
err "Error inserting row $ep"
|
err "Error inserting row $ep"
|
||||||
@ -281,8 +281,8 @@ sync_watch_history() {
|
|||||||
else
|
else
|
||||||
log "$anime_name - Episode: $episode_num found in the db... skipping"
|
log "$anime_name - Episode: $episode_num found in the db... skipping"
|
||||||
fi
|
fi
|
||||||
done <<<"${episodes[@]}"
|
done <<< "${episodes[@]}"
|
||||||
done <<<"$(sqlite3 -noheader "$temp_db" "SELECT DISTINCT anime_name FROM watch_history")"
|
done <<< "$(sqlite3 -noheader "$temp_db" "SELECT DISTINCT anime_name FROM watch_history")"
|
||||||
log "Inserted $cnt rows into watch_history table"
|
log "Inserted $cnt rows into watch_history table"
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -322,7 +322,7 @@ get_search_query() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# create history file
|
# create history file
|
||||||
[ -f "$logfile" ] || : >"$logfile"
|
[ -f "$logfile" ] || : > "$logfile"
|
||||||
|
|
||||||
#####################
|
#####################
|
||||||
## Anime selection ##
|
## Anime selection ##
|
||||||
@ -340,7 +340,7 @@ anime_selection() {
|
|||||||
idx=$((count - 1))
|
idx=$((count - 1))
|
||||||
res["$idx"]="$anime_id"
|
res["$idx"]="$anime_id"
|
||||||
count=$((count + 1))
|
count=$((count + 1))
|
||||||
done <<-EOF
|
done <<- EOF
|
||||||
$search_results
|
$search_results
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
@ -389,7 +389,7 @@ anime_selection() {
|
|||||||
menu_format_string=$menu_format_string_c2
|
menu_format_string=$menu_format_string_c2
|
||||||
|
|
||||||
printf "$menu_format_string" "$count" "$anime_id"
|
printf "$menu_format_string" "$count" "$anime_id"
|
||||||
count=$((count+1))
|
count=$((count + 1))
|
||||||
done <<< "$search_results"
|
done <<< "$search_results"
|
||||||
|
|
||||||
# User input
|
# User input
|
||||||
@ -409,7 +409,7 @@ anime_selection() {
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
# Check if input is a number
|
# Check if input is a number
|
||||||
[ "$choice" -eq "$choice" ] 2>/dev/null || die "Invalid number entered"
|
[ "$choice" -eq "$choice" ] 2> /dev/null || die "Invalid number entered"
|
||||||
|
|
||||||
# Select respective anime_id
|
# Select respective anime_id
|
||||||
count=1
|
count=1
|
||||||
@ -419,7 +419,7 @@ anime_selection() {
|
|||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
count=$((count + 1))
|
count=$((count + 1))
|
||||||
done <<-EOF
|
done <<- EOF
|
||||||
$search_results
|
$search_results
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
@ -431,7 +431,7 @@ anime_selection() {
|
|||||||
|
|
||||||
[ -z "$selection_id" ] && die "Invalid number entered"
|
[ -z "$selection_id" ] && die "Invalid number entered"
|
||||||
|
|
||||||
read -r last_ep_number <<-EOF
|
read -r last_ep_number <<- EOF
|
||||||
$(search_eps "$selection_id")
|
$(search_eps "$selection_id")
|
||||||
EOF
|
EOF
|
||||||
}
|
}
|
||||||
@ -528,7 +528,7 @@ open_episode() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
get_video_quality
|
get_video_quality
|
||||||
status_code=$(curl -s -I get_video_quality "$play_link" | head -n 1|cut -d ' ' -f2)
|
status_code=$(curl -s -I get_video_quality "$play_link" | head -n 1 | cut -d ' ' -f2)
|
||||||
log "Status code: $status_code"
|
log "Status code: $status_code"
|
||||||
|
|
||||||
if [ "$is_download" -eq 0 ]; then
|
if [ "$is_download" -eq 0 ]; then
|
||||||
@ -548,12 +548,12 @@ open_episode() {
|
|||||||
mkdir -p "$anime_id" || die "Could not create directory"
|
mkdir -p "$anime_id" || die "Could not create directory"
|
||||||
cd "$anime_id" || die "Could not enter subdirectory $ddir/$anime_id"
|
cd "$anime_id" || die "Could not enter subdirectory $ddir/$anime_id"
|
||||||
# ffmpeg -i "$play_link" -c copy "${anime_id}-${episode}.mkv" >/dev/null 2>&1 &&
|
# ffmpeg -i "$play_link" -c copy "${anime_id}-${episode}.mkv" >/dev/null 2>&1 &&
|
||||||
if command -v "notify-send" >/dev/null; then
|
if command -v "notify-send" > /dev/null; then
|
||||||
ffmpeg -i "$play_link" -c copy "${episode}.mkv" >/dev/null 2>&1 &&
|
ffmpeg -i "$play_link" -c copy "${episode}.mkv" > /dev/null 2>&1 &&
|
||||||
notify-send -i "$ANIWRAPPER_ICON_PATH" "Download complete for ${anime_id//-/ } - Episode: $episode" ||
|
notify-send -i "$ANIWRAPPER_ICON_PATH" "Download complete for ${anime_id//-/ } - Episode: $episode" ||
|
||||||
notify-send -i "$MAISAN_ICON_PATH" "Download failed for ${anime_id//-/ } - Episode: $episode. Please retry or check your internet connection"
|
notify-send -i "$MAISAN_ICON_PATH" "Download failed for ${anime_id//-/ } - Episode: $episode. Please retry or check your internet connection"
|
||||||
else
|
else
|
||||||
ffmpeg -i "$play_link" -c copy "${episode}.mkv" >/dev/null 2>&1 &&
|
ffmpeg -i "$play_link" -c copy "${episode}.mkv" > /dev/null 2>&1 &&
|
||||||
printf "${c_green}Downloaded complete for %s - Episode: %s${c_reset}\n" "${anime_id//-/ }" "$episode" ||
|
printf "${c_green}Downloaded complete for %s - Episode: %s${c_reset}\n" "${anime_id//-/ }" "$episode" ||
|
||||||
printf "${c_red}Download failed for %s - Episode: %s, please retry or check your internet connection${c_reset}\n" "${anime_id//-/ }" "$episode"
|
printf "${c_red}Download failed for %s - Episode: %s, please retry or check your internet connection${c_reset}\n" "${anime_id//-/ }" "$episode"
|
||||||
fi
|
fi
|
||||||
@ -639,7 +639,7 @@ shift $((OPTIND - 1))
|
|||||||
########
|
########
|
||||||
|
|
||||||
case $scrape in
|
case $scrape in
|
||||||
query)
|
query)
|
||||||
get_search_query "$*"
|
get_search_query "$*"
|
||||||
searched=0
|
searched=0
|
||||||
if [ $# -eq 1 ]; then
|
if [ $# -eq 1 ]; then
|
||||||
@ -666,7 +666,7 @@ query)
|
|||||||
fi
|
fi
|
||||||
episode_selection
|
episode_selection
|
||||||
;;
|
;;
|
||||||
history)
|
history)
|
||||||
stmt="SELECT DISTINCT anime_name FROM watch_history ORDER BY watch_date DESC"
|
stmt="SELECT DISTINCT anime_name FROM watch_history ORDER BY watch_date DESC"
|
||||||
search_results=$(printf "%s\n" "$stmt" | sqlite3 -noheader "$HISTORY_DB")
|
search_results=$(printf "%s\n" "$stmt" | sqlite3 -noheader "$HISTORY_DB")
|
||||||
[ -z "$search_results" ] && die "History is empty"
|
[ -z "$search_results" ] && die "History is empty"
|
||||||
@ -683,8 +683,8 @@ history)
|
|||||||
ep_choice_start=$(run_stmt "$stmt")
|
ep_choice_start=$(run_stmt "$stmt")
|
||||||
log "Most recently watched episode: $ep_choice_start"
|
log "Most recently watched episode: $ep_choice_start"
|
||||||
;;
|
;;
|
||||||
playlist)
|
playlist)
|
||||||
lines=$(wc -l <"$playlist_file")
|
lines=$(wc -l < "$playlist_file")
|
||||||
log "Num lines in playlist: " "$lines"
|
log "Num lines in playlist: " "$lines"
|
||||||
if [[ "$lines" -eq 0 ]]; then
|
if [[ "$lines" -eq 0 ]]; then
|
||||||
get_search_query "$*"
|
get_search_query "$*"
|
||||||
@ -703,14 +703,14 @@ playlist)
|
|||||||
episodes=("$selection_id")
|
episodes=("$selection_id")
|
||||||
ep_choice_start="${line[1]}"
|
ep_choice_start="${line[1]}"
|
||||||
ep_choice_end=""
|
ep_choice_end=""
|
||||||
read -r last_ep_number <<-EOF
|
read -r last_ep_number <<- EOF
|
||||||
$(search_eps "$selection_id")
|
$(search_eps "$selection_id")
|
||||||
EOF
|
EOF
|
||||||
[ "$VERBOSE" -eq 1 ] && printf "Anime: %s Episode: %d\n" "$episodes" "$ep_choice_start"
|
[ "$VERBOSE" -eq 1 ] && printf "Anime: %s Episode: %d\n" "$episodes" "$ep_choice_start"
|
||||||
[ "$VERBOSE" -eq 1 ] && printf "Episodes: %s\n" "${episodes[@]}"
|
[ "$VERBOSE" -eq 1 ] && printf "Episodes: %s\n" "${episodes[@]}"
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
add)
|
add)
|
||||||
get_search_query "$*"
|
get_search_query "$*"
|
||||||
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"
|
||||||
@ -718,7 +718,7 @@ add)
|
|||||||
[ $? -ne 0 ] && die "No anime selection found"
|
[ $? -ne 0 ] && die "No anime selection found"
|
||||||
episode_selection
|
episode_selection
|
||||||
;;
|
;;
|
||||||
sync)
|
sync)
|
||||||
printf "%s" "Enter username for remote user: "
|
printf "%s" "Enter username for remote user: "
|
||||||
read -r username
|
read -r username
|
||||||
printf "%s" "Enter host for remote user: "
|
printf "%s" "Enter host for remote user: "
|
||||||
@ -753,11 +753,11 @@ sync)
|
|||||||
esac
|
esac
|
||||||
|
|
||||||
{ # checking input
|
{ # checking input
|
||||||
[ "$ep_choice_start" -eq "$ep_choice_start" ] 2>/dev/null || die "Invalid number entered"
|
[ "$ep_choice_start" -eq "$ep_choice_start" ] 2> /dev/null || die "Invalid number entered"
|
||||||
episodes=$ep_choice_start
|
episodes=$ep_choice_start
|
||||||
|
|
||||||
if [ -n "$ep_choice_end" ]; then
|
if [ -n "$ep_choice_end" ]; then
|
||||||
[ "$ep_choice_end" -eq "$ep_choice_end" ] 2>/dev/null || die "Invalid number entered"
|
[ "$ep_choice_end" -eq "$ep_choice_end" ] 2> /dev/null || die "Invalid number entered"
|
||||||
# create list of episodes to download/watch
|
# create list of episodes to download/watch
|
||||||
episodes=$(seq $ep_choice_start $ep_choice_end)
|
episodes=$(seq $ep_choice_start $ep_choice_end)
|
||||||
fi
|
fi
|
||||||
@ -768,7 +768,7 @@ for ep in $episodes; do
|
|||||||
if [[ "$is_add" -eq 1 ]]; then
|
if [[ "$is_add" -eq 1 ]]; then
|
||||||
log "ID: $selection_id"
|
log "ID: $selection_id"
|
||||||
log "EPISODES: $episodes"
|
log "EPISODES: $episodes"
|
||||||
printf "%s\n" "$selection_id $ep" >>"$playlist_file"
|
printf "%s\n" "$selection_id $ep" >> "$playlist_file"
|
||||||
log "Added to playlist file"
|
log "Added to playlist file"
|
||||||
else
|
else
|
||||||
open_episode "$selection_id" "$ep" "$download_dir"
|
open_episode "$selection_id" "$ep" "$download_dir"
|
||||||
@ -813,7 +813,7 @@ while :; do
|
|||||||
printf "${c_blue}Choose episode $c_cyan[1-%d]$c_reset:$c_green " "$last_ep_number"
|
printf "${c_blue}Choose episode $c_cyan[1-%d]$c_reset:$c_green " "$last_ep_number"
|
||||||
read -r episode
|
read -r episode
|
||||||
printf "$c_reset"
|
printf "$c_reset"
|
||||||
[ "$episode" -eq "$episode" ] 2>/dev/null || die "Invalid number entered"
|
[ "$episode" -eq "$episode" ] 2> /dev/null || die "Invalid number entered"
|
||||||
;;
|
;;
|
||||||
|
|
||||||
r) ;;
|
r) ;;
|
||||||
|
11
aniwrapper
11
aniwrapper
@ -22,7 +22,6 @@ IS_DOWNLOAD=0
|
|||||||
quit="6. Quit"
|
quit="6. Quit"
|
||||||
options="1. Stream|2. Download|3. Continue|4. Play from File|5. Sync History|$quit"
|
options="1. Stream|2. Download|3. Continue|4. Play from File|5. Sync History|$quit"
|
||||||
|
|
||||||
|
|
||||||
#############
|
#############
|
||||||
# Functions #
|
# Functions #
|
||||||
#############
|
#############
|
||||||
@ -162,13 +161,13 @@ playlist_mode() {
|
|||||||
lines="$lines|$((cnt + 1)). $line"
|
lines="$lines|$((cnt + 1)). $line"
|
||||||
fi
|
fi
|
||||||
((cnt++))
|
((cnt++))
|
||||||
done <"$PLAYLIST_FILE"
|
done < "$PLAYLIST_FILE"
|
||||||
choice=$(rofi -dmenu -l 12 \
|
choice=$(rofi -dmenu -l 12 \
|
||||||
-sep '|' \
|
-sep '|' \
|
||||||
-config "$CFG_DIR/$CFG_FILE" -p "Choose episode to delete:" \
|
-config "$CFG_DIR/$CFG_FILE" -p "Choose episode to delete:" \
|
||||||
<<<"${lines[*]}")
|
<<< "${lines[*]}")
|
||||||
log "choice: $choice"
|
log "choice: $choice"
|
||||||
selection=$(awk '{print $1}' <<<"$choice")
|
selection=$(awk '{print $1}' <<< "$choice")
|
||||||
idx=${selection//\./}
|
idx=${selection//\./}
|
||||||
log "index selected: $idx"
|
log "index selected: $idx"
|
||||||
log "deleting entry: $idx"
|
log "deleting entry: $idx"
|
||||||
@ -196,7 +195,7 @@ play_file() {
|
|||||||
if [[ "$VERBOSE" -eq 1 ]]; then
|
if [[ "$VERBOSE" -eq 1 ]]; then
|
||||||
$PLAYER_CMD "$1"
|
$PLAYER_CMD "$1"
|
||||||
else
|
else
|
||||||
$PLAYER_CMD "$1" &>/dev/null &
|
$PLAYER_CMD "$1" &> /dev/null &
|
||||||
fi
|
fi
|
||||||
exit $?
|
exit $?
|
||||||
else
|
else
|
||||||
@ -232,7 +231,6 @@ find_videos() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
########
|
########
|
||||||
# Main #
|
# Main #
|
||||||
########
|
########
|
||||||
@ -382,4 +380,3 @@ case "$selection" in
|
|||||||
;;
|
;;
|
||||||
|
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
51
db.sh
51
db.sh
@ -9,51 +9,12 @@ log() {
|
|||||||
printf "%s\n" "$1"
|
printf "%s\n" "$1"
|
||||||
}
|
}
|
||||||
|
|
||||||
sync_search_history() {
|
|
||||||
cnt=0
|
|
||||||
temp_db="/tmp/aniwrapper_tmp_history.sqlite3"
|
|
||||||
while read -r line; do
|
|
||||||
anime_name=$(awk -F '|' '{print $2}' <<<"$line")
|
|
||||||
res=$(sqlite3 -noheader "$DIR/$DB" <<<"SELECT anime_name FROM search_history WHERE anime_name = '$anime_name'")
|
|
||||||
if [[ "${res/ //}" == "" ]]; then
|
|
||||||
log "Adding $line to search history..."
|
|
||||||
search_date=$(awk -F '|' '{print $3}' <<<"$line")
|
|
||||||
sqlite3 "$DIR/$DB" <<<"INSERT INTO search_history(anime_name, search_date) VALUES('$anime_name', '$search_date')"
|
|
||||||
if [[ "$?" -ne 0 ]]; then
|
|
||||||
log "Error inserting row $line"
|
|
||||||
fi
|
|
||||||
((++cnt))
|
|
||||||
fi
|
|
||||||
done <<<"$(sqlite3 -noheader "$temp_db" <<<"SELECT DISTINCT * FROM search_history")"
|
|
||||||
log "Inserted $cnt rows into search_history table"
|
|
||||||
}
|
|
||||||
|
|
||||||
sync_watch_history() {
|
|
||||||
cnt=0
|
|
||||||
temp_db="/tmp/aniwrapper_tmp_history.sqlite3"
|
|
||||||
while read -r line; do
|
|
||||||
anime_name=$(awk -F '|' '{print $2}' <<<"$line")
|
|
||||||
res=$(sqlite3 -noheader "$DIR/$DB" <<<"SELECT anime_name FROM watch_history WHERE anime_name = '$anime_name'")
|
|
||||||
if [[ "${res/ //}" == "" ]]; then
|
|
||||||
log "Adding $line to watch history..."
|
|
||||||
episode_num=$(awk -F '|' '{print $3}' <<<"$line")
|
|
||||||
watch_date=$(awk -F '|' '{print $NF}' <<<"$line")
|
|
||||||
sqlite3 "$DIR/$DB" <<<"INSERT INTO watch_history(anime_name, episode_number, watch_date) VALUES('$anime_name', '$episode_num', '$watch_date')"
|
|
||||||
if [[ "$?" -ne 0 ]]; then
|
|
||||||
log "Error inserting row $line"
|
|
||||||
fi
|
|
||||||
((++cnt))
|
|
||||||
fi
|
|
||||||
done <<<"$(sqlite3 -noheader "$temp_db" <<<"SELECT DISTINCT * FROM watch_history")"
|
|
||||||
log "Inserted $cnt rows into watch_history table"
|
|
||||||
}
|
|
||||||
|
|
||||||
while getopts 'cdrqCs' OPT; do
|
while getopts 'cdrqCs' OPT; do
|
||||||
case "$OPT" in
|
case "$OPT" in
|
||||||
c)
|
c)
|
||||||
log "Creating database..."
|
log "Creating database..."
|
||||||
sqlite3 "$DIR"/"$DB" <sql/search_history_tbl.sql
|
sqlite3 "$DIR"/"$DB" < sql/search_history_tbl.sql
|
||||||
sqlite3 "$DIR"/"$DB" <sql/watch_history_tbl.sql
|
sqlite3 "$DIR"/"$DB" < sql/watch_history_tbl.sql
|
||||||
log "Created database..."
|
log "Created database..."
|
||||||
;;
|
;;
|
||||||
d)
|
d)
|
||||||
@ -69,8 +30,8 @@ while getopts 'cdrqCs' OPT; do
|
|||||||
mkdir -p "$DIR"
|
mkdir -p "$DIR"
|
||||||
log "Database deleted..."
|
log "Database deleted..."
|
||||||
log "Creating database..."
|
log "Creating database..."
|
||||||
sqlite3 "$DIR"/"$DB" <sql/search_history_tbl.sql
|
sqlite3 "$DIR"/"$DB" < sql/search_history_tbl.sql
|
||||||
sqlite3 "$DIR"/"$DB" <sql/watch_history_tbl.sql
|
sqlite3 "$DIR"/"$DB" < sql/watch_history_tbl.sql
|
||||||
log "Created database..."
|
log "Created database..."
|
||||||
;;
|
;;
|
||||||
q)
|
q)
|
||||||
@ -82,10 +43,10 @@ while getopts 'cdrqCs' OPT; do
|
|||||||
log "Cleaning up database..."
|
log "Cleaning up database..."
|
||||||
stmt="DELETE FROM search_history WHERE anime_name IS NULL OR anime_name = ''"
|
stmt="DELETE FROM search_history WHERE anime_name IS NULL OR anime_name = ''"
|
||||||
log "Cleaning up search history..."
|
log "Cleaning up search history..."
|
||||||
sqlite3 "$DIR/$DB" <<<"$stmt"
|
sqlite3 "$DIR/$DB" <<< "$stmt"
|
||||||
stmt="DELETE FROM watch_history WHERE anime_name IS NULL OR anime_name = '' OR episode_number = 0"
|
stmt="DELETE FROM watch_history WHERE anime_name IS NULL OR anime_name = '' OR episode_number = 0"
|
||||||
log "Cleaning up watch history..."
|
log "Cleaning up watch history..."
|
||||||
sqlite3 "$DIR/$DB" <<<"$stmt"
|
sqlite3 "$DIR/$DB" <<< "$stmt"
|
||||||
;;
|
;;
|
||||||
s)
|
s)
|
||||||
printf "%s" "Enter connection string for remote user in the form user@host: "
|
printf "%s" "Enter connection string for remote user in the form user@host: "
|
||||||
|
4
setup.sh
4
setup.sh
@ -41,8 +41,8 @@ run_setup() {
|
|||||||
if [[ ! -f "$DIR"/"$DB" ]]; then
|
if [[ ! -f "$DIR"/"$DB" ]]; then
|
||||||
# Create the DB if not exists
|
# Create the DB if not exists
|
||||||
log "Creating history database..."
|
log "Creating history database..."
|
||||||
sqlite3 "$DIR"/"$DB" <sql/watch_history_tbl.sql
|
sqlite3 "$DIR"/"$DB" < sql/watch_history_tbl.sql
|
||||||
sqlite3 "$DIR"/"$DB" <sql/search_history_tbl.sql
|
sqlite3 "$DIR"/"$DB" < sql/search_history_tbl.sql
|
||||||
log "History database created..."
|
log "History database created..."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user