forked from aelfa/scripts
-
Notifications
You must be signed in to change notification settings - Fork 1
/
plexstats.sh
58 lines (46 loc) · 2.88 KB
/
plexstats.sh
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/bin/bash
logfile="/opt/appdata/plex/logs/plexstats.log"
db="/opt/appdata/plex/database/Library/Application Support/Plex Media Server/Plug-in Support/Databases/com.plexapp.plugins.library.db"
echo "$(date "+%d.%m.%Y %T") PLEX LIBRARY STATS" | tee -a $logfile
echo "Media items in Libraries" | tee -a $logfile
query="SELECT Library, Items \
FROM ( SELECT name AS Library, \
COUNT(duration) AS Items \
FROM media_items m \
LEFT JOIN library_sections l ON l.id = m.library_section_id \
WHERE library_section_id > 0 GROUP BY name );"
sqlite3 -header -line "$db" "$query" | tee -a $logfile
echo " " | tee -a
query="select count(*) from media_items"
result=$(sqlite3 -header -line "$db" "$query")
echo "${result:11} files in library" | tee -a $logfile
query="select count(*) from media_items where bitrate is null"
result=$(sqlite3 -header -line "$db" "$query")
echo "${result:11} files missing analyzation info" | tee -a $logfile
query="SELECT count(*) FROM media_parts WHERE deleted_at is not null"
result=$(sqlite3 -header -line "$db" "$query")
echo "${result:11} media_parts marked as deleted" | tee -a $logfile
query="SELECT count(*) FROM metadata_items WHERE deleted_at is not null"
result=$(sqlite3 -header -line "$db" "$query")
echo "${result:11} metadata_items marked as deleted" | tee -a $logfile
query="SELECT count(*) FROM directories WHERE deleted_at is not null"
result=$(sqlite3 -header -line "$db" "$query")
echo "${result:11} directories marked as deleted" | tee -a $logfile
query="select count(*) from metadata_items meta \
join media_items media on media.metadata_item_id = meta.id \
join media_parts part on part.media_item_id = media.id \
where part.extra_data not like '%deepAnalysisVersion=2%' \
and meta.metadata_type in (1, 4, 12) and part.file != '';"
result=$(sqlite3 -header -line "$db" "$query")
echo "${result:11} files missing deep analyzation info." | tee -a $logfile
echo " " | tee -a
query="select count(*) from media_parts mp join media_items mi on mi.id = mp.media_item_id where mi.library_section_id = 2 and mp.extra_data like '%intros=%';"
result=$(sqlite3 -header -line "$db" "$query")
echo "${result:11} analyzed for intros" | tee -a $logfile
query="select count(*) from media_parts mp join media_items mi on mi.id = mp.media_item_id where mi.library_section_id = 2 and mp.extra_data not like '%intros=%';"
result=$(sqlite3 -header -line "$db" "$query")
echo "${result:11} not analyzed for intros" | tee -a $logfile
query="select count(*) from media_parts mp join media_items mi on mi.id = mp.media_item_id where mi.library_section_id = 2 and mp.extra_data like '%intros=%%7B%';"
result=$(sqlite3 -header -line "$db" "$query")
echo "${result:11} have intros" | tee -a $logfile
exit