Try 30 days of free premium.

Get new episodes and other changes to show

nkls wrote 9 years ago: 1

Hello,

I am using TVMaze to create my biggest programming project so far :) I have created a pretty neat app, but I need a way to deal with updates to a show. Should I simply download all the episodes from the api and then iterate through them to find one with an id that is not already in my object? Can I assume that the episodes are in the same order as previously and that you never remove one? I am not an expert, but wouldn't it be better for everybody if I just had to download a small portion?

Thanks in advanced :)


gazza911 wrote 9 years ago: 1

I think that's a decision that's normally left to the programmer.

As with any user submitted data, there's the chance that someone has submitted incorrect data - or that at the time, there wasn't enough information available, or even in some circumstances that the show shouldn't have been created in the first place.

You do have multiple choices though...

1. Store in your database when you last updated each show, then get http://api.tvmaze.com/updates/shows at a set interval, for each ID compare the timestamp and this will tell you if you need to get information from that show - though it won't tell you what's been updated

2. For episodes that you have the release date for, but some information is omitted (i.e name = TBA), schedule to query that specific episode at a set time (such as 2 weeks before the release date) - http://api.tvmaze.com/shows/1/episodebynumber?season=1&number=1 - if you get Unknown episode / status: 404 for one you already had, then it's been removed and if it's a different ID then the episode order has changed

3. Similarly to above, for new episodes - preferably if http://api.tvmaze.com/shows/1/seasons has already told you the number of episodes ordered, just query the next episode number every week / 2 weeks (as more information becomes available) - if you get Unknown episode / status: 404 then it's not been added yet

P.S The above two won't work with specials as they have no episode number, if you want this to work with specials, you'd need to already know the date and query it like this: http://api.tvmaze.com/shows/1/episodesbydate?date=DATE

You can combine these so that you make less requests, i.e only query episode(s) that have missing information and are within 2 weeks of release, providing that the show has been updated since the last time you checked.

I'm not sure how you've set your project up, but if there's any type of moderation, you may wish to let specific users / ranks manually check for updates (for example, if they know that new data has been added)

You might also decide to check all of the episodes - http://api.tvmaze.com/shows/1/episodes?specials=1 - on a less regular basis as a clean-up process, to ensure that you haven't missed anything.

Obviously all of these are just suggestions, but for some shows that may have hundreds of episodes, it should be a lot more efficient. For full syntax and descriptions of what's listed above, see the API page

srob650 wrote 9 years ago: 1

Great suggestions gazza, I use a combination of 1. and 2. for my own program personally and it works great. Good luck nkls!

nkls wrote 9 years ago: 1

gazza911 wrote:
I think that's a decision that's normally left to the programmer.
As with any user submitted data, there's the chance that someone has submitted incorrect data - or that at the time, there wasn't enough information available, or even in some circumstances that the show shouldn't have been created in the first place.
You do have multiple choices though...
1. Store in your database when you last updated each show, then get http://api.tvmaze.com/updates/shows at a set interval, for each ID compare the timestamp and this will tell you if you need to get information from that show - though it won't tell you what's been updated
2. For episodes that you have the release date for, but some information is omitted (i.e name = TBA), schedule to query that specific episode at a set time (such as 2 weeks before the release date) - http://api.tvmaze.com/shows/1/episodebynumber?season=1&number=1 - if you get Unknown episode / status: 404 for one you already had, then it's been removed and if it's a different ID then the episode order has changed
3. Similarly to above, for new episodes - preferably if http://api.tvmaze.com/shows/1/seasons has already told you the number of episodes ordered, just query the next episode number every week / 2 weeks (as more information becomes available) - if you get Unknown episode / status: 404 then it's not been added yet
P.S The above two won't work with specials as they have no episode number, if you want this to work with specials, you'd need to already know the date and query it like this: http://api.tvmaze.com/shows/1/episodesbydate?date=DATE

You can combine these so that you make less requests, i.e only query episode(s) that have missing information and are within 2 weeks of release, providing that the show has been updated since the last time you checked.
I'm not sure how you've set your project up, but if there's any type of moderation, you may wish to let specific users / ranks manually check for updates (for example, if they know that new data has been added)
You might also decide to check all of the episodes - http://api.tvmaze.com/shows/1/episodes?specials=1 - on a less regular basis as a clean-up process, to ensure that you haven't missed anything.
Obviously all of these are just suggestions, but for some shows that may have hundreds of episodes, it should be a lot more efficient. For full syntax and descriptions of what's listed above, see the API page

Thank you very much for the detailed answer :) I am still learning how to use databases, but this should help me a lot.


david wrote 9 years ago: 1

What works best for you really depends on your use case. Another idea that would be very simple to implement: within a database transaction, simply delete all local episode data for the show you're updating, re-create the local data based on our API, then commit the transaction.

mero wrote 9 years ago: 1

This is kinda related to this topic. The http://api.tvmaze.com/updates/shows is a great way to keep track of updates. But wouldn't it be better if we had a parameter where we can set the last edit timestamp and get only the shows that was edited after? It kinda makes sense because the update timestamp always update to a future date rather than old. That way we don't have to compute all the changes and TVmaze doesn't have to dump all the Database data rather than a very small portion.

nkls wrote 9 years ago: 1

Is it safe to assume that the timezone for the timestamps is UTF? Thanks

srob650 wrote 9 years ago: 1

nkls wrote:
Is it safe to assume that the timezone for the timestamps is UTF? Thanks

The timestamps are in the format of epoch time.

EDIT: That is if you're talking about the http://api.tvmaze.com/updates/shows endpoint. If you're talking about the "airdate" and "airstamp" properties of an episode then those are in ISO 8601 format, with airstamp having the time and UTC offset appended to it, separated by the "T" character.


david wrote 9 years ago: 1

Indeed, and epochs are timezone neutral. :)

Try 30 days of free premium.