11#!/usr/bin/env python
2- # !/usr/bin/env python
32# -*- coding: utf-8 -*-
43from __future__ import unicode_literals
54from . import db
@@ -292,7 +291,6 @@ def addTVdb(full_update=True, libasins=None, cj=True):
292291 EPISODE_COUNT = 0
293292 approx = 0
294293 retrycount = 0
295- retrystart = 0
296294
297295 if full_update and not libasins :
298296 if updateRunning ():
@@ -315,32 +313,26 @@ def addTVdb(full_update=True, libasins=None, cj=True):
315313 ALL_SEASONS_ASINS = []
316314 new_libasins = checkLibraryAsins (libasins , cj )
317315 if not new_libasins :
318- return
316+ return False
319317 else :
320318 while not approx :
321319 jsondata = appfeed .getList ('TVEpisode&RollUpToSeason=T' , randint (1 , 20 ), NumberOfResults = 1 )
322320 approx = jsondata ['message' ]['body' ].get ('approximateSize' , 0 )
323321 xbmc .sleep (randint (500 , 1000 ))
324322
325323 while goAhead == 1 :
326- MAX = randint (5 , MAX_RES )
324+ MAX = randint (20 , MAX_RES )
327325 jsondata = appfeed .getList ('TVEpisode&RollUpToSeason=T' , endIndex , isPrime = prime ,
328326 OrderBy = 'Title' , NumberOfResults = MAX , AsinList = new_libasins )
329327 if not jsondata :
330328 goAhead = - 1
331329 break
332330
333331 titles = jsondata ['message' ]['body' ]['titles' ]
334- endI = jsondata ['message' ]['body' ]['endIndex' ]
335- if endI :
336- endIndex = endI
337- else :
338- endIndex += len (titles )
339- del jsondata
332+ endIndex += len (titles )
340333
341334 if titles :
342335 retrycount = 0
343- retrystart = 0
344336 SERIES_ASINS = ''
345337 EPISODE_ASINS = []
346338 EPISODE_NUM = []
@@ -406,40 +398,38 @@ def addTVdb(full_update=True, libasins=None, cj=True):
406398 del titles
407399 else :
408400 retrycount += 1
401+ endIndex += 1
409402
410403 if (approx and endIndex + 1 >= approx ) or (not approx ):
411404 goAhead = 0
412405
413406 if retrycount > 2 :
414- if not retrystart :
415- retrystart = time .time ()
416- elif time .time () > retrystart + max_wt :
417- Log ('Maxium wait time exceed, canceling database update' )
418- return False
419407 wait_time = randint (180 , 420 )
420408 Log ('Getting {} times a empty response. Waiting {} sec' .format (retrycount , wait_time ))
421- sleep (wait_time )
409+ # sleep(wait_time)
422410 retrycount = 0
423411
424412 if goAhead == 0 :
413+ finished = False
425414 if not libasins :
426415 updatePop ()
427416 delShows , delSeasons , delEpisodes = deleteremoved (getcompresult (ALL_SEASONS_ASINS ))
428417 UpdateDialog (SERIES_COUNT , SEASON_COUNT , EPISODE_COUNT , delShows , delSeasons , delEpisodes )
429- addTVdb (False , 'full' , cj )
430-
431- fixDBLShows ()
432- fixYears ()
433- fixStars ()
434- fixHDshows ()
435- updateEpisodes ()
436- fixTitles ()
437- if full_update :
438- setNewest ()
439- DialogPG .close ()
440- updateFanart ()
441- tvDB .commit ()
442- return True
418+ finished = addTVdb (False , 'full' , cj )
419+
420+ if not finished :
421+ fixDBLShows ()
422+ fixYears ()
423+ fixStars ()
424+ fixHDshows ()
425+ updateEpisodes ()
426+ fixTitles ()
427+ if full_update :
428+ setNewest ()
429+ DialogPG .close ()
430+ updateFanart ()
431+ tvDB .commit ()
432+ return True
443433
444434 return False
445435
0 commit comments