summaryrefslogtreecommitdiffstats
path: root/.local/bin/watchedlist
blob: 159510dc5edd1bb9e119c96a8519362c1168fbac (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/bin/bash

# variables
if [ -z "$1" ]
then
	database="watchedlist.db"
else
	database="$1"
fi

# checks
if [ ! -f "$database" ]
then
	echo Database "$database" file missing, exiting
	exit 0
fi

# blank database check

# movies
if [ -f "movies.csv" ]; then rm movies.csv; fi
sqlite3 -noheader -csv $database "select title from movie_watched;" > movies.csv
sed -i -e 's|\"||g' -e 's|^|* |g' movies.csv
sort -k 2 < movies.csv > movies.md
rm movies.csv

# tv shows
sqlite3 -noheader -csv $database "select * from tvshows;" > tv_shows_index.csv
watched_id=$(sqlite3 -noheader $database "select idShow from episode_watched;" | uniq)
for i in $watched_id; do grep "$i" tv_shows_index.csv | cut -f2- -d, >> tv_shows.csv; done
sed -i -e 's|\"||g' -e 's|^|* |g' tv_shows.csv
sort -k 2 < tv_shows.csv > tv_shows.md
rm tv_shows.csv tv_shows_index.csv