I'm working on some PHP code that would grab a music playlist from a remote radio page - which means it is continuously updated. I would like to store the tracks history in my database.
My problem is that I need to detect when new entries have been added to the remote tracklist, knowing that :
- I don't know how often the remote page will be updated
- I don't know how many tracks are displayed on the remote page. Sometimes it will be a single track, sometimes it will be a few dozen.
- A same track could show up several times.
For example, I will get this data when grabbing the page for the first time :
- Dead Combo — Esse Olhar Que Era Só Teu
- Myron & E — If I Gave You My Love
- Hooverphonic — Badaboum
- Alain Chamfort — Bambou - Pilooski / Jayvich Reprise
- William Onyeabor — Atomic Bomb
- Curtis Mayfield — Move on up - Extended version
- Mos Def — Ms. Fat Booty
- Nicki Minaj — Feeling Myself
- Disclosure — You & Me (Flume remix)
- Otis Redding — My Girl - Remastered Mono
Then on the second time I'll get :
- Charles Aznavour — Emmenez moi
- Mos Def — Ms. Fat Booty
- Rag'n'Bone Man — Human
- Bernard Lavilliers — Idées noires
- Julien Clerc — Ma préférence
- The Rolling Stones — Just Your Fool
- Dead Combo — Esse Olhar Que Era Só Teu
- Myron & E — If I Gave You My Love
- Hooverphonic — Badaboum
- Alain Chamfort — Bambou - Pilooski / Jayvich Reprise
As you can see, the second time, I got entries 7->10 that seems to be the same than the first time (so entries 1->6 are the new ones); and track #2 was already played in the first list but seems to have been replayed since.
The new entries here would be :
- Charles Aznavour — Emmenez moi
- Mos Def — Ms. Fat Booty
- Rag'n'Bone Man — Human
- Bernard Lavilliers — Idées noires
- Julien Clerc — Ma préférence
- The Rolling Stones — Just Your Fool
I store tracks entries in a table, and tracks history in another one.
Structure of the tracks table
| ID | artist | title | album |
--------------------------------------------------
| 12 | Mos Def | Ms. Fat Booty | |
Structure of the tracks history table
| ID | track ID | time |
------------------------------------------
| 24 | 12 | 2016-07-03 13:40:26 |
Have you got any ideas on how I could handle this ?
Thanks !