Exemple #1
0
def get_show_meta(name):
    tvdb = xbmcaddon.Addon('script.module.metahandler')
    __cwd__ = xbmc.translatePath(tvdb.getAddonInfo('path')).decode("utf-8")
    BASE_RESOURCE_PATH = os.path.join(__cwd__, 'lib', 'metahandler')
    sys.path.append(BASE_RESOURCE_PATH)
    from thetvdbapi import TheTVDB
    try:
        tv = TheTVDB(language='en')

        split = name.split(" ")
        if len(split) > 1:
            name = split[0] + " " + split[1]

        show_list = tv.get_matching_shows(name, language='all')
        #print "Searching %s" % (name)
        if len(show_list) > 0:
            show_id = show_list[0][0]
            images = tv.get_show_image_choices(show_id)
            res = {}
            for im in images:
                if 'fanart' in im[1]:
                    res['fanart'] = im[0]
                if 'poster' in im[1]:
                    res['poster'] = im[0]
            return res
    except Exception as e:
        return None
    return None
def get_show_meta(name):
	tvdb = xbmcaddon.Addon('script.module.metahandler')
	__cwd__ = xbmc.translatePath(tvdb.getAddonInfo('path')).decode("utf-8")
	BASE_RESOURCE_PATH = os.path.join(__cwd__, 'lib', 'metahandler')
	sys.path.append(BASE_RESOURCE_PATH)
	from thetvdbapi import TheTVDB
	try:
		tv = TheTVDB(language='en')

		split = name.split(" ")
		if len(split) > 1:
			name = split[0]+" "+split[1]

		show_list = tv.get_matching_shows(name,language='all')
		#print "Searching %s" % (name)
		if len(show_list) > 0:
			show_id = show_list[0][0]
			images = tv.get_show_image_choices(show_id)
			res = {}
			for im in images:
				if 'fanart' in im[1]:
					res['fanart'] = im[0]
				if 'poster' in im[1]:
					res['poster'] = im[0]
			return res
	except Exception as e:
		return None
	return None
Exemple #3
0
    def update_from_tvdb(self):
        '''Fetch all available information about a series from tvdb'''

        from thetvdbapi import TheTVDB

        tvdb = TheTVDB(settings.TVDB_API_KEY)
        (tvdb_series, tvdb_episode_list) = tvdb.get_show_and_episodes(self.tvdb_id)

        self.update_summary_details(tvdb_series)
        self.update_extended_details(tvdb_series)
        self.update_episodes(tvdb_episode_list)
        self.save()
Exemple #4
0
 def tvdbLookup(self, tvdb_id, season_num, episode_num, dateSearch):
     #TvDB Lookup for episodes
     
     meta = {}
     tvdb = TheTVDB()
     if dateSearch:
         aired=self.get_date(season_num, episode_num)
         episode = tvdb.get_episode_by_airdate(tvdb_id, aired)
         
         #We do this because the airdate method returns just a part of the overview unfortunately
         if episode is not None:
             ep_id = episode.id
             if ep_id is not None:
                 episode = tvdb.get_episode(ep_id)
     else:
         episode = tvdb.get_episode_by_season_ep(tvdb_id, season_num, episode_num)
         
     if episode is None:
         return None
     
     meta['episode_id'] = episode.id
     meta['tvdb_name'] = self.check(episode.name)
     meta['plot'] = self.check(episode.overview)
     '''if episode.season_number is not None and episode.episode_number is not None:
         meta['plot'] = "Episode: " + episode.season_number + "x" + episode.episode_number + "\n" + meta['plot']
     if episode.first_aired is not None:
         meta['plot'] = "Aired  : " + episode.first_aired + "\n" + meta['plot']
     if episode.name is not None:
         meta['plot'] = episode.name + "\n" + meta['plot']'''
     meta['rating'] = self.check(episode.rating,0)
     meta['aired'] = self.check(episode.first_aired)
     meta['poster'] = self.check(episode.image)
     meta['season_num'] = self.check(episode.season_number,0)
     meta['episode_num'] = self.check(episode.episode_number,0)
     
     print meta
     '''
     show_and_episodes = tvdb.get_show_and_episodes(tvdb_id)
     if show_and_episodes == None:
         return meta
     
     (show, ep_list) = show_and_episodes
     for episode in ep_list:
         print '      S'+ episode.season_number + '.E' + episode.episode_number
         if episode.season_number == season_num and episode.episode_number == episode_num:
             meta['']=''
             break
     '''
     
     return meta
Exemple #5
0
    def apply_tvdb_updates(self):
        '''Retreives last updates from TVDB and update existing series/seasons/episodes 
        accordingly'''

        from thetvdbapi import TheTVDB
        tvdb = TheTVDB(settings.TVDB_API_KEY)

        try:
            update = TVDBCache.objects.get(type='last')
        except TVDBCache.DoesNotExist:
            server_time = tvdb.get_server_time()
            update = TVDBCache(type='last', time=server_time)
            update.save()
            return False

        log.info("Updating series from TVDB (last update: %s)", update.time)

        (timestamp, series_list, episode_list) = tvdb.get_updates_by_timestamp(update.time)

        # Update series (details, seasons & episodes)
        for series_tvdb_id in series_list:
            try:
                series = Series.objects.get(tvdb_id=series_tvdb_id)
                # Check if this has been downloaded in the past
                if series.is_active():
                    log.info('Applying update to series "%s"', series.name)
                    series.update_from_tvdb()
            except Series.DoesNotExist:
                pass

        # Update individual episodes modifications (not new episodes)
        for episode_tvdb_id in episode_list:
            try:
                episode = Episode.objects.get(tvdb_id=episode_tvdb_id)
                episode_tvdb = tvdb.get_episode(episode_tvdb_id)
                log.info('Applying update to episode "%s s%de%d"', episode.season.series.name, episode.season.number, episode.number)
                episode.update_details(episode_tvdb)
            except Episode.DoesNotExist:
                pass

        # Update timestamp
        update.time = timestamp
        update.save()
Exemple #6
0
    def add_by_search(self, search_string):
        '''Retreiving series names for a given search string and creating any new Series objects'''
        
        log.info("Live search: '%s'", search_string)

        from thetvdbapi import TheTVDB
        tvdb = TheTVDB(settings.TVDB_API_KEY)
        tvdb_series_list = tvdb.get_matching_shows(search_string+'*')

        for tvdb_series in tvdb_series_list:
            log.info("Search result: '%s'", tvdb_series.name)

            # Check if the series already exists
            try:
                series = Series.objects.get(name=tvdb_series.name)
            except Series.DoesNotExist:
                # Check that we've got all the required tags
                if tvdb_series.name and tvdb_series.id and \
                        tvdb_series.language == 'en' and tvdb_series.banner_url:
                    log.info("Adding series to db: %s", tvdb_series.name)
                    series = Series()
                    series.update_summary_details(tvdb_series)
                    series.save()
    def set_episode_info(self, label, prefix, when, ep):
        if ep and ep['id']:
            name = ep['name']
            number = ep['number']
            aired = self.nice_date(TheTVDB.convert_date(ep['aired'][:10]))
        else:
            name = number = aired = ''
        num_array = number.split('x')
        num_array.extend([''])

        label.setProperty(prefix + when + 'Date', aired)
        label.setProperty(prefix + when + 'Title', name)
        label.setProperty(prefix + when + 'Number', number)
        label.setProperty(prefix + when + 'SeasonNumber', num_array[0])
        label.setProperty(prefix + when + 'EpisodeNumber', num_array[1])
 def upgrade_data_format(show_dict, from_ver):
     if from_ver > MAIN_DB_VER:
         log("### ERROR: found DB version that is too new for this script to handle (%d > %d)" % (from_ver, MAIN_DB_VER), level=0)
         sys.exit()
     log("### upgrading DB from version %d to %d" % (from_ver, MAIN_DB_VER), level=1)
     daymap = {'Monday': 0, 'Tuesday': 1, 'Wednesday': 2, 'Thursday': 3, 'Friday': 4, 'Saturday': 5, 'Sunday': 6}
     for tid, show in show_dict.iteritems():
         if from_ver < 2:
             # Convert Started into isoformat date:
             started = ''
             for fmt in ('%b/%d/%Y', '%a, %b %d, %Y', '%Y-%m-%d'):
                 try:
                     started = strftime('%Y-%m-%d', strptime(show['Started'], fmt))
                     break
                 except:
                     pass
             show['Started'] = started
             # Convert airtime into HH:MM (never AM/PM):
             airtime = TheTVDB.convert_time(show['Airtime'])
             show['Airtime'] = airtime.strftime('%H:%M') if airtime is not None else ''
         for ep in show['episodes']:
             if from_ver < 3 and 'wday' in ep:
                 # Convert wday from a string to an index:
                 ep['wday'] = daymap[ep['wday']]
    def _get_tvdb_meta(self, imdb_id, name, year=''):
        """
        Requests meta data from TVDB and creates proper dict to send back

        Args:
            imdb_id (str): IMDB ID
            name (str): full name of tvshow you are searching
        Kwargs:
            year (str): 4 digit year of tvshow, when imdb_id is not available it is recommended
                        to include the year whenever possible to maximize correct search results.

        Returns:
            DICT. It must also return an empty dict when
            no movie meta info was found from tvdb because we should cache
            these "None found" entries otherwise we hit tvdb alot.
        """
        xbmc.log('Starting TVDB Lookup', 0)
        tvdb = TheTVDB()
        tvdb_id = ''

        try:
            if imdb_id:
                tvdb_id = tvdb.get_show_by_imdb(imdb_id)
        except Exception as e:
            xbmc.log(
                '************* Error retreiving from thetvdb.com1: %s ' % e, 4)
            tvdb_id = ''

        # Intialize tvshow meta dictionary
        meta = self._init_tvshow_meta(imdb_id, tvdb_id, name, year)

        # if not found by imdb, try by name
        if tvdb_id == '':
            try:
                # If year is passed in, add it to the name for better TVDB search results
                # if year:
                #    name = name + ' ' + year
                show_list = tvdb.get_matching_shows(name)
            except Exception as e:
                xbmc.log(
                    '************* Error retreiving from thetvdb.com2: %s ' %
                    e, 4)
                show_list = []

            xbmc.log('Found TV Show List: %s' % show_list, 0)
            tvdb_id = ''
            for show in show_list:
                (junk1, junk2, junk3) = show
                try:
                    # if we match imdb_id or full name (with year) then we know for sure it is the right show
                    if (imdb_id and junk3
                            == imdb_id) or (year and self._string_compare(
                                self._clean_string(junk2),
                                self._clean_string(name + year))):
                        tvdb_id = self._clean_string(junk1)
                        if not imdb_id:
                            imdb_id = self._clean_string(junk3)
                        name = junk2
                        break
                    # if we match just the cleaned name (without year) keep the tvdb_id
                    elif self._string_compare(self._clean_string(junk2),
                                              self._clean_string(name)):
                        tvdb_id = self._clean_string(junk1)
                        if not imdb_id:
                            imdb_id = self._clean_string(junk3)
                        break

                except Exception as e:
                    xbmc.log(
                        '************* Error retreiving from thetvdb.com3: %s '
                        % e, 4)

        if tvdb_id:
            xbmc.log(
                'Show *** ' + name + ' *** found in TVdb. Getting details...',
                0)

            try:
                show = tvdb.get_show(tvdb_id)
            except Exception as e:
                xbmc.log(
                    '************* Error retreiving from thetvdb.com: %s ' % e,
                    4)
                show = None

            if show is not None:
                meta['imdb_id'] = imdb_id
                meta['tvdb_id'] = tvdb_id
                meta['title'] = name
                if str(show.rating) != '' and show.rating is not None:
                    meta['rating'] = float(show.rating)
                # "Soft Focus with Jena Friedman" had an empty runtime, killing metadata routines
                if str(show.runtime) != '':
                    meta['duration'] = int(show.runtime) * 60
                else:
                    meta['duration'] = 99999
                meta['plot'] = show.overview
                meta['mpaa'] = show.content_rating
                meta['premiered'] = str(show.first_aired)

                # Do whatever we can to set a year, if we don't have one lets try to strip it from
                # show.first_aired/premiered
                if not year and show.first_aired:
                    # meta['year'] = int(self._convert_date(meta['premiered'], '%Y-%m-%d', '%Y'))
                    meta['year'] = int(meta['premiered'][:4])

                if show.genre != '':
                    temp = show.genre.replace("|", ",")
                    temp = temp[1:(len(temp) - 1)]
                    meta['genre'] = temp
                meta['studio'] = show.network
                meta['status'] = show.status
                if show.actors:
                    for actor in show.actors:
                        meta['cast'].append(actor)
                meta['banner_url'] = show.banner_url
                meta['cover_url'] = show.poster_url
                meta['backdrop_url'] = show.fanart_url
                meta['overlay'] = 6

                return meta
        else:
            return meta
Exemple #10
0
    def imdbLookup(self, imdb_id, type, name):
        # Movie.imdbLookup doesn't return all the info that Movie.getInfo does like the cast.
        # So do a small lookup with getVersion just to get the tmdb id from the imdb id.
        # Then lookup by the tmdb id to get all the meta.

        meta = {}
        if type=='tvshow':
            print 'TV Show lookup'
            tvdb = TheTVDB()
            tvdb_id = tvdb.get_show_by_imdb(imdb_id)

            # if not found by imdb, try by name
            if tvdb_id == '':
                cleaned_name = name[:(len(name)-7)] # strip the trailing " (yyyy)"
                show_list=tvdb.get_matching_shows(cleaned_name)
                #print show_list
                tvdb_id=''
                prob_id=''
                for show in show_list:
                    (junk1, junk2, junk3) = show
                    #if we match imdb_id or full name (with year) then we know for sure it is the right show
                    if junk3==imdb_id or junk2==name:
                        tvdb_id=junk1
                        break
                    #if we match just the cleaned name (without year) keep the tvdb_id
                    elif junk2==cleaned_name:
                        prob_id = junk1
                if tvdb_id == '' and prob_id != '':
                    tvdb_id = prob_id

            if tvdb_id != '':
                print 'Show *** ' + name + ' *** found in TVdb. Getting details...'
                show = tvdb.get_show(tvdb_id)
                if show is not None:
                    meta['imdb_id'] = imdb_id
                    meta['id'] = tvdb_id
                    meta['name'] = name
                    if str(show.rating) == '' or show.rating == None:
                        meta['rating'] = 0
                    else:
                        meta['rating'] = show.rating
                    meta['runtime'] = 0
                    meta['overview'] = show.overview
                    meta['certification'] = show.content_rating
                    meta['released'] = show.first_aired
                    meta['trailer_url'] = ''
                    if show.genre != '':
                        temp = show.genre.replace("|",",")
                        temp = temp[1:(len(temp)-1)]
                        meta['imdb_genres'] = temp
                    meta['tvdb_studios'] = show.network
                    if show.actors != None:
                        num=1
                        meta['actors']=''
                        print show.actors
                        for actor in show.actors:
                            if num == 1:
                                meta['actors'] = actor
                            else:
                                meta['actors'] = meta['actors'] + ", " + actor
                                if num == 5: # Read only first 5 actors, there might be a lot of them
                                    break
                            num = num + 1
                    #meta['imgs_prepacked'] = self.classmode
                    meta['imdb_poster'] = show.poster_url
                    print 'cover is  *** ' + meta['imdb_poster']
                    
                    print '          rating ***' + str(meta['rating'])+'!!!'

                    if meta['overview'] == 'None' or meta['overview'] == '' or meta['overview'] == 'TBD' or meta['overview'] == 'No overview found.' or meta['rating'] == 0 or meta['runtime'] == 0 or meta['actors'] == '' or meta['imdb_poster'] == '':
                        print ' Some info missing in TVdb for TVshow *** '+ name + ' ***. Will search imdb for more'
                        meta = self._search_imdb( meta, imdb_id)
                    else:
                        meta['overview'] = 'Starring : \n' + meta['actors'] + '\n\nPlot : \n' + meta['overview']
                    return meta
                else:
                    meta = self._search_imdb( meta, imdb_id)
                    return meta

        try:
            tmdb_id = self.getVersion(imdb_id)['id']
        except:
            print ' Movie *** '+ imdb_id + ' *** not in tmdb. Will search imdb '
            meta = self._search_imdb( meta, imdb_id)
            return meta

        if tmdb_id:
            meta = self._do_request('Movie.getInfo', tmdb_id)

            if meta is None: # fall through to IMDB lookup
                meta = {}

            tmp_cast = []
            tmp_cast = meta.get('cast', '')
            meta['actors'] = ''
            for temp in tmp_cast:
                job=temp.get('job','')
                if job == 'Actor':
                    num=temp.get('order','')
                    if num == 0 or meta['actors'] == '':
                        meta['actors'] = temp.get('name','')
                    else:
                        meta['actors'] = meta['actors'] + ', ' + temp.get('name','')
                        if num == 4: # Read only first 5 actors, there might be a lot of them
                            break
            #print meta
            meta['actors'] = self.cleanUnicode(meta['actors'])
            # Read overview only when in English Language, to avoid some unicode errors
            if meta['language'] != 'en':
                meta['overview'] = ''
            else:
                meta['overview'] = self.cleanUnicode(meta['overview'])
            #print ' Actors ' + str(meta['actors'])
            if meta['overview'] == 'None' or meta['overview'] == '' or meta['overview'] == 'TBD' or meta['overview'] == 'No overview found.' or meta['rating'] == 0 or meta['runtime'] == 0 or str(meta['genres']) == '[]' or str(meta['posters']) == '[]' or meta['actors'] == '':
                print ' Some info missing in TMDb for Movie *** '+ imdb_id + ' ***. Will search imdb for more'
                meta = self._search_imdb( meta, imdb_id)
            else:
                meta['overview'] = 'Starring : \n' + meta['actors'] + '\n\nPlot : \n' + meta['overview']
            return meta
        else:
            meta = {}
            meta = self._search_imdb( meta, imdb_id)
            return meta
Exemple #11
0
 def getSeasonPosters(self, tvdb_id, season):
     tvdb = TheTVDB()
     images = tvdb.get_show_image_choices(tvdb_id)
     
     return images
Exemple #12
0
#!/usr/bin/python

from thetvdbapi import TheTVDB

moo = TheTVDB('273A29FB654AC4D2')
showid = moo.get_matching_shows('House')[0][0]
print moo.get_show(showid).
    def set_labels(self, infolabel, item, want_ep_ndx = None):
        art = item["art"]
        must_have = None
        if infolabel == 'listitem':
            label = xbmcgui.ListItem()
            prefix = ''
            label.setLabel(item["localname"])
            label.setThumbnailImage(item.get("thumbnail", ""))
            try:
                must_have = LISTITEM_ART[int(__addon__.getSetting("ThumbType"))]
            except:
                pass
        else:
            label = xbmcgui.Window(10000)
            if infolabel == "windowproperty":
                prefix = 'NextAired.'
            elif infolabel == "windowpropertytoday":
                prefix = 'NextAired.' + str(self.count) + '.'
                label.setProperty("NextAired.ShowAllTVShows", __addon__.getSetting("ShowAllTVShowsOnHome"))
            else:
                return # Impossible...
            label.setProperty(prefix + "Label", item["localname"])
            label.setProperty(prefix + "Thumb", item.get("thumbnail", ""))

        if want_ep_ndx:
            next_ep = item['episodes'][want_ep_ndx]
            latest_ep = item['episodes'][want_ep_ndx-1]
            airdays = [ next_ep['wday'] ]
        else:
            ep_len = len(item['episodes'])
            next_ep = item['episodes'][1] if ep_len > 1 else None
            latest_ep = item['episodes'][0]
            airdays = []
            if ep_len > 1:
                date_limit = (TheTVDB.convert_date(item['episodes'][1]['aired'][:10]) + timedelta(days=6)).isoformat()
                for ep in item['episodes'][1:]:
                    if ep['aired'][:10] > date_limit:
                        break
                    airdays.append(ep['wday'])
        airdays.sort()
        daynums = ', ' . join([str(wday) for wday in airdays])
        airdays = ', ' . join([self.weekdays[wday] for wday in airdays])

        is_today = 'True' if next_ep and next_ep['aired'][:10] == self.datestr else 'False'

        started = TheTVDB.convert_date(item["Started"])
        airtime = TheTVDB.convert_time(item["Airtime"])
        if airtime is not None:
            airtime = airtime.strftime('%I:%M %p' if self.ampm else '%H:%M')
        else:
            airtime = '??:??'

        status = item.get("Status", "")
        if status == 'Continuing':
            ep = next_ep if next_ep else latest_ep if latest_ep else None
            if not ep or not ep['id'] or NEW_REGEX.match(ep['number']):
                status_id = '4' # New
            else:
                status_id = '0' # Returning
        elif status == 'Ended':
            if next_ep:
                status_id = '6' # Final Season
            else:
                status_id = '1' # Cancelled/Ended
        elif status == '':
            status_id = '2' # TBD/On the bubble
        else:
            status_id = '-1' # An unknown value shouldn't be possible...
        if status_id != '-1':
            status = STATUS[status_id]

        label.setProperty(prefix + "AirTime", airdays + ": " + airtime if airdays != "" else airtime)
        label.setProperty(prefix + "Path", item.get("path", ""))
        label.setProperty(prefix + "Library", item.get("dbid", ""))
        label.setProperty(prefix + "Status", status)
        label.setProperty(prefix + "StatusID", status_id)
        label.setProperty(prefix + "Network", item.get("Network", ""))
        label.setProperty(prefix + "Started", self.nice_date(started, force_year = True))
        # XXX Note that Classification is always unset at the moment!
        label.setProperty(prefix + "Classification", item.get("Classification", ""))
        label.setProperty(prefix + "Genre", item.get("Genres", ""))
        label.setProperty(prefix + "Premiered", str(item.get("Premiered", "")))
        label.setProperty(prefix + "Country", item.get("Country", ""))
        label.setProperty(prefix + "Runtime", str(item.get("Runtime", "")))
        # Keep old fanart property for backwards compatibility
        label.setProperty(prefix + "Fanart", art.get("fanart", ""))
        # New art properties
        for art_type in ('fanart', 'poster', 'banner', 'landscape', 'clearlogo', 'characterart', 'clearart'):
            art_url = art.get(art_type, "")
            if must_have and art_url == "" and art_type == must_have:
                try:
                    url = "http://opencoder.net/next-aired-missing/" + art_type + "/" + urllib.quote(item["localname"])
                    art_url = "image://%s.png/" % urllib.quote(url, '')
                except:
                    pass
            label.setProperty("%sArt(%s)" % (prefix, art_type), art_url)
        label.setProperty(prefix + "Today", is_today)
        label.setProperty(prefix + "AirDay", airdays)
        label.setProperty(prefix + "AirDayNum", daynums)
        label.setProperty(prefix + "ShortTime", airtime)

        # This sets NextDate, NextTitle, etc.
        self.set_episode_info(label, prefix, 'Next', next_ep)
        # This sets LatestDate, LatestTitle, etc.
        self.set_episode_info(label, prefix, 'Latest', latest_ep)

        if infolabel == 'listitem':
            return label
        network = normalize(show, 'Network', 'Unknown')
        country = self.country_dict.get(network, 'Unknown')
        # XXX TODO allow the user to specify an override country that gets the local timezone.
        tzone = CountryLookup.get_country_timezone(country, self.in_dst)
        if not tzone:
            tzone = ''
        tz_re = re.compile(r"([-+])(\d\d):(\d\d)")
        m = tz_re.match(tzone)
        if m:
            tz_offset = (int(m.group(2)) * 3600) + (int(m.group(3)) * 60)
            if m.group(1) == '-':
                tz_offset *= -1
        else:
            tz_offset = 1 * 3600 # Default to +01:00
        try:
            airtime = TheTVDB.convert_time(show.get('Airs_Time', ""))
        except:
            airtime = None
        local_airtime = airtime if airtime is not None else TheTVDB.convert_time('00:00')
        local_airtime = datetime.combine(self.date, local_airtime).replace(tzinfo=tz.tzoffset(None, tz_offset))
        if airtime is not None: # Don't backtrack an assumed midnight time (for an invalid airtime) into the prior day.
            local_airtime = local_airtime.astimezone(tz.tzlocal())

        current_show['Show Name'] = normalize(show, 'SeriesName')
        first_aired = show.get('FirstAired', None)
        if first_aired:
            first_aired = TheTVDB.convert_date(first_aired)
            current_show['Premiered'] = first_aired.year
            current_show['Started'] = first_aired.isoformat()
        else:
            current_show['Premiered'] = current_show['Started'] = ""
Exemple #15
0
    def load(self, node, mirror_url, series=None):

        Episode.sqlmeta.lazyUpdate = True
        self.episode_id = node.findtext("id")
        self.tvdb_show_id = node.findtext("seriesid")
        self.name = node.findtext("EpisodeName")
        self.overview = node.findtext("Overview")
        self.season_number = int(node.findtext("SeasonNumber"))
        self.episode_number = int(node.findtext("EpisodeNumber"))
        self.director = node.findtext("Director")
        self.guest_stars = node.findtext("GuestStars")
        self.language = node.findtext("Language")
        self.production_code = node.findtext("ProductionCode")
        self.rating = node.findtext("Rating")
        self.writer = node.findtext("Writer")
        self.show = series
        # set the season
        try:
            self.season = Season.select((Season.q.season == self.season_number) & (Season.q.show == self.show)).getOne()
            # self.season = Season.get(series=series, season=self.season_number)
        except Exception as e:
            print "XXXXXXXX"
            print e
            self.season = Season(show=series, season=self.season_number)

        # Air date
        from thetvdbapi import TheTVDB

        self.first_aired = TheTVDB.convert_date(node.findtext("FirstAired"))

        # DVD Information
        self.dvd_chapter = node.findtext("DVD_chapter")
        self.dvd_disc_id = node.findtext("DVD_discid")
        self.dvd_episode_number = node.findtext("DVD_episodenumber")
        self.dvd_season = node.findtext("DVD_season")

        # Artwork/screenshot
        self.image = node.findtext("filename")
        if self.image is not None:
            self.poster_url = "%s/banners/%s" % (mirror_url, self.image)
        else:
            self.poster_url = ""
        # Episode ordering information (normally for specials)
        self.airs_after_season = node.findtext("airsafter_season")
        self.airs_before_season = node.findtext("airsbefore_season")
        self.airs_before_episode = node.findtext("airsbefore_episode")

        # Unknown
        self.combined_episode_number = node.findtext("combined_episode_number")
        self.combined_season = node.findtext("combined_season")
        self.absolute_number = node.findtext("absolute_number")
        self.season_id = node.findtext("seasonid")
        self.ep_img_flag = node.findtext("EpImgFlag")

        # External references
        self.imdb_id = node.findtext("IMDB_ID")

        # When this episode was last updated
        self.last_updated = datetime.datetime.fromtimestamp(int(node.findtext("lastupdated")))

        # Handling play history
        self.watched = False
        self.pos = 0
        self.syncUpdate()
        Episode.sqlmeta.lazyUpdate = False