navidrome analyze & generate update
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -17,3 +17,4 @@ sand_box.py
|
|||||||
rating_test.py
|
rating_test.py
|
||||||
iTunesGraphParser.my.py
|
iTunesGraphParser.my.py
|
||||||
iTunes Library.xml
|
iTunes Library.xml
|
||||||
|
navidrome/navidrome.db
|
||||||
|
|||||||
@@ -1,6 +1,15 @@
|
|||||||
import sqlite3
|
import sqlite3
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
import meilisearch
|
import meilisearch
|
||||||
|
|
||||||
|
|
||||||
|
def tzunit(dt) -> datetime:
|
||||||
|
if dt.tzinfo is not None:
|
||||||
|
return dt.replace(tzinfo=None)
|
||||||
|
return dt
|
||||||
|
|
||||||
|
|
||||||
client = meilisearch.Client("http://127.0.0.1:7700", "aSampleMasterKey")
|
client = meilisearch.Client("http://127.0.0.1:7700", "aSampleMasterKey")
|
||||||
index = client.index("itunes-albums")
|
index = client.index("itunes-albums")
|
||||||
|
|
||||||
@@ -25,27 +34,45 @@ for row in cur.execute("SELECT * FROM album;"):
|
|||||||
meili_result_len = len(msearch["hits"])
|
meili_result_len = len(msearch["hits"])
|
||||||
if meili_result_len > 0:
|
if meili_result_len > 0:
|
||||||
meili_hit = msearch["hits"][0]
|
meili_hit = msearch["hits"][0]
|
||||||
|
|
||||||
if meili_hit["_rankingScore"] > 0.5:
|
if meili_hit["_rankingScore"] > 0.5:
|
||||||
print(f"Update {row[1]}")
|
meili_artist = (
|
||||||
|
[meili_hit["Album Artist"]]
|
||||||
|
if "Album Artist" in meili_hit
|
||||||
|
else meili_hit["Artist"]
|
||||||
|
)
|
||||||
|
|
||||||
|
nv_date = tzunit(datetime.fromisoformat(row[4]))
|
||||||
|
itunes_date = tzunit(datetime.fromisoformat(meili_hit["Date Added"]))
|
||||||
|
timedelta = nv_date - itunes_date
|
||||||
|
|
||||||
val_score = 0
|
val_score = 0
|
||||||
if meili_result_len == 1:
|
if timedelta.days < 1:
|
||||||
val_score += 50
|
val_score = -1
|
||||||
if meili_hit["Track Count"] == row[3]:
|
else:
|
||||||
val_score += 40
|
if meili_result_len == 1:
|
||||||
if meili_hit["Name"] == row[1]:
|
val_score += 50
|
||||||
val_score += 30
|
if meili_hit["Track Count"] == row[3]:
|
||||||
if row[2] in meili_hit["Artist"]:
|
val_score += 40
|
||||||
val_score += 10
|
if meili_hit["Name"] == row[1]:
|
||||||
|
val_score += 30
|
||||||
|
if row[2] in meili_artist:
|
||||||
|
val_score += 10
|
||||||
|
|
||||||
|
meili_artist = (
|
||||||
|
str(meili_artist[0]) if len(meili_artist) == 1 else str(meili_artist)
|
||||||
|
)
|
||||||
data = (
|
data = (
|
||||||
meili_hit["Persistent ID"],
|
meili_hit["Persistent ID"],
|
||||||
meili_hit["Date Added"],
|
meili_hit["Date Added"],
|
||||||
meili_result_len,
|
meili_result_len,
|
||||||
meili_hit["Name"],
|
meili_hit["Name"],
|
||||||
str(meili_hit["Artist"]),
|
str(meili_artist),
|
||||||
str(meili_hit),
|
str(meili_hit),
|
||||||
meili_hit["Track Count"],
|
meili_hit["Track Count"],
|
||||||
val_score,
|
val_score,
|
||||||
row[0],
|
row[0],
|
||||||
)
|
)
|
||||||
|
print(f"Update {row[1]}")
|
||||||
instertor.execute(update_statement, data)
|
instertor.execute(update_statement, data)
|
||||||
con.commit()
|
con.commit()
|
||||||
|
|||||||
21
navidrome/generator.py
Normal file
21
navidrome/generator.py
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
import sqlite3
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
|
||||||
|
def tzunit(dt) -> datetime:
|
||||||
|
if dt.tzinfo is not None:
|
||||||
|
return dt.replace(tzinfo=None)
|
||||||
|
return dt
|
||||||
|
|
||||||
|
|
||||||
|
con = sqlite3.connect("navidrome.db")
|
||||||
|
cur = con.cursor()
|
||||||
|
|
||||||
|
for row in cur.execute("SELECT * FROM album where persistent_id is not null;"):
|
||||||
|
if row[12] >= 100:
|
||||||
|
nv_date = tzunit(datetime.fromisoformat(row[4]))
|
||||||
|
itunes_date = tzunit(datetime.fromisoformat(row[6]))
|
||||||
|
timedelta = nv_date - itunes_date
|
||||||
|
if timedelta.days > 1:
|
||||||
|
sql_st = f"UPDATE album SET created_at = '{itunes_date.isoformat()}' WHERE id = '{row[0]}';"
|
||||||
|
print(sql_st)
|
||||||
23
navidrome/init_db.sh
Executable file
23
navidrome/init_db.sh
Executable file
@@ -0,0 +1,23 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
|
||||||
|
cp ~/workspace/litestream/navidrome/navidrome.db .
|
||||||
|
|
||||||
|
echo
|
||||||
|
echo "Removing tables..."
|
||||||
|
for table in $(sqlite3 navidrome.db "SELECT name FROM sqlite_master WHERE name != 'album' and type='table'"); do
|
||||||
|
echo Process $table
|
||||||
|
sqlite3 navidrome.db "DROP TABLE $table;" || echo "Failed for table $table"
|
||||||
|
done
|
||||||
|
|
||||||
|
echo
|
||||||
|
echo "Removing index..."
|
||||||
|
for index in $(sqlite3 navidrome.db "SELECT name FROM sqlite_master WHERE type='index'"); do
|
||||||
|
echo $index
|
||||||
|
sqlite3 navidrome.db "DROP INDEX $index;" || echo "Failed for index $index"
|
||||||
|
done
|
||||||
|
|
||||||
|
echo
|
||||||
|
echo "Apply scripts..."
|
||||||
|
sqlite3 navidrome.db < clean_cols.sql.sql
|
||||||
|
sqlite3 navidrome.db < create_cols.sql
|
||||||
Reference in New Issue
Block a user