https://github.com/stypox/mp3-player
Plays playlists of mp3s in the desired order (track number, title...)
https://github.com/stypox/mp3-player
audio audio-player id3 id3-reader metadata mp3 mp3-player mp3-tags mp3player music music-metadata music-player music-sorting player
Last synced: 8 months ago
JSON representation
Plays playlists of mp3s in the desired order (track number, title...)
- Host: GitHub
- URL: https://github.com/stypox/mp3-player
- Owner: Stypox
- Created: 2018-04-29T08:55:14.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2025-01-06T14:13:40.000Z (10 months ago)
- Last Synced: 2025-01-06T15:27:11.454Z (10 months ago)
- Topics: audio, audio-player, id3, id3-reader, metadata, mp3, mp3-player, mp3-tags, mp3player, music, music-metadata, music-player, music-sorting, player
- Language: Python
- Homepage:
- Size: 67.4 KB
- Stars: 3
- Watchers: 4
- Forks: 1
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Mp3 player
Plays playlists of MP3s **sorted** by **track number**, by title, **randomly**... **Remembers the song being played** and the sorting settings before exiting. Can be controlled by pressing **keyboard keys**.
##### Useful in combination with my youtube [playlist-downloader](https://github.com/Stypox/song-downloader) that saves song metadata.# Keyboard controls
The script uses **keyboard input**, instead of console input, since it's **simpler** and more **convenient**. Note that the console window must be focused for this to work. For example by pressing ``p`` the music pauses. This is the complete list of **keybindings** (**\|** means or):Abort without saving: a | e
Save current song and sorting settings, then exit: s
Pause and resume: p | Enter
Restart: ......................................... r | Home (*)
Next song: Arrow down | Arrow right
Previous song: ................................... Arrow up | Arrow left
Next playlist: Page up
Previous playlist: ............................... Page downIn case the used console doesn't support direct keyboard input, **press Enter** after pressing a key, just like it was a normal console input.
(*) ``Home`` is also known as ``Start`` or ``Beginning``, depending on the keyboard.# Sorting
The script provides several ways to **sort songs** and uses [ID3 metadata](https://en.wikipedia.org/wiki/ID3) to get informations about MP3s. The **default** sort order is by **track number** and all sort orders have a **corresponding code** that the script uses to understand them (see [Usage](#usage)):
* **Path**: sorts the songs based on their path in alphabetical order a-z
(codes: "p" or "path")
* **Title**: sorts the songs based on their title in alphabetical order a-z
(codes: "t" or "title")
* **Artist**: sorts the songs based on their artist in alphabetical order a-z
(codes: "a" or "artist")
* **Track number**: sorts the songs based on their track number from bottom up
(codes: "n" or "number" or "tracknumber")
* **Random**: randomly shuffles all the songs
(codes: "r" or "random")
* **Modified** (prefix): after sorting the songs as requested, this modifier introduces some small variability
(prefix codes: "m-" or "modified-")
* **Distributed** (prefix): after sorting the songs as requested, this modifier shuffles the songs according to a probability distribution that picks one song at a time preferring songs that come first in the sorted list but still picking later songs often enough
(prefix codes: "d-" or "distributed-")For example: "p" -> sorted by path; "m-number" -> sorted by track number with some variability;
# Usage
Choose some **directories full of MP3**. Every directory is considered a **playlist** and processed separately from others. Inside every directory a file named ``mp3-player-settings.txt`` will be created containing the **settings for that directory** (for example the song to start with the next time that directory is played). These setting, if existing, will be **overwritten by manually provided parameters**. The directories I choose are "C:/path/to/songs/" and "./Music/".Then there are two ways to provide the script with those directories: using a **file** or using **command line arguments** (all parameters between **\[square brackets\]** are to be considered optional):
## Saving directories in file
In the directory the script is executed in create a file named ``mp3-player-directories.txt``. In that file you can insert the **directories to be played** this way:DIRECTORY [SORT_ORDER] [START_SONG]
DIRECTORY [SORT_ORDER] [START_SONG]
...Here "DIRECTORY" represents the directory in which to **look for songs**; "SORT_ORDER" is **optional**, must be a **sorting code** (see [Sorting](#sorting)), represents the **sort order** and defaults to track number order; "START_SONG" is **optional**, must be an **integer** (negative integers mean "count from the right"), represents the index of the **song to start with** and defaults to ``0``. **Save the file and run** the script. In this case the file could be:
C:/path/to/songs/ random
./Music/ modified-artist 15## Passing directories as command line arguments
**Open a terminal** and navigate to the "DIRECTORY" the python script is in (run ``cd DIRECTORY``). Then run ``python3 FILENAME ARGUMENTS`` (*) replacing "FILENAME" with the name of the script. "ARGUMENTS" is the list of **directories to be played** and must be formatted this way:DIRECTORY [SORT_ORDER] [START_SONG] - ... - DIRECTORY [SORT_ORDER] [START_SONG]
Here "DIRECTORY" represents the directory in which to **look for songs**; "SORT_ORDER" is **optional**, must be a **sorting code** (see [Sorting](#sorting)), represents the **sort order** and defaults to track number order; "START_SONG" is **optional**, must be an **integer** (a negative integer means "count from the right"), represents the index of the **song to start with** and defaults to ``0``. For example (command line commands):
> cd C:/mp3-player/
> python3 mp3-player.py C:/path/to/songs/ random - ./Music/ modified-artist 15(*) Note that the command used for Python is **not always** ``python3``: it could be ``py``, ``python``, ``python3.6`` or others too.
## Result
The music should start playing! Now you can use keys to navigate through songs and playlist, see [Keyboard controls](#keyboard-controls).
# Dependencies
* Requires either **[Python 3.6.x](https://www.python.org/downloads/)** or **[Python 3.7.x](https://www.python.org/downloads/)** (I didn't test older versions, but newer ones may work).
* Install dependencies from [requirements.txt](requirements.txt) using this command: `python3 -m pip install -r requirements.txt`
It will install the following [`pip`](https://packaging.python.org/tutorials/installing-packages/) **modules**: [python-vlc](https://pypi.org/project/python-vlc/); [mutagen](https://pypi.org/project/mutagen/).
# Notes
* When using random sort order the order of songs is **different every time** the script is executed.
* Start song argument is **useless** when the sort order is random, so it's **not saved** in ``mp3-player-settings.txt``.
* When out-of-range indices are provided as "START_SONG" they will be **normalized** using modulus.