First of all: great work!! Your API is extraordinary!!
There si only one thing I can't understand completely: which is the best way to use the $data["series"] and $data["episodes"] arrays that are returned by the function getUpdates($previousTime)?
This is the context:
Two tables in my local database ("Series" and "Episodes"). Each record in "Episodes" table has a "thetvdb_episode_id" field and a "thetvdb_series_id" field that corresponds to the field "thetvdb_id" of table "Series". This way I know to which series the episodes belong.
Finally, my database does NOT contain all the series/episodes that are present in the thetvdb database. Only the most popular ones, and I would like to keep it that way.
What should I do now to update my database? Which is the best way (to minimize the number of requests to thetvdb and to my database)? Of course I only need to know the logic, not the actual code.
This is what I think:
FIRST APPROACH:
- cycle through the "series" array with a foreach
- for each record, check if the series_id is present in my database (with a normal select query)
- if so, request the series data to thetvdb and update my database
First problem:
when only an episode of a series is updated on thetvdb, will the series_id be present in $data["series"] or does $data["series"] reflect only the changes to the series details?
Second problem:
Now I would be forced to replace all the series data in my database with the ones downloaded from thetvdb. That is of course wrong. There is no need to replace old/unchanged data along with the new ones. Maybe I could do a count and compare the total number of episodes or look at the "lastUpdated" field.
SECOND APPROACH:
- cycle through the "episodes" array with a foreach
- for each record, request the episode data (including the series_id) to thetvdb
- check if the series_id is present in my database (with a normal select query)
- if so, add/update the episode data in my database
Problem: almost 1000 request (one for each episode)... only 60 really useful.
FINAL CONSIDERATION:
Everything would be much easier if (in the $data["episodes"] array) there was also a "seriesId" value for each episode. This way, I would cycle through the array, check if the seriesId is present in my database and (if so) retrive the episode data from thetvdb.