Jump to content

How to setup Relations (?) for a MP3 DB with PW?


horst
 Share

Recommended Posts

Hi, I'm thinking on using PW to scan my MP3-folders and want ask how you would organize the data.
 
I want to store 'Trackname', 'Artistname',  and 'Albumname' & 'Tracknumber', if Track belongs to an Album. (most will do, but not all).
 
I want to be able to do fast (Selector) searches and sortings on combinations of this fields.
 
Any suggestions for a PW-newbie?

Link to comment
Share on other sites

Hi horst,

my suggestion:

Template artist

- title

- other metadata from artist

Template album

- title

- artist (Page field with template artist)

- cover (image)

Template song

- title

- tracknumber

- album (Page field with template album)

If a song/track doesn't have an album, you can leave the album page field empty.

EDIT:

Just noticed that when a song doesn't belong to an album, you cannot get the artist.

So maybe adding the artist field also to song? Hmm... let me think again :P

Possible solution here

Another possible way is to organize over the page tree:

- Artists (artists)

--+ artist1 (artist)

----+ Albums (albums)

------+ album1 (album)

---------+ song1 (track)

---------+ song2 (track)

------+ album2 (album)

---------+ song1 (track)

....

----+ Songs (songs)

------+ song_that_does_not_belong_to_album (song)

--+ artist2 (artist)

....

Depends on the search queries. Organizing this way you don't need page reference fields.

Searches are then over parents/childrens.

  • Like 2
Link to comment
Share on other sites

Hi Wanze, many thanks for your suggestions!

...
 
EDIT:
Just noticed that when a song doesn't belong to an album, you cannot get the artist.
So maybe adding the artist field also to song? Hmm... let me think again :P

With the first one I'm not sure how to solve that.

Another possible way is to organize over the page tree:
 
- Artists (artists)
--+ artist1 (artist)
----+ Albums (albums)
------+ album1 (album)
---------+ song1 (track)
---------+ song2 (track)
------+ album2 (album)
---------+ song1 (track)
....
----+ Songs (songs)
------+ song_that_does_not_belong_to_album (song)
--+ artist2 (artist)
....
 
Depends on the search queries. Organizing this way you don't need page reference fields.
Searches are then over parents/childrens.

 

The second one would just reflect the filesystem. Not bad, because it's like i use it since ever :-)


---


But (maybe it's totally silly): could it be an option to have only one Template (Tracks) with the fields: Artist, Album, Trackname Tracknumber, and some other (tracklength, ...) and one record per mp3file?

Or will this slow down PW by searching / sorting? (15 - 20.000 files)

(I came up with this when thinking about how to solve your first suggestion)

Link to comment
Share on other sites

Hi Wanze, many thanks for your suggestions!

With the first one I'm not sure how to solve that.

The second one would just reflect the filesystem. Not bad, because it's like i use it since ever :-)

---

But (maybe it's totally silly): could it be an option to have only one Template (Tracks) with the fields: Artist, Album, Trackname Tracknumber, and some other (tracklength, ...) and one record per mp3file?

Or will this slow down PW by searching / sorting? (15 - 20.000 files)

(I came up with this when thinking about how to solve your first suggestion)

The problem if you store everything in one template: You have redundant data.

For example: You store the same album title 11 times if you have 11 tracks.

If you have 120 tracks of the same artist, you will store the artist 120 times in a text field. What happens if the band changes their name? :)

Maybe not a good example, but in a relational database you should (almost) never store redundant data.

Can you explain or give some examples what kind of queries you want to do?

Maybe this helps us further how to structure the data.

Link to comment
Share on other sites

...

If you have 120 tracks of the same artist, you will store the artist 120 times in a text field

...

but in a relational database you should (almost) never store redundant data.

Can you explain or give some examples what kind of queries you want to do?

Maybe this helps us further how to structure the data.

Ah, I did know it: it was totally silly!  :wacko:

---

I'm not sure, and I've forgotten the Genre-Field, but I think mostly I want to search for an Artist or an Album or a Genre, - or, what would be really nice: want to have 50 or any number random Tracks of specified Genre or Artist as playlist output.

Link to comment
Share on other sites

Hey Macrura,
 

ok, I will try to help out, since i'm interested in having some reusable code for this..
 
in the meantime, here are some things that might help:
 
http://www.script-tutorials.com/id3-tags-reader-with-php/
http://getid3.sourceforge.net/

 
really nice that you want to help out!
 
- But, with this id3 reading and writing stuff I'm allready perfectly equipped. :D
 
- What would be good to have is functional mp3-streaming code.
 
Playlistgeneration and ServersidePlaying (for win) is already in tha house, too. ;)

Link to comment
Share on other sites

I think the easiest queries you can build with a template structure that is the following:

Template artist

- title

- genre (Page field with template genre)

- other metadata from artist

Template album

- title

- artist (Page field with template artist)

- cover (image)

Template track

- title

- tracknumber

- tracklength

- file (mp3)

- album (Page field with template album)

Template genre

- title

This way, you have all your pages on a separate "branch" in your tree - but the data is related through page fields.

+Artists

--+ artist1

--+ artist2

+Albums

--+ album1

--+ album2

+Tracks

--+ track1

--+ track2

+Genres

--+ genre1

--+ genre2

Sample queries:

// Search for artists
$artists = $pages->find("template=artist, title=Metallica|Queens of the Stone Age");

// Search 50 random tracks by artists with genre Rock
$genre = $pages->get("template=genre, title=Rock");
$artists = $pages->find("template=artist, genre=$genre"); //If you have lot's of artists, you should limit here too and select random artists
$tracks = $pages->find("template=track, artist=$artists, sort=random, limit=50");

// Get all albums of an artist
$albums = $pages->find("template=album, artist.title=Dieter Bohlen") 

The issue with the track that doesn't belong to an album could be solved by creating an album "unknown" per artist and reference

this album in the track.

Did I already say that I love ProcessWire? :wub:

  • Like 3
Link to comment
Share on other sites

...

// Get all albums of an artist

$albums = $pages->find("template=album, artist.title=Dieter Bohlen") :P

$albums.deleteAll(); // << you forgot :P

The issue with the track that doesn't belong to an album could be solved by creating an album "unknown" per artist and reference

this album in the track.

Did I already say that I love ProcessWire? :wub:

^-^

Great!

  • Like 1
Link to comment
Share on other sites

I'm thrilled to see the final result.

+1 Horst for your Idea.

Would be another great example of PWs flexibility

Thanks Luis. - so have to say: I only want put together the basic stuff but also want to keep it modular and scalable. For example I personally only use mp3-files but if people use other formats like ogg they should be able to extend the class module for that easily.

Maybe with some help it could become really nice and not only poor basic ;-)

If someone has good skills on how to build / design / layout admin pages with that UI-stuff it would be really helpful if he/she could design the output for the backend.

Also if someone is good with frontend design and want to collaborate that would be great too.

I have a really short screencast of what I have done till now, (most of this was learning how to send green or red messages to admin screen, how / where to store config data, to create permissions and roles, and basically how to create a module that has a page in the admin section, ...):

https://youtu.be/u_S8ajLkzRI

Next steps are to parse ID3Tags, compare file-data with DB-data and import new tracks.

Question: is it possible to store arrays or WireData on a page?

  • Like 4
Link to comment
Share on other sites

have had some hours last evening ;)(exactly 8 'til now)

I think I can finish the import next time I get 2-3 hours. So, don't know when now.

There is some trouble with chars in filenames and ID3-Tags that want not get into the DB, so I have played around with sanitizer, but have to go deeper and change the current behave. :D

Here are a screencast of the backend, starting with an empty DB (no mp3 data in it)

set one or more pathes, do a quick filesystem scan (without parsing ID3 etc)

envoke a command line script to perform scan with parsing mp3 files and pull data into DB:

(please look fullscreen or otherwise enlarge Video)

https://youtu.be/Re08fuNFRao

  • Like 4
Link to comment
Share on other sites

  • 2 weeks later...

So, - that thing with the Titles (sanitizing but leave spaces, etc) seams to be solved.
 
Also basic stream support is added.
 
The output to the frontend is only a simple menu and information about current page. It's made for coders :grin:
 
You may have a look to output (it's a bit like var_dump) and the code in the 2 Templatefiles. That's intended as starting point for your own Frontend creation.
 
There is an own caching mechanism with the LocalAudioFiles-module. It caches the menus and the DB-infos. It refreshes them when DB gets modified or you may permanently disable caching in the modules page.
 
Here are the latest screencast:
https://youtu.be/qeT5s013GUE
 
and here without audio for the german audience :(
https://youtu.be/MefyBCDDXrs
 
I want upload the first site profile, but have got an error when importing (Can't save page 0: /genre//: It has empty 'name' field). So I first want to fix that and upload siteprofile after that. (Maybe tomorrow evening)

  • Like 4
Link to comment
Share on other sites

Hi, here are the first SiteProfile:
 
There is currently some weird behave with the importer. So if you will run into something similar, it is only a intermediate state to create duplicate artists ;-)

Also the importer part has to be more justified when it comes to duplicate Tracknames but from different Artists/Albums.

- All of it is in a very basic an early state! But if you like to play with it you are welcome. If you do some tweaks (regardless of frontend, backend, module-code) please share it here.

  • Like 1
Link to comment
Share on other sites

Horst,

I have tested this a little bit. Wanna show you something soon (hint, hint). :-X

I noticed that the genre field is designated as a multiple page select under "Type" yet in the input tab under "Input field type" it is designated as "select" rather than one of the multiple page selection types. In my template files, I cannot access the value of the genre field of an Artist page. I get the ID when I echo the results e.g. $page->genre, but not the name of the genre when I do $page->genre->title. I am guessing the wrong input type is causing this problem? I have had similar issues in the past where I selected the wrong input type. However, I haven't yet changed the input type to find out in this case...will check later.

Thanks.

Link to comment
Share on other sites

I have tested this a little bit. Wanna show you something soon (hint, hint). :-X

Oho! :)

 

I noticed that the genre field is designated as a multiple page select under "Type" yet in the input tab under "Input field type" it is designated as "select" rather than one of the multiple page selection types. In my template files, I cannot access the value of the genre field of an Artist page. I get the ID when I echo the results e.g. $page->genre, but not the name of the genre when I do $page->genre->title. I am guessing the wrong input type is causing this problem? I have had similar issues in the past where I selected the wrong input type. However, I haven't yet changed the input type to find out in this case...will check later.

 

I have allready noticed that the (page) fields are not set correct. But I also have solved the importer problem.

 

Should I wait with updating the Profile until you have checked that with the genre field?

 

 

 

---------------------------------------------------------

I also have found some nice audioplayers:

 

about Sounds in HTML-Pages:

and some Players:-----------------------------------------------------------
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...