Reposted from
http://code.google.com/p/tvrename/issues/detail?id=6
Hey Guys,
This shouldn't be too dificult, from my nose through the code we are already obtaining the ZIP file from TVDB.com
To find the specific season artwork we need to:
1. Download banners.xml for each series (it's in the same location as en.xml that has the series information in it)
Call to GetPageZIP in TheTVDB.cs should do it (may be more efficient to download the zip files onceand use each file from it.)
2. Parse the XML content
3. Scan through each banner in the Banners Collection
4. Search for the banner with the highest rating for 'BannerType'=season; 'BannerType2' = season; 'Language=en'; Season=SeasonId
5. Record the BannerPath for that element
6. save the image for that season for thetvdb.com/banners/<BannerPath>
I'm not a C coder, but do have a bit of background in hacking things together in Java. I have done my best below to produce an example of the code that would find the appropriate season banner. I hope it helps?
Thanks
Mark
in javay pseudocode:
string GetBannerURL(int SeriesId, int TVDBShowId) throws BannerNotFoundException
// seriesId is the number of the series; 1 for series 1 etc
// intSeriesId is the number of the show in TVDB - eg 76290 is for the series called '24'
boolean found = false;
number bestRating =0;
string bestBannerURL ='';
string lang = forceEnglish ? "en" : this.PreferredLanguage(code);
string url = BuildURL(false, episodesToo, code, lang);
text bannerXML = GetPageZIP(url, "banners.xml", true, forceReload)
XMLDocument bannerDocument = ParseXML(bannerXML);
for each (node banner) in bannerDocument
if node.getElement('BannerType') = 'season'
and node.getElement('BannerType2') = 'season'
and node.getElement('Language') = lang
and node.getElement('Season') = SeriesId
then
// we have a valid banner
if found = false then
//We don't have a valid banner so far, let use this one
found = true;
bestRating = node.getElement('Rating')
bestBannerURL = 'http://thetvdb.com/banners/' & node.getElement('BannerPath')
else if node.getElement('Rating') > bestRating
//We have a better quality banner than the current one, update it
bestRating = node.getElement('Rating')
bestBannerURL = 'http://thetvdb.com/banners/' & node.getElement('BannerPath')
else
//Do nothing, we already have a better banner
end if
else
// do nothing, the file contains many other URLs for images
end if
next
if found = false then throw BannerNotFoundException
else
return bestBannerURL
Image Example
http://www.thetvdb.com/banners/seasons/76290-1-6.jpg
XML Example:
<?xml version="1.0" encoding="UTF-8"?>
<Banners>
<Banner>
<id>149801</id>
<BannerPath>seasons/76290-1-6.jpg</BannerPath>
<BannerType>season</BannerType>
<BannerType2>season</BannerType2>
<Language>en</Language>
<Rating>6.7778</Rating>
<RatingCount>9</RatingCount>
<Season>1</Season>