Git Product home page Git Product logo

mkpl's Introduction

make_playlist: Playlist maker

mkpl

mkpl is a command line tool to create playlist files (M3U format).

Installation

To install mkpl, see here:

$ pip install make_playlist               # for python enviroment

$ dnf copr enable matteoguadrini/mkpl
$ dnf install python-make_playlist -y     # for Red Hat and fedora

$ git clone https://github.com/MatteoGuadrini/mkpl.git && cd mkpl
$ pip install .                           # for others

Command arguments

mkpl have many command line arguments. They are explained in this table:

short long description args
-d --directories Directories that contains multimedia file Path of directories
-e --exclude-dirs Exclude directory paths Path of directories
-i --include Include other file format Format of file. ex. mp3
-p --pattern Regular expression inclusion pattern Regular expression string
-f --format Select only a file format Format of file. ex. mp3
-s --size Start size in bytes Bytes number
-m --max-tracks Maximum number of tracks Number
-t --title Playlist title Title string
-g --encoding Text encoding UTF-8,ASCII,UNICODE
-I --image Playlist image Image path
-l --link Add local or remote files Files
-j --join Join one or more other playlist files Playlist files
-r --recursive Recursive search
-a --absolute Absolute file name
-s --shuffle Casual order
-u --unique The same files are not placed in the playlist
-c --append Continue playlist instead of override it
-w --windows Windows style folder separator
-v --verbose Enable verbosity (debug mode)
-S --split Split playlist by directories
-R --interactive Asks each file for confirmation
-C --count Count elements into playlist
-o --orderby-name Order playlist files by name
-O --orderby-date Order playlist files by creation date
-T --orderby-track Order playlist files by track
-y --orderby-year Order playlist files by year
-Z --orderby-size Order playlist files by size
-L --orderby-length Order playlist files by length

Examples

  1. Create a playlist for one music album:

    cd myalbum
    mkpl myalbum.m3u
  2. Create a playlist of a film saga

    mkpl -d HarryPotter -f mkv HP_saga.m3u
  3. Create a shuffled playlist with my music collection

    mkpl -d "my_mp3_collection" "my_mp4_collection" -rs "my music.m3u"
  4. Create a shuffled playlist with my music collection and exclude dirs

    mkpl -d "my_mp3_collection" "my_mp4_collection" -r -s -e "my_mp3_collection/metallica" "my_mp3_collection/dk" "my music.m3u"
  5. Create a TV series playlist with max 15 tracks

    mkpl -d "my_series/GOT" -m 15 "got_first_15.m3u"
  6. Add into my music playlist new songs and don't add same file

    mkpl -d "new_collection" -rsu "my music.m3u" -a
  7. Create playlist with music and video files if files is greater then 10MB

    mkpl -d "my_files" -r -z 10485760 "multimedia.m3u"
  8. Create playlist with only number one and two tracks with regular expression

    mkpl -d "my_mp3_collection" -r -p "^[12]|[012]{2}" "my music.m3u"
  9. Create a playlist for one music album and set the title:

    cd myalbum
    mkpl myalbum.m3u -t "My Album"
  10. Create a playlist and add UTF-8 encoding

    mkpl -d "new_collection" -r "my music.m3u" -g "UTF-8"
  11. Create a playlist and set image

    mkpl -d "new_collection" -r "my music.m3u" -I "new_collection/playlist_cover.jpg"
  12. Create a playlist and add remote file links

    mkpl -d "new_collection" -r "my music.m3u" -l http://192.168.1.123/mp3/song1.mp3, http://192.168.1.123/mp3/song2.mp4
  13. Create a playlist and set Windows backslash (\) folder separator (for Windows OS)

    mkpl -d "new_collection" -r "my music.m3u" -w
  14. Split playlist into N playlists fon N directories

    mkpl -d "folder1" "folder2" "folder3" -r "my_music.m3u" -S

    Result:

    $> ls
    my_music.m3u
    folder1.m3u
    folder2.m3u
    folder3.m3u
    ...
  15. Sort playlist files by name (-o), by creation date (-O), by track number (-T), by year (-y), by size (-Z) or by length (-L):

    mkpl -d "new_collection" -r "my music.m3u" -o
    mkpl -d "new_collection" -r "my music.m3u" -O
    mkpl -d "new_collection" -r "my music.m3u" -T
    mkpl -d "new_collection" -r "my music.m3u" -y
    mkpl -d "new_collection" -r "my music.m3u" -Z
    mkpl -d "new_collection" -r "my music.m3u" -L
  16. Join the "First playlist.m3u" and "Second playlist.m3u8" with new "Third playlist.m3u":

    mkpl -d "new_collection" -r "Third playlist" -j "First playlist.m3u" "Second playlist.m3u8"
  17. Counts the multimedia files:

    mkpl -d "new_collection" -r "My new collection" -C
    4023
  18. Asks confirmation for every file into folders:

    mkpl -d "new_collection" -r "My new collection" -R
    Add file new_collection/sample1.mp3 to playlist? [Y/n]:y
    Add file new_collection/sample2.mp3 to playlist? [Y/n]:Y
    Add file new_collection/sample3.mp3 to playlist? [Y/n]:n
    Add file new_collection/sample4.mp3 to playlist? [Y/n]:N

Use it like Python module

mkpl can also be used as a Python module to customize your scripts.

from make_playlist import *

# Prepare playlist list: find multimedia files with name starts between a and f
playlist = make_playlist('/Music/collections',
                         ('mp3', 'mp4', 'aac'),
                         '^[a-f].*',
                         recursive=True,
                         unique=True)

# Write playlist to file
write_playlist('/Music/AtoF.m3u', 'wt', playlist)

Open source

mkpl is an open source project. Any contribute, It's welcome.

A great thanks.

For donations, press this

For me

paypal

For Telethon

The Telethon Foundation is a non-profit organization recognized by the Ministry of University and Scientific and Technological Research. They were born in 1990 to respond to the appeal of patients suffering from rare diseases. Come today, we are organized to dare to listen to them and answers, every day of the year.

Adopt the future

Treeware

This package is Treeware. If you use it in production, then we ask that you buy the world a tree to thank us for our work. By contributing to the Treeware forest you’ll be creating employment for local families and restoring wildlife habitats.

Treeware

Acknowledgments

Thanks to Mark Lutz for writing the Learning Python and Programming Python books that make up my python foundation.

Thanks to Kenneth Reitz and Tanya Schlusser for writing the The Hitchhiker’s Guide to Python books.

Thanks to Dane Hillard for writing the Practices of the Python Pro books.

Special thanks go to my wife, who understood the hours of absence for this development. Thanks to my children, for the daily inspiration they give me and to make me realize, that life must be simple.

Thanks, Python!

mkpl's People

Contributors

matteoguadrini avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

nearlytrex kopsis

mkpl's Issues

Why am I getting this error?

Traceback (most recent call last):
File "f:\Python Folder\mkpl.py", line 36, in
from mutagen import File, MutagenError, id3
ModuleNotFoundError: No module named 'mutagen'
Thanks,
Pantheon

mkpl fails to create playlist if filenames have characters such as ō

Description

mkpl fails to create playlist if filenames have characters such as ō

Some file names may have other character set / encodings (found in non english languages) and these characters seem to crash mkpl - the error is only apparent if you enable verbose output (-v). If verbose is not enabled, it will say the playlist argument is not defined.

Example output (Windows):
mkpl -d c:\temp\ -v test.m3u
debug: formats={'aiff', 'mp2', 'avi', 'mp1', 'm4a', 'alac', 'mp3', 'wmv', 'opus', 'xvid', 'wma', 'wav', 'ogg', 'mpg', 'mov', 'mpeg', 'divx', 'mp4', 'flac', 'aac'}, recursive=False, pattern=.*, split=False
debug: current directory=c:\temp, root=c:
debug: add multimedia file temp\Test - ō.mp3
debug: write playlist test.m3u
Traceback (most recent call last):
File "", line 198, in _run_module_as_main
File "", line 88, in run_code
File "C:\Users\keef\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\Scripts\mkpl.exe_main
.py", line 7, in
File "C:\Users\keef\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\mkpl.py", line 345, in main
_process_playlist(multimedia_files, args)
File "C:\Users\keef\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\mkpl.py", line 301, in _process_playlist
write_playlist(other_playlist if other_playlist else cli_args.playlist,
File "C:\Users\keef\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\mkpl.py", line 182, in write_playlist
pl.write(joined_string.join(files[ext_part:max_tracks]) + end_file_string)
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.1008.0_x64__qbz5n2kfra8p0\Lib\encodings\cp1252.py", line 19, in encode
return codecs.charmap_encode(input,self.errors,encoding_table)[0]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
UnicodeEncodeError: 'charmap' codec can't encode character '\u014d' in position 12: character maps to

Steps to Reproduce

Try to create a playlist from a directory which contains a filename having non english characters such as ō

Line of code
Unknown

Expected Behaviour

  • Better error handling - it should skip any problematic files and move on to the next
  • Preferably, allow these file names to be added to the playlist

Your Environment

Python 3.11

  • mkpl version used: 1.6.0
  • Operating System and version: Windows 11

Additional context

mkpl enhancement - Support .opus files

Description

Description of the proposal

Enable support for OPUS format files.

Proposed names of the parameters (short and long)

None needed.

  • name parameter
  • possible argument(s)

Additional context

This error is reported for a directory with *.opus files:

warning: no multimedia files are found here:

mkpl enhancement: cache

Description

Cache added tracks

Description of the proposal
Add option to cache tracks added to playlist for specified time, so that they aren't available for adding to playlist till their cache period is over.

Proposed names of the parameters (short and long)

  • name parameter: cache
  • possible argument(s): time(in days)
    • --cache (default when called with out the time):30 days)
    • --cache 60

mkpl enhancement: add ability to order playlist entries by file "track" metadata

Description

Description of the proposal
See issue #4 for evolution of this idea.

It would be great to have the default be to order tracks lexically in playlists by their "track" tag/metadata, and then my filename if no metadata is found. This default behavior could avoid having to specify a flag for this. The use of a metadata parsing library could be extended to add filters as CLI flags, which would filter files based on metadata, for other enhancements, but this is perhaps an extension of the kernel of this enhancement.

Proposed names of the parameters (short and long)

N/A, for this enhancement; posssibly --order-by with "filesystem" "metadata:track" as arguments, if it was absolutely necessary.

  • name parameter: N/A
  • possible argument(s) N/A

Additional context
See issue #4 as mentioned.

mkpl enhancement

Description

Create a m3u file recursively for every directory?

Proposed names of the parameters (short and long)

-rd recursive directory

Additional context

I think a lot of music collectors follow a folder structure and an easy way to update all their folders with one command will be very helpful

Also, Thanks for creating this project👍 Found this on ask.ubuntu

typo and suggestion one more include file type, utf8 encoding default

7. Create playlist with music and video files if files is greater then 10MB

7. Create playlist with music and video files if files are greater than 10MB

still haven't tried it out yet but will soon. Just by looking at the examples I'm not clear the difference between

-f | --format | Select only a file format | Format of file. ex. mp3

-i | --include | Include other file format | Format of file. ex. mp3

so is -i like appending -i mp3 opus (so adding multiple files)
-f is saying choose mp3 and exclude all others?

mkpl -d "new_collection" -r "my music.m3u" -g "UTF-8"
Also is there a reason why utf-8 encoding isn't the default? I remember pysubs2 eventually made it the default about a year or so ago.

the sort and regex features are awesome..very powerful stuff...

Shuffles order every time

I can't find a way to instruct mkpl to create playlist "in album order".
it's like the "shuffle" option is always set.
basically this is what happens:

$ cd Electric\ Light\ Orchestra\ (1975)\ Face\ The\ Music/

$ mkpl test.m3u

$ cat test.m3u
11 - Strange Magic [Single Edit].m4a
01 - Fire On High.m4a
03 - Evil Woman.m4a
06 - Strange Magic.m4a
04 - Nightrider.m4a
07 - Down Home Town.m4a
05 - Poker.m4a
10 - Evil Woman [Stripped Down Mix].m4a
09 - Fire On High [Early Alternate Mix].m4a
12 - Waterfall [Instrumental Mix].m4a
08 - One Summer Dream.m4a
02 - Waterfall.m4a

Ability to use full paths in the playlist file output

Description

Currently the playlist is generated relative to the directory, for example if I have my files in c:\files\music\ and run mkpl from c:\files\ the generated playlist items will have the path music\tune.mp3

Can an option be added to enable full paths (c:\music\tune.mp3)

Proposed names of the parameters (short and long)

-fp -fullpath

mkpl shuffle and extension bug

Description

When specified the --shuffle flag and one of exensions attribute as --title or --encoding, the first three lines are shuffled with tracks.

Steps to Reproduce

$ mkpl "test.m3u" --shuffle --title "My test shuffled" --directories /mymusic
$ cat "test.m3u"
/mymusic/track1.mp3
/mymusic/track14.mp3
#EXTM3U
/mymusic/track2.mp3
#PLAYLIST: My test shuffled
...

Expected Behaviour

The first three lines remains unchanged.

Your Environment

  • mkpl version used: 1.2.0
  • Operating System and version: linux Fedora 36 x86_64

mkpl enhancement - Add argument (option) to replace spaces in filenames with %20 (space code)

Description

Some files I have struggle to play on mpv, some contain ' or - and this when coupled with spaces or double spaces like somefile what' s going on -seg01.mp3 (note the double spaces before -seg01 makes the player refuse to play.

Proposed names of the parameters (short and long)

  • name parameter = safe names
  • possible argument(s) = --safe_names (-sn)

Additional context

The idea is to pass the proposed "--safe_names" or "-sn" argument to replace spaces with %20 thus making the example file from above to be added like: somefile%20what'%20s%20going%20on%20-seg01.mp3 thus making the file playable again and bypass mpv's strange tendency to read m3u entries as arguments if the files have spaces or special characters.

Order by Track

When using -T (order by track) it treats the track number as text rather than an int and does not sort properly as a result. The track order sorts as

1,10,11,12,...,19,2,20,21,...,etc

Fixed by converting track number to an int as below

def get_track(file):
"""Get file by track for sort"""
file = open_multimedia_file(file)
if file and hasattr(file, "tags"):
default = id3.TRCK(text="0")
return int(file.tags.get("TRCK", default)[0])

[Q&A/HELP] make m3u based on track ID?

i have a huge music collection now , but the problem i did while ripping them is, they have names that do no start with numbers
, instead they start with music file names , that's a problem , since mpv plays files based on alphatic order .

i just want mkbl to make m3u list of album i am going to play , in track number order and feed to it mpv

this are the some other post of same question :
https://www.reddit.com/r/mpv/comments/10sp0ge/questionhelp_force_to_play_track_based_upon_track/

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.