Exemple #1
0
def add_season(tv_show, tv_path):
    split_season = str(tv_path).split("\\")
    season_name = split_season[-1]
    tv_season_name = f"{tv_show[0].title} {season_name}"
    season = Season(tv=tv_show[0],
                    name=season_name,
                    tv_season_name=tv_season_name)
    season.save()
    return season
def update_season(show_item, season_number):
    try:
        update_season = Season.objects.get(show=show_item,
                                           number=season_number)
        return update_season
        #print '		-Updated Season '+str(sea)
    except Season.DoesNotExist:
        new_season = Season(
            show=show_item,
            number=season_number,
        )
        new_season.save()
        print '		-Added Season ' + str(season_number)
        return new_season
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()