diff --git a/.gitignore b/.gitignore index 16579ad..c91ff4d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ musiclibrary.db .DS_Store __pycache__ +.envrc \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..36a17f6 --- /dev/null +++ b/Makefile @@ -0,0 +1,20 @@ +.PHONY: all fmt test changelog + +all: fmt test + +fmt: + ruff format + ruff check --fix + + +test: + pytest + +dev: + fastapi dev app.py --host 0.0.0.0 + +prod: + fastapi run app.py + +changelog: + git-cliff -O CHANGELOG.md \ No newline at end of file diff --git a/app.py b/app.py index 4fca12a..7a9ceae 100644 --- a/app.py +++ b/app.py @@ -64,6 +64,8 @@ async def get_general_stats( file_size_str = humanize.naturalsize(beets_statistics.get_file_size()) avg_bpm = beets_statistics.get_avg_bpm() format_count, lossless, lossy, unknown = beets_statistics.get_track_formats() + + recently_added_albums = beets_statistics.get_recently_added_albums() except (DBQueryError, DBNotFoundError) as e: raise HTTPException( status_code=500, detail="Could not query general statistics: {}".format(e) @@ -81,6 +83,7 @@ async def get_general_stats( "lossless": lossless, "lossy": lossy, "unknown": unknown, + "recently_added_albums": recently_added_albums, }, ) diff --git a/beetsstatistics.py b/beetsstatistics.py index 4e39d18..6367774 100644 --- a/beetsstatistics.py +++ b/beetsstatistics.py @@ -402,6 +402,23 @@ def get_albums_not_in_mb(self): except sqlite3.Error as e: raise DBQueryError from e + def get_recently_added_albums(self): + try: + cursor = self.get_db_connection().cursor() + query = """select + a.id, + a.album, + a.albumartist + from albums a order by a.added desc + limit 10;""" + cursor.execute(query) + results = cursor.fetchall() + + cursor.close() + return results + except sqlite3.Error as e: + raise DBQueryError from e + if __name__ == "__main__": parser = argparse.ArgumentParser(prog="beets-statistics") diff --git a/pyproject.toml b/pyproject.toml index 6157000..e08b064 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [project] name = "" version = "0.0.1" -requires-python = "~=3.13" +requires-python = ">=3.13,<4" dependencies = [ "fastapi[standard]", "pyyaml", diff --git a/static/main.css b/static/main.css index 6eb77db..5ba5244 100644 --- a/static/main.css +++ b/static/main.css @@ -210,5 +210,5 @@ table.data-table col.progress-bar-col { } div#plot { - height: 80vw; + height: 50vh; } \ No newline at end of file diff --git a/templates/albums.html b/templates/albums.html index 4303812..3610d2b 100644 --- a/templates/albums.html +++ b/templates/albums.html @@ -1,3 +1,4 @@ +{% import "macros.tmpl" as macros -%} @@ -15,29 +16,7 @@

Albums

{% for album in albums %} -
-
-
-

{{album.title if album.title else "n/a"}}

- -
{{album.year if album.year else "n/a"}}
-
{{album.album_artist if album.album_artist else "n/a"}}
-
{{album.genre if album.genre else "n/a"}}
-
{% if album.barcode %}{{album.barcode}}{% endif %} 
-
- {% if album.complete_percentage > 100 %} -
- {% else %} -
- {% endif %} - {{album.complete_percentage|round}}% -
-
-
-
+ {{ macros.album_tile(album.id, album.title, album.mb_albumid, album.year, album.album_artist, album.genre, album.barcode, album.complete_percentage) }} {% endfor %}
diff --git a/templates/index.html b/templates/index.html index 45205f9..bc093d8 100644 --- a/templates/index.html +++ b/templates/index.html @@ -1,3 +1,4 @@ +{% import "macros.tmpl" as macros -%} @@ -18,10 +19,18 @@

General insights

{{file_size}} disk storage
{{avg_bpm}} BPM on average
+ +

Recently added albums

+
+ {% for album in recently_added_albums %} + {{ macros.album_tile(album.id, album.title, album.mb_albumid, album.year, album.albumartist, album.genre)}} + {% endfor %} +

File formats

+ {% include 'footer.html' %}