lpinca / binb

:notes: Competitive, multiplayer, realtime, guess the song game
https://binb.co
MIT License
291 stars 61 forks source link

Importing large list / Changing categories #33

Closed Scratchmang closed 4 years ago

Scratchmang commented 4 years ago

Hey there, not sure if this is still being maintained but I stumbled upon BINB and it's a damn good bit of code.

Anyway, when I try to add a bunch of new artists, (80's 90's) I keep getting the infamous "Cannot read property 'toLowerCase' of null" when I run "npm start"

At first I thought it was due to non-ascii characters so like an 'o' with an Umlaut "ö" so I converted everything and ensured there were no accents anywhere. Also removed other characters like '!' and the '&' symbol, replacing them where possible so '&' became 'and' still no joy.

Is there some sort of required formatting? I'm not sure how the names of the Bands are pulled into the Database, is it done from the file artist-ids.js or does the program pull them directly from iTunes and therefor unable to handle names like "Mötley Crüe"?

Not a programmer by any means, but any assistance would be appreciated.

Thanks in advance

Scratchmang commented 4 years ago

Oh and I forgot to add.

How do I chance (or can I change) the categories? So rather than having Rock/Pop/Oldies, would it be possible to have 70's/80's/90's etc....?

lpinca commented 4 years ago

You get that error when the databases does not contain the correct data. Specifically when there are no songs to play in a room.

Rooms can be added in config.json file but songs must be added manually. The load_sample_tracks.js is there only to show how to do it.

Scratchmang commented 4 years ago

So I'm assuming they are imported from "artist-ids.js" which I have populated with all the artist ID's from iTunes.

How does it determine which song goes in which category? I'm missing something here I know. Sorry

lpinca commented 4 years ago

That is only an example. Assume you want to add "Madonna - Like a Virgin" in the Pop room, you first search the data with iTunes Search API:

curl "https://itunes.apple.com/search?term=madonna+like+a+virgin&entity=song" | jq

Then you add it to the pop station as shown in load_sample_tracks.js. Hope it makes sense.

The relevant bits are

https://github.com/lpinca/binb/blob/b41a023edba3e03ed47919bcd5acd2d4e8a90231/util/load_sample_tracks.js#L59-L73

and

https://github.com/lpinca/binb/blob/b41a023edba3e03ed47919bcd5acd2d4e8a90231/util/load_sample_tracks.js#L77

Scratchmang commented 4 years ago

I'm sorry, but no, it's not exactly 'clear' to me how this works. I must be half way there as some things appear to be working. I've not made any changes (additions to) load_sample_tracks.js I've only changed (edited) the artist-ids.js which now looks like this....

'use strict';

/**

module.exports = { pop: [ 32940, // Michael Jackson 659587, // Prince & The Revolution 20044, // Madonna 78500, // U2

And so on to the end...

What I am seeing here is that I need to add each artist individually to the load_sample_tracks.js? Again I think I am missing something here. Please excuse my lack of programming knowledge, I'm learning here as I go, and I do appreciate responses to my questions.

lpinca commented 4 years ago

Ignore completely artist-ids.js and load_sample_tracks.js, and focus on the two small snippets I posted above. Remove all rooms and only keep one.

To add a song there you need to run

HMSET song:1 artistName Madonna ...

you can get values for each field from iTunes Search API.

The second command is

ZADD pop <score> 1

score is per room and should be a number that is incremented for each song in that room.

Scratchmang commented 4 years ago

Perhaps a working sample would help?

Again I do apologize for not fully understanding here. You say to ignore the two files artist-ids.js and load_sample_tracks.js. I can see form the command you provided earlier

curl "https://itunes.apple.com/search?term=madonna+like+a+virgin&entity=song" | jq

That the output is formatted better than the original way I was pulling artistID's (that's a huge help) So using your example for Madonna I get...

{ "wrapperType": "track", "kind": "song", "artistId": 326259248, "collectionId": 410220135, "trackId": 410220249, "artistName": "Brazil XXI & Silvinha Santana", "collectionName": "Bossa N' Madonna", "trackName": "Like A Virgin", "collectionCensoredName": "Bossa N' Madonna", "trackCensoredName": "Like A Virgin", "collectionArtistId": 36270, "collectionArtistName": "Various Artists", "artistViewUrl": "https://music.apple.com/us/artist/brazil-xxi/326259248?uo=4", "collectionViewUrl": "https://music.apple.com/us/album/like-a-virgin/410220135?i=410220249&uo=4", "trackViewUrl": "https://music.apple.com/us/album/like-a-virgin/410220135?i=410220249&uo=4", "previewUrl": "https://audio-ssl.itunes.apple.com/itunes-assets/Music/08/c5/5b/mzm.madqngiu.aac.p.m4a", "artworkUrl30": "https://is4-ssl.mzstatic.com/image/thumb/Music/v4/c6/ad/b8/c6adb866-11ac-05de-3a70-b97fd34d651a/source/30x30bb.jpg", "artworkUrl60": "https://is4-ssl.mzstatic.com/image/thumb/Music/v4/c6/ad/b8/c6adb866-11ac-05de-3a70-b97fd34d651a/source/60x60bb.jpg", "artworkUrl100": "https://is4-ssl.mzstatic.com/image/thumb/Music/v4/c6/ad/b8/c6adb866-11ac-05de-3a70-b97fd34d651a/source/100x100bb.jpg", "collectionPrice": 9.99, "trackPrice": 1.29, "releaseDate": "2011-01-25T12:00:00Z", "collectionExplicitness": "notExplicit", "trackExplicitness": "notExplicit", "discCount": 1, "discNumber": 1, "trackCount": 12, "trackNumber": 6, "trackTimeMillis": 249120, "country": "USA", "currency": "USD", "primaryGenreName": "Electronic", "isStreamable": true },

To use just one song of hers. (I'd never seen 'jq' before thank you for that one) But form there? Not sure as to what you mean? Do I create a new file with all the information? You said to ignore artist-ids.js and load_sample_tracks.js.... Again I'm sorry for allt he questions and my confusion as to what needs doing here.....

Scratchmang commented 4 years ago

Oh wait....

HMSET is from the redis-cli.....

So I need to add them manually to the database.....

so first I need to run the redis-cli then "HMSET song:1 artistName Madonna ..."

What's the full line supposed to look like?

HMSET song:1 artistName Madonna, trackName "Like A Virgin", trackViewUrl "https://music.apple.com/us/album/like-a-prayer/202971254?i=202971388&uo=4", previewUrl "https://audio-ssl.itunes.apple.com/itunes-assets/Music/22/f9/1d/mzm.svgqlihg.aac.p.m4a", artworkUrl60 "https://is2-ssl.mzstatic.com/image/thumb/Music/v4/f3/65/e7/f365e720-a273-01a2-e99a-83ac3f0adc42/source/60x60bb.jpg", artworkUrl100: "https://is2-ssl.mzstatic.com/image/thumb/Music/v4/f3/65/e7/f365e720-a273-01a2-e99a-83ac3f0adc42/source/100x100bb.jpg"

That's beginning to make sense.

Then once that one is in,

ZADD pop _score 1

And that would add song 1 to the Group "pop" but what's the 'score'?

And this would continue so if I added a second song, it would be

HMSET song:2 artistName Megadeath etc....

and ZADD metal _score 2

Am I beginning to understand this now?

lpinca commented 4 years ago

Yes correct, remove the commas from HMSET. score is an integer that you should increment every time you add a song in a room. It is per room so if you add a songs in pop and one in rock score is 1 in pop and 1 in rock.

Scratchmang commented 4 years ago

I'm starting to understand. Thank you so much for taking the time to answer my questions. If it's OK with you please leave this issue open for a bit while I try and make my way thru all of this and update my installation. I'll document everything I do and pass it along if you want to add it to your documentation for binb so you won;t have to go thru all of this again next time someone as new to all of this comes along.

lpinca commented 4 years ago

Well, all of this can be deducted by reading load_sample_tracks.js, it's pretty simple for a developer.

Scratchmang commented 4 years ago

I'm sure. But then I'm not a developer :) I'm just a regular hobbyist who has a very (and I do mean VERY) limited understanding of what's happening here. It was quite confusing to me I am not ashamed to admit :)

However, with that said, and with your assistance I think I have managed to wrap my head around it all. I just need to figure out how to "Automate" it a little bit so as to make things a bit simpler for those of us who have a little less knowledge is all.

Again, my deepest thinks for your help and you assistance in pointing me int he right direction. I'll update you with the results of my experiments in getting a bunch of songs added...

Scratchmang commented 4 years ago

OK,

So I think I am getting closer to where i need to be. As of now I have a file looking like this...

HMSET song:1 artistName "Madonna" trackName "Like a Vi........." HMSET song:1 artistName "Madonna" trackName "Love Don'........." HMSET song:1 artistName "Madonna" trackName "Material ........."

I'm assuming that the 'song:1' needs to increment by 1 for each song? so it really should look like this....

HMSET song:1 artistName "Madonna" trackName "Like a Vi........." HMSET song:2 artistName "Madonna" trackName "Love Don'........." HMSET song:3 artistName "Madonna" trackName "Material ........."

And so on. eventually ending up with something like

HMSET song:23845 artistName "ZZ Top" trackName "Sharp Dres ........."

And the ZADD would look like this.... ZADD pop 1 1 ZADD pop 2 2 ZADD pop 3 1

all the way to ZZTOP

ZADD rock 1 23845

Am I beginning to understand this?

Scratchmang commented 4 years ago

So....

Progress last night. I've created a script that reads a list of band names and creates a file with all the relevant information. Makes things a lot quicker when grabbing songs for 20+ groups.

Anyway, just got on a plane will update more in a couple of days

Scratchmang commented 4 years ago

OK,

Back form the holidays and back to working on this. Again please excuse my limited knowledge of the Database and how it all works. I'm making progress I think...

Anyway, I have a script that reads a text file which contains band names the list of names is called 'list.bnd' and is formatted like this..

Outkast Eminem Coldplay Radiohead Kanye+West Alicia+Keys U2 System+of+a+Down The+White+Stripes Green+Day Red+Hot+Chili+Peppers

As the CURL statement does not seem to work with 'spaces' they are replaced with a '+' sign.

The script itself (Attached) then reads in the name of the band, does the curl query to iTunes, dumps the results, and eventually once it is complete leaves me with a file looking like this...

HMSET song:1 artistName "Outkast", trackName "Ms. Jackson", trackViewUrl "https://music.apple.com/us/album/ms-jackson/255836651?i=255836745&uo=4", previewUrl "https://audio-ssl.itunes.apple.com/itunes-assets/Au$ HMSET song:2 artistName "Outkast", trackName "Hey Ya!", trackViewUrl "https://music.apple.com/us/album/hey-ya-radio-mix-club-mix/281430653?i=281430764&uo=4", previewUrl "https://audio-ssl.itunes.apple.com/itune$ HMSET song:3 artistName "Outkast", trackName "So Fresh, So Clean", trackViewUrl "https://music.apple.com/us/album/so-fresh-so-clean/255836651?i=255836736&uo=4", previewUrl "https://audio-ssl.itunes.apple.com/it$ HMSET song:4 artistName "Outkast", trackName "B.O.B.", trackViewUrl "https://music.apple.com/us/album/b-o-b/255836651?i=255837382&uo=4", previewUrl "https://audio-ssl.itunes.apple.com/itunes-assets/AudioPreview$

And so on till the end of the file...

HMSET song:1331 artistName "At the Drive-In", trackName "Hostage Stamps", trackViewUrl "https://music.apple.com/us/album/hostage-stamps/1207471331?i=1207471435&uo=4", previewUrl "https://audio-ssl.itunes.apple.$ HMSET song:1332 artistName "At the Drive-In", trackName "Chanbara", trackViewUrl "https://music.apple.com/us/album/chanbara/1443564291?i=1443564303&uo=4", previewUrl "https://audio-ssl.itunes.apple.com/itunes-a$ HMSET song:1333 artistName "At the Drive-In", trackName "Transatlantic Foe", trackViewUrl "https://music.apple.com/us/album/transatlantic-foe/1443564291?i=1443564492&uo=4", previewUrl "https://audio-ssl.itunes.$

From here, I'm assuming I have to do a redis-cli hmset function for all the songs?

And then the ZADD function... Still muddling my way thru all this...

I've attached the script for you to look at if it's of interest.

art.txt

Igor-Lira commented 4 years ago

see this video where I create a room using spotfy playlist https://www.youtube.com/watch?v=-oBlpM3Mvqk&feature=youtu.be