Skip to content

Commit 7c2adf2

Browse files
committed
📔 update documentation & fix tracklist indexing
- Fixed tracklist indexing for album posters (#30). - Rephrased questions in prompt.py for clarity. - Hid module names in the documentation for cleaner output.
1 parent 8ddf0e0 commit 7c2adf2

File tree

16 files changed

+154
-88
lines changed

16 files changed

+154
-88
lines changed

BeatPrints/errors.py

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -78,19 +78,7 @@ def __init__(self, message="Use format 'x-y' where x and y are numbers."):
7878
super().__init__(self.message)
7979

8080

81-
class PathNotFoundError(Exception):
82-
"""
83-
Raised when the specified path cannot be found.
84-
"""
85-
86-
def __init__(
87-
self, message="The specified path for saving the image could not be found."
88-
):
89-
self.message = message
90-
super().__init__(self.message)
91-
92-
93-
class ThemeNotFound(Exception):
81+
class ThemeNotFoundError(Exception):
9482
"""
9583
Raised when the specified theme is not found or is invalid.
9684
"""

BeatPrints/poster.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from . import image, write
1616
from .utils import filename, organize_tracks
1717

18-
from .errors import ThemeNotFound
18+
from .errors import ThemeNotFoundError
1919
from .spotify import TrackMetadata, AlbumMetadata
2020

2121

@@ -100,7 +100,7 @@ def track(
100100

101101
# Check if the theme mentioned is valid or not
102102
if theme not in THEMES:
103-
raise ThemeNotFound
103+
raise ThemeNotFoundError
104104

105105
# Get theme colors and template for the poster
106106
color, template = image.get_theme(theme)
@@ -172,7 +172,7 @@ def album(
172172

173173
# Check if the theme mentioned is valid or not
174174
if theme not in THEMES:
175-
raise ThemeNotFound
175+
raise ThemeNotFoundError
176176

177177
# Get theme colors and template for the poster
178178
color, template = image.get_theme(theme)
@@ -198,11 +198,10 @@ def album(
198198
# Album's Tracks
199199
tracks = metadata.tracks
200200

201-
if indexing:
202-
tracks = [f"{i + 1}. {track}" for i, track in enumerate(tracks)]
203-
204201
# Organize the tracklist and render it on the poster
205-
tracklist, track_widths = organize_tracks(tracks)
202+
tracklist, track_widths = organize_tracks(tracks, indexing)
203+
204+
# Starting Position
206205
x, y = C_TRACKS
207206

208207
# Render the tracklist, adjusting the position for each column

BeatPrints/utils.py

Lines changed: 53 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,29 @@
1111
from . import write, consts
1212

1313

14-
def organize_tracks(tracks: list) -> tuple:
14+
def add_flat_indexes(nlist: list) -> list:
15+
"""
16+
Adds a flat index to each track name in a nested list.
17+
18+
Args:
19+
nlist (list): A nested list of track names.
20+
21+
Returns:
22+
list: The modified nested list with flat indexes added to track names.
23+
"""
24+
25+
index = 1
26+
27+
for idx, cols in enumerate(nlist):
28+
for jdx, row in enumerate(cols):
29+
30+
nlist[idx][jdx] = f"{index}. {row}"
31+
index += 1
32+
33+
return nlist
34+
35+
36+
def organize_tracks(tracks: list, indexing: bool = False) -> tuple:
1537
"""
1638
Organizes tracks into columns that fit within the maximum allowed width.
1739
@@ -23,18 +45,39 @@ def organize_tracks(tracks: list) -> tuple:
2345
- List of lists where each inner list contains a column of track names.
2446
- List of widths for each track column.
2547
"""
48+
49+
def calculate_column_width(tracks_column: list, additional_width: int = 0):
50+
"""
51+
Helper function to calculate the width of the longest track in a column.
52+
"""
53+
54+
tracks = max(tracks_column, key=len)
55+
56+
return (
57+
write.calculate_text_width(tracks, write.font("Light"), consts.S_TRACKS)
58+
+ additional_width
59+
)
60+
61+
additional_width = 0
62+
63+
# Account for the space that index numbers take
64+
if indexing:
65+
index = len(tracks) + 1
66+
67+
additional_width = write.calculate_text_width(
68+
f"{index}", write.font("Light"), consts.S_TRACKS
69+
)
70+
2671
while True:
2772
# Split tracks into columns with a maximum of MAX_ROWS per column
2873
columns = [
2974
tracks[i : i + consts.MAX_ROWS]
3075
for i in range(0, len(tracks), consts.MAX_ROWS)
3176
]
3277

33-
# Determine the width of the longest track in each column
34-
max_tracks = [max(col, key=len) for col in columns]
78+
# Determine the width of each column
3579
track_widths = [
36-
write.calculate_text_width(track, write.font("Light"), consts.S_TRACKS)
37-
for track in max_tracks
80+
calculate_column_width(col, additional_width) for col in columns
3881
]
3982

4083
# Sum the total width and check if it fits within the allowed MAX_WIDTH
@@ -44,11 +87,15 @@ def organize_tracks(tracks: list) -> tuple:
4487
break # If it fits, exit the loop
4588

4689
else:
47-
# If it doesn't fit, remove the longest track from the longest column
90+
# If it doesn't fit, remove the longest track from the column with the widest width
4891
longest_column_index = track_widths.index(max(track_widths))
4992
longest_column = columns[longest_column_index]
5093
tracks.remove(max(longest_column, key=len))
5194

95+
# Add flat indexes to tracks if indexing is enabled
96+
if indexing:
97+
columns = add_flat_indexes(columns)
98+
5299
return columns, track_widths
53100

54101

README.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
![examples](https://i.ibb.co.com/y0jKqHK/banner.png)
2222

23-
<h3 align="center">📔 Check out the new documentation <a href="https://beatprints.readthedocs.io/en/latest/">here!</a></h3>
23+
<h3 align="center">📔 Check out the documentation <a href="https://beatprints.readthedocs.io/en/latest/">here!</a></h3>
2424

2525
## 📦 Installation
2626

@@ -134,9 +134,7 @@ I wanted to make it free for everyone to print themselves, as I believe my poste
134134
## ❤️ Special Thanks
135135

136136
- A big thanks to [Spotify Poster Generator](https://github.com/AnveshakR/poster-generator/) by [@AnveshakR](https://github.com/AnveshakR) for inspiring BeatPrints with amazing ideas!
137-
- Shoutout to [@Magniquick](https://github.com/Magniquick), [@Krishna-Gunjan](https://github.com/Krishna-Gunjan), and [@itsnotrin](https://github.com/itsnotrin) for their awesome contributions!
138-
- Thanks to [@T-Dynamos](https://github.com/T-Dynamos) and [@cherriae](https://github.com/cherriae) for their great improvements and tweaks.
139-
- A special nod to [@itsnotrin](https://github.com/itsnotrin) for helping make album poster generation possible!
137+
- Shoutout to [@Magniquick](https://github.com/Magniquick), [@Krishna-Gunjan](https://github.com/Krishna-Gunjan), [@itsnotrin](https://github.com/itsnotrin), [@T-Dynamos](https://github.com/T-Dynamos), and [@cherriae](https://github.com/cherriae) for their awesome contributions!
140138

141139

142140
## 📜 License

cli/prompt.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,16 @@ def poster_features():
184184
qmark="💫",
185185
),
186186
accent=questionary.confirm(
187-
"• Add a color accent?", default=False, style=exutils.lavish, qmark="🌈"
187+
"• Add a colored accent to the bottom?",
188+
default=False,
189+
style=exutils.lavish,
190+
qmark="🌈",
188191
),
189192
image=questionary.confirm(
190-
"• Use a custom image?", default=False, style=exutils.lavish, qmark="🥐"
193+
"• Use a custom image as the poster's cover art?",
194+
default=False,
195+
style=exutils.lavish,
196+
qmark="🥐",
191197
),
192198
).unsafe_ask()
193199

@@ -213,7 +219,7 @@ def create_poster():
213219
Create a poster based on user input.
214220
"""
215221
poster_type = questionary.select(
216-
"• What type of poster would you like to create?",
222+
"• What do you want to create?",
217223
choices=["Track Poster", "Album Poster"],
218224
style=exutils.lavish,
219225
qmark="🎨",
@@ -245,7 +251,8 @@ def main():
245251
create_poster()
246252

247253
except KeyboardInterrupt as e:
248-
print("╰─ 👋 Alright, no problem! See you next time.")
254+
exutils.clear()
255+
print("👋 Alright, no problem! See you next time.")
249256
exit(1)
250257

251258
except Exception as e:

docs/conf.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
project = "BeatPrints"
1212
copyright = "2024, elysianmyst"
1313
author = "elysianmyst"
14-
release = "v1.1.1"
14+
release = "v1.1.2"
1515

1616
# -- General configuration ---------------------------------------------------
1717
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
@@ -23,6 +23,9 @@
2323
"sphinxcontrib.video",
2424
]
2525

26+
# Hides the module name in documentation
27+
add_module_names = False
28+
2629
templates_path = ["_templates"]
2730
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]
2831

docs/guidebook/cli.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ Windows
1919
2020
[general]
2121
search_limit = 7
22-
output_directory = "<path-to-save-your-posters>"
22+
output_directory = "<path-to-save-your-posters>"
2323
2424
[credentials]
25-
client_id = "your-client-id"
26-
client_secret = "your-client-secret"
25+
client_id = "<your-client-id>"
26+
client_secret = "<your-client-secret>"
2727
2828
Replace ``<path-to-save-your-posters>`` with the path where you'd like to save the generated posters, and fill in the ``client_id`` and ``client_secret`` with your Spotify credentials.
2929

docs/guidebook/generate.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33

44
This is a quick guide on how to generate posters using **BeatPrints** through code.
55

6+
.. note::
7+
8+
It is important for you to have the ``.env`` file in the same directory.
9+
610
🎷 Track Posters
711
^^^^^^^^^^^^^^^^^
812

@@ -35,6 +39,11 @@ To generate a track poster, follow the steps below.
3539
# Generate the track poster
3640
ps.track(metadata, highlighted_lyrics)
3741
42+
.. tip::
43+
44+
You can create a **helper function** to display lyrics with line numbers in a nice format using `rich <https://github.com/Textualize/rich/>`_.
45+
This is just a **basic way** to generate the poster. The sky's the limit!
46+
3847
💿️ Album Posters
3948
^^^^^^^^^^^^^^^^^
4049

docs/misc/FAQ.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ Why isn't "x" language supported in BeatPrints?
1313
-----------------------------------------------
1414
The lack of support for some languages is due to the large size of font files (around 90 MB) required for the tool. Adding more languages would significantly increase the project's size. Since Pillow (the library used for this project) doesn’t support multi-language text natively, the write.py module would need to be rewritten to handle this, which is a time-consuming task. This issue is actively being worked on, but a simple solution hasn't been found yet.
1515

16+
Why are some tracks missing from the album posters?
17+
---------------------------------------------------
18+
Some tracks are missing from the album posters because the function organizes tracks into columns that fit within a set width, removing the longest track name if needed. Additionally, since it's not always possible to fit all tracks in order, a shuffle feature was added to randomly select tracks for the poster.
19+
1620
I've got a really interesting idea for a feature for BeatPrints.
1721
----------------------------------------------------------------
1822
I really appreciate that you want to contribute! Feel free to create an issue on the GitHub page. Just keep in mind that I started this project for fun, so actively maintaining it can be tough for me. I’m not always able to dedicate a lot of time, but I truly appreciate all ideas and contributions, and I’ll try my best to work on it when I can. Your suggestions are always welcome!

docs/reference/errors.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33

44
.. automodule:: BeatPrints.errors
55
:members:
6+
:member-order: bysource

0 commit comments

Comments
 (0)