Skip to main content

Easily tag and manipulate MP3 files in a programmatic way.

Project description

EasyMP3

EasyMP3 is a Python library designed for individuals with limited Python experience to easily manipulate and tag their MP3 files programmatically. This library is a simplified wrapper around the mutagen library, providing simpler functions and expanded functionality.

Installation and Usage

Prerequisites

  • Python 3.x

Installation

pip install easymp3

Usage Examples

Creating A Tagger Object

from easymp3 import EasyMP3

songs_directory = r"path\to\songs"
tagger = EasyMP3(songs_directory, search_subfolders=True)

This will create a tagger object that contains the paths to all MP3 files in the given directory including MP3 files in subfolders of the directory.

Using String Templates

String templates can be created using f strings and passing constants from the Tag class. For example:

from easymp3 import Tag

file_name_template = f"{Tag.TITLE} - {Tag.ARTIST}"

Setting Tags From Filenames

String templates can be used to set tags from the filename.

This will set the filename for all MP3 files in the tagger object. Ex. Fast - Juice WRLD.mp3.

from easymp3 import EasyMP3, Tag

songs_directory = r"path\to\songs"
tagger = EasyMP3(songs_directory, search_subfolders=True)

file_name_template = f"{Tag.TITLE} - {Tag.ARTIST}"
tagger.set_tags_from_filename(file_name_template)

Setting Filenames From Tags

String templates can also be used to set the filenames from the tags.

For all MP3 files in the tagger object that are correctly formatted, their title and artist will be set accordingly. Ex. If the file is named Fast - Juice WRLD.mp3 then the title will be set to Fast, and the artist will be set to Juice WRLD.

from easymp3 import EasyMP3, Tag

songs_directory = r"path\to\songs"
tagger = EasyMP3(songs_directory, search_subfolders=True)

file_name_template = f"{Tag.TITLE} - {Tag.ARTIST}"
tagger.set_filename_from_tags(file_name_template)

Copying Tags To Other MP3 Files

For all MP3 files in the tagger object, their tags will be extracted to existing MP3 files (of the same filename) in a specified directory. Ex. for all MP3 files in songs_directory, their tags will be copied to a file of the same name in copy_directory.

from easymp3 import EasyMP3

songs_directory = r"path\to\songs"
copy_directory = r"path\to\other\directory"

tagger = EasyMP3(songs_directory, search_subfolders=True)

tagger.copy_tags(copy_directory)

Setting Cover Arts

From Filename

By specifying a directory for cover art images, cover art can be set for each MP3 file in the tagger object.

This will set the cover art for every MP3 file in the tagger object if it is found. For example, if an MP3 is titled Fast.mp3 and there is a file in covers_path titled Fast.png, that image will be set as the front cover art for Fast.mp3.

from easymp3 import EasyMP3

songs_directory = r"path\to\songs"
covers_path = r"path\to\covers"
tagger = EasyMP3(songs_directory, search_subfolders=True)

tagger.set_cover_art(covers_path)

From A Template

Cover art can also be set by using a string template that represents how the cover images are named.

This will set the cover for all images that match the template. For example, if an MP3 file is tagged such that the title is Fast and the artist is Juice WRLD, then if an image file exists with the name Fast - Juice WRLD, that image will be set as the front cover image.

from easymp3 import EasyMP3, Tag

songs_directory = r"path\to\songs"
covers_path = r"path\to\covers"
template_str = f"{Tag.TITLE} - {Tag.ARTIST}"
tagger = EasyMP3(songs_directory, search_subfolders=True)

tagger.set_cover_art(covers_path, template_str)

Extracting Cover Arts

From Filename

This will extract the cover art for all MP3 files in the tagger object and name them using the filename of the original MP3 file. For example, if an MP3 file is named Fast - Juice WRLD.mp3, then the cover image will be named Fast - Juice WRLD.png (the extension can vary)

from easymp3 import EasyMP3

songs_directory = r"path\to\songs"
extracted_covers_path = r"path\to\covers"
tagger = EasyMP3(songs_directory, search_subfolders=True)

tagger.extract_cover_arts(extracted_covers_path)

From A Template

The filenames for extracted cover art can also be set using a string template.

This will set all the extracted cover images as the template. For example, if MP3 file is tagged such that the title is Fast and the artist is Juice WRLD, then the the extracted cover image will be named Fast - Juice WRLD.png (the extension can vary)

from easymp3 import EasyMP3, Tag

songs_directory = r"path\to\songs"
extracted_covers_path = r"path\to\covers"
template_str = f"{Tag.TITLE} - {Tag.ARTIST}"
tagger = EasyMP3(songs_directory, search_subfolders=True)

tagger.extract_cover_arts(extracted_covers_path, template_str)

Removing All Tags

This will remove all tags from all MP3 files in the tagger object.

from easymp3 import EasyMP3

songs_directory = r"path\to\songs"
tagger = EasyMP3(songs_directory, search_subfolders=True)

tagger.remove_all_tags()

Key Features

  • String Templates: Use string templates to set filenames from tags, set tags from filenames, export cover arts, and set cover arts from files.
  • Simplicity: EasyMP3 simplifies the MP3 tagging and manipulation process, making it accessible to users with little Python experience.
  • Expanded Functionality: Built on top of mutagen, EasyMP3 extends its capabilities with more user-friendly functions.

Libraries Used

  • Mutagen: For MP3 file manipulation.
  • re (Regular Expressions): For implementing string templates.

Challenges Overcome

  • Reusable Code: Faced difficulties in writing reusable code, which led to frequent refactoring. Overcame this by creating a util module with general-purpose functions, some of which accept other functions as parameters for versatility.
  • String Templates: Implementing string templates with regular expressions was challenging. Solved this by studying the python regex library (re) documentation and using regex templates like f'(?P<{attribute}>.+).
  • Feature-Rich Yet Simple: Balancing a feature-rich library with simplicity was tough. Introduced multiple default parameters for functions and rigorously documented them to maintain simplicity while offering expanded functionality.
  • Documentation: Initially struggled with professional documentation. Researched and adopted the reStructuredText style, replicating its format for EasyMP3's documentation.

Overall Impact and Significance

EasyMP3 allows users to quickly create powerful scripts utilizing its features without needing to delve into the complexities of the mutagen library. This significantly lowers the barrier for users looking to manage their MP3 collections programmatically.

Contribution

Contributions are welcome! Please fork the repository and submit a pull request with your changes.

License

This project is licensed under the MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

easymp3-1.3.3.tar.gz (14.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

easymp3-1.3.3-py3-none-any.whl (13.7 kB view details)

Uploaded Python 3

File details

Details for the file easymp3-1.3.3.tar.gz.

File metadata

  • Download URL: easymp3-1.3.3.tar.gz
  • Upload date:
  • Size: 14.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for easymp3-1.3.3.tar.gz
Algorithm Hash digest
SHA256 982bee96049dcab87e341977f1758b4873146c8ee80ea4c0c4423a88306be112
MD5 3db7ded21d4868ba893b9f4035cf64a8
BLAKE2b-256 f97da24e2a15383eccd79fa56a5cdd8216afce6bd57c49e8a746749d408b32a5

See more details on using hashes here.

File details

Details for the file easymp3-1.3.3-py3-none-any.whl.

File metadata

  • Download URL: easymp3-1.3.3-py3-none-any.whl
  • Upload date:
  • Size: 13.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for easymp3-1.3.3-py3-none-any.whl
Algorithm Hash digest
SHA256 6beef6b0e80b3d24e9a77e823af401f7aa365448dc886bc0cdf5069a1dd2675f
MD5 5c53e7626bfeb1a20b7ac2918952a199
BLAKE2b-256 a1a540b0a16e68f834b1800910d8f21efc1a74e6dc8c94925c4340117f8d4de9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page