def setUp(self): self.show = Show(name="Test Show") self.show.save() self.episode = Show(name="Test Episode") self.episode.save() self.video_file = TVVideoFile(name="Test Video File") self.video_file.save()
def create_tables(fail_silently=True): Channel.create_table(fail_silently=fail_silently) Genre.create_table(fail_silently=fail_silently) Show.create_table(fail_silently=fail_silently) Episode.create_table(fail_silently=fail_silently) Airing.create_table(fail_silently=fail_silently) Label.create_table(fail_silently=fail_silently) Actor.create_table(fail_silently=fail_silently) ActorEpisodeRelationship.create_table(fail_silently=fail_silently) AiringLabelRelationship.create_table(fail_silently=fail_silently)
class CoreModelTest(unittest.TestCase): """ Test the models contained in the 'core' app """ def setUp(self): self.show = Show(name="Test Show") self.show.save() self.episode = Show(name="Test Episode") self.episode.save() self.video_file = TVVideoFile(name="Test Video File") self.video_file.save() def tearDown(self): self.show.delete() self.episode.delete() self.video_file.delete() def testModels(self): self.assertEquals(self.show.name, "Test Show") self.assertEquals(self.episode.name, "Test Episode") self.assertEquals(self.video_file.name, "Test Video File")
def check_show(id,show_id): try: show_startTime = datetime.now() headers = {'content-type': 'application/json'} payload = {'cmd': 'show', 'tvdbid': show_id} r = requests.get(sickbeard_api_url, params=payload, verify=False) showapi_detail = r.json() if not showapi_detail["result"] == "success": #q.put("Error: result bad") return update_show = Show.objects.get(tvdbid = show_id) #if update_show.use_sickbeard == False: #sickbeard doesnt need to check this # return #print "{:3d} {:40s} {:10s}".format(id, update_show.name, "CHECKING") #print 'Checking Show #'+id+' - ' + update_show.name update_show.name=showapi_detail["data"]['show_name'].encode('utf8', 'replace')[:200] #update_show.date_added=showapi_detail["data"]['date_added'].encode('utf8', 'replace') #update_show.date_updated=datetime.date.today() #update_show.date_aired=showapi_detail["data"]['date_aired'].encode('utf8', 'replace') if showapi_detail["data"]['next_ep_airdate']: update_show.date_next_episode=datetime.strptime(showapi_detail["data"]['next_ep_airdate'].encode('utf8', 'replace'), "%Y-%m-%d") update_show.file_path=showapi_detail["data"]['location'].encode('utf8', 'replace') #update_show.tvdbid=showapi_detail["data"]['tvdb_series_id'].encode('utf8', 'replace') update_show.genre=",".join(showapi_detail["data"]['genre']).encode('utf8', 'replace')[:200] update_show.airs=showapi_detail["data"]['airs'].encode('utf8', 'replace')[:50] update_show.network=showapi_detail["data"]['network'].encode('utf8', 'replace')[:50] #update_show.actors=showapi_detail["data"]['actors'].encode('utf8', 'replace')[:400] #update_show.runtime=showapi_detail["data"]['runtime'].encode('utf8', 'replace')[:42] + ' minutes' update_show.save() for sea in showapi_detail["data"]['season_list']: try: update_season = Season.objects.get(show=update_show,number=sea) #print ' -Updated Season '+str(sea) check_episodes(update_show,update_season) except Season.DoesNotExist: new_season = Season( show=update_show, number=sea, ) new_season.save() print "{:3d} {:40s} {:10s} {:3s}".format(id, update_show.name, "ADDED SEA", 'S'+str(sea)) #print ' -Added Season - '+update_show.name+' '+str(sea) print "{:3d} {:40s} {:10s} {:25s}".format(id, update_show.name, "UPDATED", str(datetime.now()-show_startTime)) #print '%d %10s - %s (%s)' % id, "UPDATED", update_show.name, str(datetime.now()-show_startTime) #q.put('Updated Show - ' + update_show.name) except Show.DoesNotExist: #print showapi_detail["data"]["show_name"] new_show = Show( name=showapi_detail["data"]['show_name'].encode('utf8', 'replace')[:200], date_next_episode=datetime.strptime(showapi_detail["data"]['next_ep_airdate'].encode('utf8', 'replace'), "%Y-%m-%d"), file_path=showapi_detail["data"]['location'].encode('utf8', 'replace'), genre=",".join(showapi_detail["data"]['genre']).encode('utf8', 'replace')[:200], tvdbid=show_id.encode('utf8', 'replace'), airs=showapi_detail["data"]['airs'].encode('utf8', 'replace')[:50], network=showapi_detail["data"]['network'].encode('utf8', 'replace')[:50], ) new_show.save() #print '%d %10s - %s' % id, "CREATED", showapi_detail["data"]['show_name'] print "{:3d} {:40s} {:10s}".format(id, showapi_detail["data"]['show_name'], "CREATED") except: print '!!!!!!! ERROR Show #'+str(id)+' - ' + showapi_detail["data"]['show_name'] traceback.print_exc()
update_show.network = showapi_detail["data"]['network'].encode( 'utf8')[:50] #update_show.actors=showapi_detail["data"]['actors'].encode('utf8')[:400] #update_show.runtime=showapi_detail["data"]['runtime'].encode('utf8')[:42] + ' minutes' update_show.save() for sea in showapi_detail["data"]['season_list']: season_item = update_season(update_show, sea) update_episodes(season_item) print 'Updated Show - ' + showapi_detail["data"]['show_name'] except Show.MultipleObjectsReturned as e: new_show = Show.objects.filter(tvdbid=show_id).reverse()[0].delete() print 'Deleted Show (Duplicate) - ' + show_id except Show.DoesNotExist: #print showapi_detail["data"]["show_name"] new_show = Show( name=showapi_detail["data"]['show_name'].encode('utf8')[:200], date_next_episode=datetime.strptime( showapi_detail["data"]['next_ep_airdate'].encode('utf8'), "%Y-%m-%d"), file_path=showapi_detail["data"]['location'].encode('utf8'), genre=",".join( showapi_detail["data"]['genre']).encode('utf8')[:200], tvdbid=show_id.encode('utf8'), airs=showapi_detail["data"]['airs'].encode('utf8')[:50], network=showapi_detail["data"]['network'].encode('utf8')[:50], ) new_show.save() print 'Created Show - ' + showapi_detail["data"]['show_name']
def import_show(show_id): """ Imports a tvdb show from its id """ tvdbapi = TheTVDB(settings.TVDBAPI_KEY) print "Querying TheTVDB... for id %s" % show_id result = tvdbapi.get_show_and_episodes(show_id) if result: tvdbshow, tvdbepisodes = result print "Show.name = %s" % (tvdbshow.name,) try: show = Show.objects.get(tvdb_showid=tvdbshow.id) print "Updating existing show" except Show.DoesNotExist: print "Creating new show" show = Show(tvdb_showid=tvdbshow.id) show.name = tvdbshow.name show.overview = tvdbshow.overview show.genre = str(tvdbshow.genre[0]) # FIXME This is an array show.network = tvdbshow.network show.content_rating = tvdbshow.content_rating show.runtime = tvdbshow.runtime show.status = tvdbshow.status show.first_aired = tvdbshow.first_aired show.airs_day = tvdbshow.airs_day show.airs_time = tvdbshow.airs_time show.tvdb_language = tvdbshow.language if tvdbshow.rating: show.tvdb_rating = tvdbshow.rating show.tvdb_banner_url = tvdbshow.banner_url show.tvdb_fanart_url = tvdbshow.fanart_url show.tvdb_poster_url = tvdbshow.poster_url show.tvdb_last_updated = tvdbshow.last_updated show.save() # Download the images for the show filename = "%s/banner/%s.jpg" % (settings.MEDIANAV_TV_MEDIA, show.tvdb_showid) if not os.access(filename, os.F_OK): print "Downloading banner image to %s" % (filename) urllib.urlretrieve(show.tvdb_banner_url, filename) filename = "%s/poster/%s.jpg" % (settings.MEDIANAV_TV_MEDIA, show.tvdb_showid) if not os.access(filename, os.F_OK): print "Downloading poster image to %s" % (filename) urllib.urlretrieve(show.tvdb_poster_url, filename) filename = "%s/fanart/%s.jpg" % (settings.MEDIANAV_TV_MEDIA, show.tvdb_showid) if not os.access(filename, os.F_OK): print "Downloading fanart image to %s" % (filename) urllib.urlretrieve(show.tvdb_fanart_url, filename) # Add / Update episodes from tvdb to medianav for tvdbepisode in tvdbepisodes: #update = 0 #update_fields = "" try: print "Update: s%02de%02d %s" % (int(tvdbepisode.season_number), int(tvdbepisode.episode_number), tvdbepisode.name.encode('latin-1', 'ignore')) episode = Episode.objects.get(tvdb_episodeid=tvdbepisode.id) except Episode.DoesNotExist: episode = Episode(tvdb_episodeid=tvdbepisode.id) print "Create: s%02de%02d %s" % (int(tvdbepisode.season_number), int(tvdbepisode.episode_number), tvdbepisode.name.encode('latin-1', 'ignore')) #if episode.show != show: # update = 1 # update_fields += " show" #if episode.name != tvdbepisode.name: # update = 1 # update_fields += " name" episode.name = tvdbepisode.name episode.show = show episode.overview = tvdbepisode.overview episode.season_number = tvdbepisode.season_number episode.episode_number = tvdbepisode.episode_number episode.director = tvdbepisode.director episode.guest_stars = tvdbepisode.guest_stars episode.production_code = tvdbepisode.production_code episode.writer = tvdbepisode.writer episode.first_aired = tvdbepisode.first_aired episode.tvdb_language = tvdbepisode.language if tvdbepisode.rating: episode.tvdb_rating = tvdbepisode.rating episode.tvdb_image = tvdbepisode.image episode.tvdb_last_updated = tvdbepisode.last_updated episode.save() #if update: # print "Update: s%02de%02d %s [%s]" % (int(tvdbepisode.season_number), int(tvdbepisode.episode_number), tvdbepisode.name, update_fields), # Remove any episodes that are no longer in tvdb list for episode in show.episode_set.all(): if episode.tvdb_episodeid not in (int(e.id) for e in tvdbepisodes): print "Delete: s%02de%02d %s" % (episode.season_number, episode.episode_number, episode.name) episode.delete() else: print "Unable to retrieve information for show_id = %s" % (show_id,)
def import_show(show_id): """ Imports a tvdb show from its id """ tvdbapi = TheTVDB(settings.TVDBAPI_KEY) print "Querying TheTVDB... for id %s" % show_id result = tvdbapi.get_show_and_episodes(show_id) if result: tvdbshow, tvdbepisodes = result print "Show.name = %s" % (tvdbshow.name, ) try: show = Show.objects.get(tvdb_showid=tvdbshow.id) print "Updating existing show" except Show.DoesNotExist: print "Creating new show" show = Show(tvdb_showid=tvdbshow.id) show.name = tvdbshow.name show.overview = tvdbshow.overview show.genre = str(tvdbshow.genre[0]) # FIXME This is an array show.network = tvdbshow.network show.content_rating = tvdbshow.content_rating show.runtime = tvdbshow.runtime show.status = tvdbshow.status show.first_aired = tvdbshow.first_aired show.airs_day = tvdbshow.airs_day show.airs_time = tvdbshow.airs_time show.tvdb_language = tvdbshow.language if tvdbshow.rating: show.tvdb_rating = tvdbshow.rating show.tvdb_banner_url = tvdbshow.banner_url show.tvdb_fanart_url = tvdbshow.fanart_url show.tvdb_poster_url = tvdbshow.poster_url show.tvdb_last_updated = tvdbshow.last_updated show.save() # Download the images for the show filename = "%s/banner/%s.jpg" % (settings.MEDIANAV_TV_MEDIA, show.tvdb_showid) if not os.access(filename, os.F_OK): print "Downloading banner image to %s" % (filename) urllib.urlretrieve(show.tvdb_banner_url, filename) filename = "%s/poster/%s.jpg" % (settings.MEDIANAV_TV_MEDIA, show.tvdb_showid) if not os.access(filename, os.F_OK): print "Downloading poster image to %s" % (filename) urllib.urlretrieve(show.tvdb_poster_url, filename) filename = "%s/fanart/%s.jpg" % (settings.MEDIANAV_TV_MEDIA, show.tvdb_showid) if not os.access(filename, os.F_OK): print "Downloading fanart image to %s" % (filename) urllib.urlretrieve(show.tvdb_fanart_url, filename) # Add / Update episodes from tvdb to medianav for tvdbepisode in tvdbepisodes: #update = 0 #update_fields = "" try: print "Update: s%02de%02d %s" % ( int(tvdbepisode.season_number), int(tvdbepisode.episode_number), tvdbepisode.name.encode('latin-1', 'ignore')) episode = Episode.objects.get(tvdb_episodeid=tvdbepisode.id) except Episode.DoesNotExist: episode = Episode(tvdb_episodeid=tvdbepisode.id) print "Create: s%02de%02d %s" % ( int(tvdbepisode.season_number), int(tvdbepisode.episode_number), tvdbepisode.name.encode('latin-1', 'ignore')) #if episode.show != show: # update = 1 # update_fields += " show" #if episode.name != tvdbepisode.name: # update = 1 # update_fields += " name" episode.name = tvdbepisode.name episode.show = show episode.overview = tvdbepisode.overview episode.season_number = tvdbepisode.season_number episode.episode_number = tvdbepisode.episode_number episode.director = tvdbepisode.director episode.guest_stars = tvdbepisode.guest_stars episode.production_code = tvdbepisode.production_code episode.writer = tvdbepisode.writer episode.first_aired = tvdbepisode.first_aired episode.tvdb_language = tvdbepisode.language if tvdbepisode.rating: episode.tvdb_rating = tvdbepisode.rating episode.tvdb_image = tvdbepisode.image episode.tvdb_last_updated = tvdbepisode.last_updated episode.save() #if update: # print "Update: s%02de%02d %s [%s]" % (int(tvdbepisode.season_number), int(tvdbepisode.episode_number), tvdbepisode.name, update_fields), # Remove any episodes that are no longer in tvdb list for episode in show.episode_set.all(): if episode.tvdb_episodeid not in (int(e.id) for e in tvdbepisodes): print "Delete: s%02de%02d %s" % (episode.season_number, episode.episode_number, episode.name) episode.delete() else: print "Unable to retrieve information for show_id = %s" % (show_id, )
def check_show(id, show_id): try: show_startTime = datetime.now() headers = {'content-type': 'application/json'} payload = {'cmd': 'show', 'tvdbid': show_id} r = requests.get(sickbeard_api_url, params=payload, verify=False) showapi_detail = r.json() if not showapi_detail["result"] == "success": #q.put("Error: result bad") return update_show = Show.objects.get(tvdbid=show_id) #if update_show.use_sickbeard == False: #sickbeard doesnt need to check this # return #print "{:3d} {:40s} {:10s}".format(id, update_show.name, "CHECKING") #print 'Checking Show #'+id+' - ' + update_show.name update_show.name = showapi_detail["data"]['show_name'].encode( 'utf8', 'replace')[:200] #update_show.date_added=showapi_detail["data"]['date_added'].encode('utf8', 'replace') #update_show.date_updated=datetime.date.today() #update_show.date_aired=showapi_detail["data"]['date_aired'].encode('utf8', 'replace') if showapi_detail["data"]['next_ep_airdate']: update_show.date_next_episode = datetime.strptime( showapi_detail["data"]['next_ep_airdate'].encode( 'utf8', 'replace'), "%Y-%m-%d") update_show.file_path = showapi_detail["data"]['location'].encode( 'utf8', 'replace') #update_show.tvdbid=showapi_detail["data"]['tvdb_series_id'].encode('utf8', 'replace') update_show.genre = ",".join(showapi_detail["data"]['genre']).encode( 'utf8', 'replace')[:200] update_show.airs = showapi_detail["data"]['airs'].encode( 'utf8', 'replace')[:50] update_show.network = showapi_detail["data"]['network'].encode( 'utf8', 'replace')[:50] #update_show.actors=showapi_detail["data"]['actors'].encode('utf8', 'replace')[:400] #update_show.runtime=showapi_detail["data"]['runtime'].encode('utf8', 'replace')[:42] + ' minutes' update_show.save() for sea in showapi_detail["data"]['season_list']: try: update_season = Season.objects.get(show=update_show, number=sea) #print ' -Updated Season '+str(sea) check_episodes(update_show, update_season) except Season.DoesNotExist: new_season = Season( show=update_show, number=sea, ) new_season.save() print "{:3d} {:40s} {:10s} {:3s}".format( id, update_show.name, "ADDED SEA", 'S' + str(sea)) #print ' -Added Season - '+update_show.name+' '+str(sea) print "{:3d} {:40s} {:10s} {:25s}".format( id, update_show.name, "UPDATED", str(datetime.now() - show_startTime)) #print '%d %10s - %s (%s)' % id, "UPDATED", update_show.name, str(datetime.now()-show_startTime) #q.put('Updated Show - ' + update_show.name) except Show.DoesNotExist: #print showapi_detail["data"]["show_name"] new_show = Show( name=showapi_detail["data"]['show_name'].encode('utf8', 'replace')[:200], date_next_episode=datetime.strptime( showapi_detail["data"]['next_ep_airdate'].encode( 'utf8', 'replace'), "%Y-%m-%d"), file_path=showapi_detail["data"]['location'].encode( 'utf8', 'replace'), genre=",".join(showapi_detail["data"]['genre']).encode( 'utf8', 'replace')[:200], tvdbid=show_id.encode('utf8', 'replace'), airs=showapi_detail["data"]['airs'].encode('utf8', 'replace')[:50], network=showapi_detail["data"]['network'].encode( 'utf8', 'replace')[:50], ) new_show.save() #print '%d %10s - %s' % id, "CREATED", showapi_detail["data"]['show_name'] print "{:3d} {:40s} {:10s}".format( id, showapi_detail["data"]['show_name'], "CREATED") except: print '!!!!!!! ERROR Show #' + str( id) + ' - ' + showapi_detail["data"]['show_name'] traceback.print_exc()
if not update_show.airs: update_show.airs=showapi_detail["data"]['airs'].encode('utf8')[:50] update_show.network=showapi_detail["data"]['network'].encode('utf8')[:50] #update_show.actors=showapi_detail["data"]['actors'].encode('utf8')[:400] #update_show.runtime=showapi_detail["data"]['runtime'].encode('utf8')[:42] + ' minutes' update_show.save() for sea in showapi_detail["data"]['season_list']: season_item = update_season(update_show,sea) update_episodes(season_item) print 'Updated Show - ' + showapi_detail["data"]['show_name'] except Show.MultipleObjectsReturned as e: new_show = Show.objects.filter(tvdbid = show_id).reverse()[0].delete() print 'Deleted Show (Duplicate) - ' + show_id except Show.DoesNotExist: #print showapi_detail["data"]["show_name"] new_show = Show( name=showapi_detail["data"]['show_name'].encode('utf8')[:200], date_next_episode=datetime.strptime(showapi_detail["data"]['next_ep_airdate'].encode('utf8'), "%Y-%m-%d"), file_path=showapi_detail["data"]['location'].encode('utf8'), genre=",".join(showapi_detail["data"]['genre']).encode('utf8')[:200], tvdbid=show_id.encode('utf8'), airs=showapi_detail["data"]['airs'].encode('utf8')[:50], network=showapi_detail["data"]['network'].encode('utf8')[:50], ) new_show.save() print 'Created Show - ' + showapi_detail["data"]['show_name']