pMusic DB and file format


pMusic is an audio-player using a database (DB) to keep track of meta-information of your music. This is info like:
  • ID3-tags (artist, title, album, ...) that are embedded into the file.
  • links to lyrics, albumart, ...
  • Stream info like format, samplerate, bpm, ...
  • User listening activity.

  • While most players depends on an external DB like Mysql or Mariadb, pMusic has its own, very simple, internal DB. Basically it is a textfile with 21 columns separated by a |, where each line contains info of one file. When reading from the DB (ie. when searching), we just grab the line(s) corresponding to our request.

    To make the infra-structure simple; the DB, the sourcelist (search-result-field) and the internal file format (*.pmd), uses the exact same formating. That means, we can dump the raw output of the DB to the gui, a favorite list, or ie. to the smart-add function. This helps a lot when it comes to speed. Sometimes you might forget that pMusic is not compiled binary, but just a bash script.

    GeekNote: To be technically correct, the sourcelist and *.pmd file contains only the first 15 columns of the DB format. They have no use of the last items of info.


    The DB structure

    Let's look at one line of my DB:
    /mnt/sdb1/musikk/Tindrum - Drums Of War.mp3|Tindrum|Drums Of War|Drums of war|1|1988|Hard Rock|Live||mp3|175|04:02|117|/mnt/sdb1/musikk/Tindrum - Drums Of War.mp3|gtk-audio|2aa59ada-3dd8-40b7-878a-bb682fca7b30|479933cd-d787-4126-8315-7749ca4781a1|Tindrum|/mnt/home/pmusic storage/albumart/Tindrum - Drums Of War.jpg||,1357415329,1357417187

    This line holds all info we got about this track. Instead of explaining what it all means, just open up the DB-editor found in Menu > Music sources > My Music. Here we can look at, and edit all info in the DB.



    Most of this is straightforward, but 3 things might not seem logical:

  • The Command (column 1) and the Path (column 14) is equal. The Command is executed when adding stuff to the playqueue. The Path is what it says - the local path. Because the example shows a local file taken from the DB textfile, the command is equal to the path. This is not the fact for an url pointing to a radio-station web address.

  • The last column, Timestamps, is not self explanatory. Each time you has played a song, the DB adds the given time in seconds since 1970 to the end of the line. This is used to provide better sorting depending on your preferred music. And, to search for your most played songs ie. in February.

  • Column 7 - Rate - is empty, and it is always empty in the DB textfile, but not in the sourcelist (left pane). The rating is equal to number of timestamps, and is calculated in func_rating. This calculation also change the icon depending on the song's rating. Geeknote: This is a great example of the blinding speed of awk.


  • Writing to the DB

    pMusic allows 2 major ways to write info to the DB. Either by (1) user interaction or the default (2) silent mode.

    (1) user interaction
    The static way is to start the indexer (Menu > Music sources > My Music) which scans your system for audio-files and adds the info to the DB. Depending on your music collection, this might take a long time, but place all available information (ID3-tags and stream info) to the DB at once.

    (2) silent mode
    The default dynamic behavior is to store info as you play. When you press the Play-button, pMusic
  • checks the file for ID3-tags and stream info.
  • searches the web for lyrics, albumart and artist info. (Must be activated in the preferences.)
  • tries to build an album-list if tracks are available on your system. (Must be activated in the preferences.)

  • If using mode (1), we still miss info from the web and album lists, so mode (2) will kick in anyway for missing info.

    All this info must be written to the DB - but that's not straightforward - we can't just start writing...
  • To avoid parallel writings to the DB, there exist a queue-system (DB is locked while writing).
  • To avoid a long queue (many locks are resource hungry), the info is passed to a DB-stack. The DB-stack can hold several info-capsules.
  • Writing to the DB, empties the stack in one operation. This avoids the queue to grow.

  • The stack is found at $HOME/.pmusic/tmp/mymusic_stack.
    The merging is done at func_index -merge_stack.


    Keep the DB in shape

    In addition, there are mechanisms to keep the DB in shape. When you add a file to the playqueue, pMusic checks it in func_add - functions check_source and fix_db.

    If the added file is not already in the DB, ask user to scan the source directory for new music. This message shows up embedded in the main window to not disturb the user too much. It could be that we don't want to respond to this message, and that is just ok.



    If the added file has its line in the DB, but not present in your system, something should probably be updated, and this message below will show up. But, if the filename is found in the DB with another path than the defined, pMusic will play the alternative source instead. Therefor, this box is not often seen in recent versions of pMusic.




    The Playlist file format

    I mentioned earlier the internal file format *.pmd used by ie. the favorites structure. But, for the user, the pMusic format is the *.pmu found in the save box. You can choose to save to an external format as *.m3u or *.pls, but to get the full power of pMusic, *.pmu is the recommended choice. This because it cooperates well with the DB.

    *.pmu contains the same info as in the playqueue. This makes it possible to dump a *.pmu into the playqueue, while a *.m3u has to be converted. Since all information in a *.pmu is grabbed from the DB, we can quickly revert, and grab the full track-info back from the DB. This is seen when expanding a *.pmu in the sourcelist (left pane). - We see full track-info including rating calculation. When expanding a m3u/pls we only see the actual info inside the file.

    When looking at the playqueue in the gui, you see 3 columns:
    Length | Track title | Path

    In fact there are 2 more hidden columns, and all are part of the *.pmu file:
    Icon | Length | Track title | Path | ID

    The Icon holds gtk-play when the play-icon is shown, else it's empty. This will of course always be empty inside a *.pmu file
    The ID holds an unique id-number together with the path. This is necessary to avoid conflict when playqueue contains several instances of the same song. The ID keeps track of which of the similar songs you are playing/moving/editing.

    Unlike *.m3u, the *.pmu playlist does not handle relative paths. This to stay close to the DB format. Instead pMusic will search for an alternative path if playing track is not found. The statusbar will show this information during search. Code found in func_progressbar.

    The short story of the pMusic file formats is:
    *.pmd mirrors the DB
    *.pmu mirrors the playqueue


    This is the basic structure of the pMusic data format.

    Posted on 9 Jul 2016, 18:54 by zigbert - Categories: Development
    Edit - Delete


    No comments posted yet.

    Add Comment

    Title
    Author
     
    Content
    Show Smilies
    Security Code 7319650
    The Puppy Linux mascot?
    Password (to protect your identity)