Skip to content

Commit

Permalink
☕ ️update cli documentation and guidebook
Browse files Browse the repository at this point in the history
- Added CLI section to the documentation.
- Included toml dependency in pyproject.toml.
- Improved the guidebook for better clarity and usability.
  • Loading branch information
TrueMyst committed Dec 23, 2024
1 parent 4ca2f24 commit d79644b
Show file tree
Hide file tree
Showing 12 changed files with 94 additions and 146 deletions.
19 changes: 3 additions & 16 deletions BeatPrints/write.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ def render_singleline(
size: int,
anchor: Optional[str] = None,
align: Literal["left", "center", "right"] = "left",
direction: Literal["rtl", "ltr", "ttb"] = "ltr",
) -> None:
"""
Renders a single line of text on the image with specified styling.
Expand All @@ -153,7 +152,6 @@ def render_singleline(
size (int): The font size.
anchor (str, optional): Text anchor for alignment.
align (str, optional): Text alignment ("left", "center", "right").
direction (str, optional): Text direction ("rtl", "ltr", "ttb").
"""
offset = 0
formatted_text = group_by_font(text, fonts)
Expand All @@ -177,7 +175,6 @@ def render_singleline(
font=font,
anchor=anchor,
align=align,
direction=direction,
embedded_color=True,
)

Expand Down Expand Up @@ -222,10 +219,9 @@ def text(
anchor: Optional[str] = None,
spacing: int = 0,
align: Literal["left", "center", "right"] = "left",
direction: Literal["rtl", "ltr", "ttb"] = "ltr",
) -> None:
"""
Renders text on an image at a specified position with customizable font, size, color, alignment, direction, and spacing.
Renders text on an image at a specified position with customizable font, size, color, alignment, and spacing.
Args:
draw (ImageDraw.ImageDraw): The drawing context.
Expand All @@ -237,7 +233,6 @@ def text(
anchor (str, optional): Text anchor for alignment.
spacing (int, optional): Vertical spacing between lines.
align (str, optional): Text alignment ("left", "center", "right").
direction (str, optional): Text direction ("rtl", "ltr", "ttb").
"""
x, y = pos

Expand All @@ -250,20 +245,12 @@ def text(
# Call render_singleline drawing for each line
for line in lines:
render_singleline(
draw,
(x, y + y_offset),
line,
color,
fonts,
size,
anchor,
align,
direction,
draw, (x, y + y_offset), line, color, fonts, size, anchor, align
)
y_offset += size + scale + spacing
else:
# Draw a single line
render_singleline(draw, pos, text, color, fonts, size, anchor, align, direction)
render_singleline(draw, pos, text, color, fonts, size, anchor, align)


def heading(
Expand Down
45 changes: 3 additions & 42 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,50 +79,11 @@ highlighted_lyrics = ly.select_lines(lyrics, "5-9")
ps.track(metadata, highlighted_lyrics)
```

## 🥞 CLI Setup
## 🥞 CLI

To get started with the BeatPrints CLI, you'll need to set up a configuration file.
Here’s a short video showing how to generate posters using the CLI. For more information refer to the documentation [here](https://beatprints.readthedocs.io/en/latest/guidebook/cli.html)

### Windows

1. Create a folder named `BeatPrints` in the following directory:

```python
C:\Users\<YourUsername>\AppData\Roaming\BeatPrints\
```

2. Inside this folder, create a file called `config.toml` with the following contents:

```toml
[general]
search_limit = 7
output_directory = "<path-to-save-your-posters>"

[credentials]
client_id = "your-client-id"
client_secret = "your-client-secret"
```

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.

### Linux or macOS

1. Create a folder named `BeatPrints` in your `~/.config/` directory:

```python
~/.config/BeatPrints/
```

3. Inside this folder, create a file called `config.toml` with the same contents as mentioned above.

### Running the CLI

Once the config file is set up, you can run the BeatPrints CLI:

1. Open your terminal.
2. Type `beatprints` and press Enter.

Your poster will be saved in the output directory you specified in the `config.toml` file.
https://github.com/user-attachments/assets/3efb7028-c533-4bf4-880b-da3a71f8a3db

## 🖼️ Examples

Expand Down
6 changes: 3 additions & 3 deletions cli/exutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from questionary import Style
from typing import List, Union

from BeatPrints.spotify import TrackMetadata, AlbumMetadata
from BeatPrints import spotify

default = Style(
[
Expand Down Expand Up @@ -37,7 +37,7 @@ def clear() -> None:
print(BEATPRINTS_ANSI)


def tablize_track(tracks: List[TrackMetadata]):
def tablize_track(tracks: List[spotify.TrackMetadata]):
"""
Creates a pretty table for displaying track search results.
"""
Expand All @@ -55,7 +55,7 @@ def tablize_track(tracks: List[TrackMetadata]):
return table


def tablize_albums(albums: List[AlbumMetadata]) -> Table:
def tablize_albums(albums: List[spotify.AlbumMetadata]) -> Table:
"""
Creates a pretty table for displaying album search results.
"""
Expand Down
9 changes: 7 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,17 @@
project = "BeatPrints"
copyright = "2024, elysianmyst"
author = "elysianmyst"
release = "v1.0.4"
release = "v1.0.5"

# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration

extensions = ["sphinx.ext.autodoc", "sphinx.ext.napoleon", "sphinx_copybutton"]
extensions = [
"sphinx.ext.autodoc",
"sphinx.ext.napoleon",
"sphinx_copybutton",
"sphinxcontrib.video",
]

templates_path = ["_templates"]
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]
Expand Down
58 changes: 58 additions & 0 deletions docs/guidebook/cli.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
🥞 CLI Setup
------------

To get started with the BeatPrints CLI, you'll need to set up a configuration file.

Windows
~~~~~~~

1. Create a folder named ``BeatPrints`` in the following directory:

.. code:: python
C:\Users\<YourUsername>\AppData\Roaming\
2. Inside this folder, create a file called ``config.toml`` with the
following contents:

.. code:: toml
[general]
search_limit = 7
output_directory = "<path-to-save-your-posters>"
[credentials]
client_id = "your-client-id"
client_secret = "your-client-secret"
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.


.. important::

If you're using **Windows**, please ensure you use **double backslashes** (``\\``) rather than a single backslash when specifying your output path. For example:

.. code:: python
output_directory = "C:\\Users\\<YourUsername>\\Downloads\\Posters"
Linux or macOS
~~~~~~~~~~~~~~

1. Create a folder named ``BeatPrints`` in your ``~/.config/`` directory:

.. code:: python
~/.config/BeatPrints/
2. Inside this folder, create a file called ``config.toml`` with the same contents as mentioned above.

Running the CLI
~~~~~~~~~~~~~~~

Once the config file is set up, you can run the BeatPrints CLI:

1. Open your terminal.
2. Type ``beatprints`` and press Enter.

Your poster will be saved in the output directory you specified in the ``config.toml`` file.
8 changes: 5 additions & 3 deletions docs/guidebook/guide.rst → docs/guidebook/generate.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Generate Posters
================
🎨 Code Examples
===================

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

🎷 Track Posters
^^^^^^^^^^^^^^^^^
Expand Down Expand Up @@ -64,6 +64,8 @@ Like tracks, you can also create an album poster, follow these steps below.
# Generate the album poster
ps.album(metadata)
This is a basic guide on generating your posters. You can extend it by creating your own functions to make them more useful.

.. tip::

Use a hyphen (-) between the track/album and the artist for more accurate results.
Expand Down
4 changes: 3 additions & 1 deletion docs/guidebook/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@ Quick Start
A quick short guide on how to generate track or album posters.

.. toctree::
:maxdepth: 1

guide
cli
generate
58 changes: 8 additions & 50 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ keys:

.. code:: python
SPOTIFY_CLIENT_ID = ""
SPOTIFY_CLIENT_SECRET = ""
SPOTIFY_CLIENT_ID = "<your-client-id>"
SPOTIFY_CLIENT_SECRET = "<your-client-secret>"
You can get these from the `Spotify Developer Dashboard <https://developer.spotify.com/dashboard/>`_ by creating a new app with **Web API** as the scope.

Expand All @@ -76,7 +76,7 @@ Here’s how you can create your first poster:
sp = spotify.Spotify(CLIENT_ID, CLIENT_SECRET)
# Search for a track
search = sp.get_track("Juno Clairo", limit=1)
search = sp.get_track("Saturn - SZA", limit=1)
# Get the track's metadata and lyrics
metadata = search[0]
Expand All @@ -86,55 +86,13 @@ Here’s how you can create your first poster:
# Generate the track poster
ps.track(metadata, highlighted_lyrics)
🥞 CLI Setup
------------
🥞 CLI
------

To get started with the BeatPrints CLI, you'll need to set up a configuration file.
Here’s a short video showing how to generate posters using the CLI. For more information refer to the documentation `here <https://beatprints.readthedocs.io/en/latest/guidebook/cli.html>`_

Windows
~~~~~~~

1. Create a folder named ``BeatPrints`` in the following directory:

.. code:: python
C:\Users\<YourUsername>\AppData\Roaming\BeatPrints\
2. Inside this folder, create a file called ``config.toml`` with the
following contents:

.. code:: toml
[general]
search_limit = 7
output_directory = "<path-to-save-your-posters>"
[credentials]
client_id = "your-client-id"
client_secret = "your-client-secret"
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.

Linux or macOS
~~~~~~~~~~~~~~

1. Create a folder named ``BeatPrints`` in your ``~/.config/`` directory:

.. code:: python
~/.config/BeatPrints/
2. Inside this folder, create a file called ``config.toml`` with the same contents as mentioned above.

Running the CLI
~~~~~~~~~~~~~~~

Once the config file is set up, you can run the BeatPrints CLI:

1. Open your terminal.
2. Type ``beatprints`` and press Enter.

Your poster will be saved in the output directory you specified in the ``config.toml`` file.
.. video:: https://github.com/user-attachments/assets/3efb7028-c533-4bf4-880b-da3a71f8a3db
:width: 700

🖼️ Examples
-----------
Expand Down
26 changes: 0 additions & 26 deletions docs/misc/FAQ.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,3 @@ The lack of support for some languages is due to the large size of font files (a
I've got a really interesting idea for a feature for BeatPrints.
----------------------------------------------------------------
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!

How do I fix the libraqm error?
-------------------------------

If you encounter this following error:

.. code::
"KeyError: 'setting text direction, language or font features is not supported without libraqm'"
For Windows Users
~~~~~~~~~~~~~~~~~
You can resolve this by downloading ``fribidi.dll`` from `here <https://www.dllme.com/dll/files/fribidi>`_ and placing it in your Python directory, such as:

.. code::
C:\Program Files\Python312\
For macOS Users
~~~~~~~~~~~~~~~
If you run into the same issue, fix it by reinstalling Pillow with the correct configuration:

.. code::
pip uninstall Pillow
pip install Pillow --global-option="build_ext" --config-settings="-I=/opt/homebrew/Cellar"
4 changes: 2 additions & 2 deletions docs/misc/index.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Misc
====
Miscellaneous
=============

.. toctree::

Expand Down
1 change: 1 addition & 0 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
furo
sphinx-copybutton
sphinxcontrib-video
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "BeatPrints"
version = "1.0.4"
version = "1.0.5"
description = "Create eye-catching, pinterest-style music posters effortlessly."
authors = ["elysianmyst <[email protected]>"]
license = "CC-BY-NC-4.0"
Expand Down

0 comments on commit d79644b

Please sign in to comment.