Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
musiclibrary.db
.DS_Store
__pycache__
.envrc
20 changes: 20 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -81,6 +83,7 @@ async def get_general_stats(
"lossless": lossless,
"lossy": lossy,
"unknown": unknown,
"recently_added_albums": recently_added_albums,
},
)

Expand Down
17 changes: 17 additions & 0 deletions beetsstatistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[project]
name = ""
version = "0.0.1"
requires-python = "~=3.13"
requires-python = ">=3.13,<4"
dependencies = [
"fastapi[standard]",
"pyyaml",
Expand Down
2 changes: 1 addition & 1 deletion static/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -210,5 +210,5 @@ table.data-table col.progress-bar-col {
}

div#plot {
height: 80vw;
height: 50vh;
}
25 changes: 2 additions & 23 deletions templates/albums.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{% import "macros.tmpl" as macros -%}
<!DOCTYPE html>
<html>
<head>
Expand All @@ -15,29 +16,7 @@ <h2>Albums</h2>

<div class="album-cards">
{% for album in albums %}
<div class="album">
<div class="container">
<div class="album-cover"><img src="/cover/{{album.id}}" width="200" height="200" loading="lazy" /></div>
<h4 class="album-title" title="{{album.title if album.title else "n/a"}}">{{album.title if album.title else "n/a"}}</h4>
<div class="album-mb-link">{% if album.mb_albumid %}<a href="https://musicbrainz.org/release/{{album.mb_albumid}}">On MusicBrainz</a>{% endif %}&nbsp;</div>
<h5 class="album-year">{{album.year if album.year else "n/a"}}</h5>
<div class="album-artist" title="{{album.album_artist if album.album_artist else "n/a"}}">{{album.album_artist if album.album_artist else "n/a"}}</div>
<div class="album-genre">{{album.genre if album.genre else "n/a"}}</div>
<div class="album-barcode">{% if album.barcode %}{{album.barcode}}{% endif %}&nbsp;</div>
<div class="completeness">
{% if album.complete_percentage > 100 %}
<div class="progress-bar invalid">
{% else %}
<div
style="width: {{album.complete_percentage|round}}%;"
class="progress-bar"
>
{% endif %}
{{album.complete_percentage|round}}%
</div>
</div>
</div>
</div>
{{ macros.album_tile(album.id, album.title, album.mb_albumid, album.year, album.album_artist, album.genre, album.barcode, album.complete_percentage) }}
{% endfor %}
</div>
</content>
Expand Down
9 changes: 9 additions & 0 deletions templates/index.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{% import "macros.tmpl" as macros -%}
<!DOCTYPE html>
<html>
<head>
Expand All @@ -18,10 +19,18 @@ <h2>General insights</h2>
<div>{{file_size}} disk storage</div>
<div>{{avg_bpm}} BPM on average</div>
</div>

<h3>Recently added albums</h3>
<div class="album-cards">
{% for album in recently_added_albums %}
{{ macros.album_tile(album.id, album.title, album.mb_albumid, album.year, album.albumartist, album.genre)}}
{% endfor %}
</div>
<h3>File formats</h3>
<div id="plot"></div>

</content>

{% include 'footer.html' %}
<script>
var format_data = [{
Expand Down
27 changes: 27 additions & 0 deletions templates/macros.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{% macro album_tile(id, title, mb_albumid, year, album_artist, genre, barcode, complete_percentage) -%}
<div class="album">
<div class="container">
<div class="album-cover"><img src="/cover/{{id}}" width="200" height="200" loading="lazy" /></div>
<h4 class="album-title" title="{{title if title else "n/a"}}">{{title if title else "n/a"}}</h4>
<div class="album-mb-link">{% if mb_albumid %}<a href="https://musicbrainz.org/release/{{mb_albumid}}">On MusicBrainz</a>{% endif %}&nbsp;</div>
<h5 class="album-year">{{year if year else "n/a"}}</h5>
<div class="album-artist" title="{{album_artist if album_artist else "n/a"}}">{{album_artist if album_artist else "n/a"}}</div>
<div class="album-genre">{{genre if genre else "n/a"}}</div>
<div class="album-barcode">{% if barcode %}{{barcode}}{% endif %}&nbsp;</div>
{% if complete_percentage %}
<div class="completeness">
{% if complete_percentage > 100 %}
<div class="progress-bar invalid">
{% else %}
<div
style="width: {{complete_percentage|round}}%;"
class="progress-bar"
>
{% endif %}
{{complete_percentage|round}}%
</div>
</div>
{% endif %}
</div>
</div>
{%- endmacro %}
Loading