hydrus/include/ClientImportGallery.py

1524 lines
51 KiB
Python
Raw Normal View History

2018-07-18 21:07:15 +00:00
import ClientConstants as CC
import ClientDownloading
import ClientImportFileSeeds
import ClientImportGallerySeeds
import ClientImporting
import ClientImportOptions
import ClientNetworkingJobs
import ClientPaths
import HydrusConstants as HC
import HydrusData
import HydrusExceptions
import HydrusGlobals as HG
import HydrusPaths
import HydrusSerialisable
import threading
import time
import traceback
import wx
class GalleryImport( HydrusSerialisable.SerialisableBase ):
SERIALISABLE_TYPE = HydrusSerialisable.SERIALISABLE_TYPE_GALLERY_IMPORT
SERIALISABLE_NAME = 'Gallery Import'
SERIALISABLE_VERSION = 1
2018-08-01 20:44:57 +00:00
def __init__( self, query = None, gallery_identifier = None ):
2018-07-18 21:07:15 +00:00
# eventually move this to be ( name, first_url ). the name will be like 'samus_aran on gelbooru'
2018-08-01 20:44:57 +00:00
# then queue up a first url
if query is None:
query = 'samus_aran'
2018-07-18 21:07:15 +00:00
if gallery_identifier is None:
gallery_identifier = ClientDownloading.GalleryIdentifier( HC.SITE_TYPE_DEVIANT_ART )
HydrusSerialisable.SerialisableBase.__init__( self )
self._creation_time = HydrusData.GetNow()
2018-08-01 20:44:57 +00:00
self._gallery_import_key = HydrusData.GenerateKey()
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
self._query = query
2018-07-18 21:07:15 +00:00
self._gallery_identifier = gallery_identifier
self._page_key = 'initialising page key'
self._publish_to_page = False
self._current_page_index = 0
2018-08-01 20:44:57 +00:00
self._num_new_urls_found = 0
2018-07-18 21:07:15 +00:00
self._num_urls_found = 0
self._file_limit = HC.options[ 'gallery_file_limit' ]
self._gallery_paused = False
self._files_paused = False
self._file_import_options = HG.client_controller.new_options.GetDefaultFileImportOptions( 'loud' )
self._tag_import_options = ClientImportOptions.TagImportOptions( is_default = True )
self._last_gallery_page_hit_timestamp = 0
self._gallery_seed_log = ClientImportGallerySeeds.GallerySeedLog()
self._file_seed_cache = ClientImportFileSeeds.FileSeedCache()
self._no_work_until = 0
self._no_work_until_reason = ''
self._lock = threading.Lock()
self._gallery_status = ''
self._gallery_status_can_change_timestamp = 0
self._current_action = ''
2018-08-01 20:44:57 +00:00
self._file_network_job = None
self._gallery_network_job = None
2018-07-18 21:07:15 +00:00
self._files_repeating_job = None
self._gallery_repeating_job = None
HG.client_controller.sub( self, 'NotifyFileSeedsUpdated', 'file_seed_cache_file_seeds_updated' )
def _AddSearchPage( self, page_index ):
try:
gallery = ClientDownloading.GetGallery( self._gallery_identifier )
except Exception as e:
HydrusData.PrintException( e )
self._files_paused = True
self._gallery_paused = True
HydrusData.ShowText( 'A downloader could not load its gallery! It has been paused and the full error has been written to the log!' )
return
gallery_url = gallery.GetGalleryPageURL( self._query, page_index )
gallery_seed = ClientImportGallerySeeds.GallerySeed( gallery_url, can_generate_more_pages = True )
self._gallery_seed_log.AddGallerySeeds( ( gallery_seed, ) )
2018-08-01 20:44:57 +00:00
def _AmOverFileLimit( self ):
if self._file_limit is not None and self._num_new_urls_found >= self._file_limit:
return True
return False
2018-07-18 21:07:15 +00:00
def _DelayWork( self, time_delta, reason ):
self._no_work_until = HydrusData.GetNow() + time_delta
self._no_work_until_reason = reason
def _GetSerialisableInfo( self ):
2018-08-01 20:44:57 +00:00
serialisable_gallery_import_key = self._gallery_import_key.encode( 'hex' )
2018-07-18 21:07:15 +00:00
serialisable_gallery_identifier = self._gallery_identifier.GetSerialisableTuple()
serialisable_file_import_options = self._file_import_options.GetSerialisableTuple()
serialisable_tag_import_options = self._tag_import_options.GetSerialisableTuple()
serialisable_gallery_seed_log = self._gallery_seed_log.GetSerialisableTuple()
serialisable_file_seed_cache = self._file_seed_cache.GetSerialisableTuple()
2018-08-01 20:44:57 +00:00
return ( serialisable_gallery_import_key, self._creation_time, self._query, serialisable_gallery_identifier, self._current_page_index, self._num_urls_found, self._num_new_urls_found, self._file_limit, self._gallery_paused, self._files_paused, serialisable_file_import_options, serialisable_tag_import_options, serialisable_gallery_seed_log, serialisable_file_seed_cache, self._no_work_until, self._no_work_until_reason )
2018-07-18 21:07:15 +00:00
def _InitialiseFromSerialisableInfo( self, serialisable_info ):
2018-08-01 20:44:57 +00:00
( serialisable_gallery_import_key, self._creation_time, self._query, serialisable_gallery_identifier, self._current_page_index, self._num_urls_found, self._num_new_urls_found, self._file_limit, self._gallery_paused, self._files_paused, serialisable_file_import_options, serialisable_tag_import_options, serialisable_gallery_seed_log, serialisable_file_seed_cache, self._no_work_until, self._no_work_until_reason ) = serialisable_info
self._gallery_import_key = serialisable_gallery_import_key.decode( 'hex' )
2018-07-18 21:07:15 +00:00
self._gallery_identifier = HydrusSerialisable.CreateFromSerialisableTuple( serialisable_gallery_identifier )
self._file_import_options = HydrusSerialisable.CreateFromSerialisableTuple( serialisable_file_import_options )
self._tag_import_options = HydrusSerialisable.CreateFromSerialisableTuple( serialisable_tag_import_options )
self._gallery_seed_log = HydrusSerialisable.CreateFromSerialisableTuple( serialisable_gallery_seed_log )
self._file_seed_cache = HydrusSerialisable.CreateFromSerialisableTuple( serialisable_file_seed_cache )
def _FileNetworkJobPresentationContextFactory( self, network_job ):
def enter_call():
with self._lock:
2018-08-01 20:44:57 +00:00
self._file_network_job = network_job
2018-07-18 21:07:15 +00:00
def exit_call():
with self._lock:
2018-08-01 20:44:57 +00:00
self._file_network_job = None
2018-07-18 21:07:15 +00:00
return ClientImporting.NetworkJobPresentationContext( enter_call, exit_call )
def _GalleryNetworkJobPresentationContextFactory( self, network_job ):
def enter_call():
with self._lock:
2018-08-01 20:44:57 +00:00
self._gallery_network_job = network_job
2018-07-18 21:07:15 +00:00
def exit_call():
with self._lock:
2018-08-01 20:44:57 +00:00
self._gallery_network_job = None
2018-07-18 21:07:15 +00:00
return ClientImporting.NetworkJobPresentationContext( enter_call, exit_call )
2018-08-01 20:44:57 +00:00
def _WorkOnFiles( self ):
2018-07-18 21:07:15 +00:00
file_seed = self._file_seed_cache.GetNextFileSeed( CC.STATUS_UNKNOWN )
if file_seed is None:
return
did_substantial_work = False
try:
if file_seed.WorksInNewSystem():
def status_hook( text ):
with self._lock:
self._current_action = text
2018-08-01 20:44:57 +00:00
did_substantial_work = file_seed.WorkOnURL( self._file_seed_cache, status_hook, ClientImporting.GenerateDownloaderNetworkJobFactory( self._page_key ), self._FileNetworkJobPresentationContextFactory, self._file_import_options, self._tag_import_options )
with self._lock:
should_present = self._publish_to_page and file_seed.ShouldPresent( self._file_import_options )
page_key = self._page_key
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
if should_present:
2018-07-18 21:07:15 +00:00
file_seed.PresentToPage( page_key )
did_substantial_work = True
else:
2018-08-01 20:44:57 +00:00
def network_job_factory( method, url, **kwargs ):
network_job = ClientNetworkingJobs.NetworkJobDownloader( self._page_key, method, url, **kwargs )
with self._lock:
self._file_network_job = network_job
return network_job
try:
gallery = ClientDownloading.GetGallery( self._gallery_identifier )
except Exception as e:
HydrusData.PrintException( e )
with self._lock:
self._files_paused = True
self._gallery_paused = True
HydrusData.ShowText( 'A downloader could not load its gallery! It has been paused and the full error has been written to the log!' )
return
gallery.SetNetworkJobFactory( network_job_factory )
2018-07-18 21:07:15 +00:00
with self._lock:
self._current_action = 'reviewing file'
file_seed.PredictPreImportStatus( self._file_import_options, self._tag_import_options )
status = file_seed.status
url = file_seed.file_seed_data
if status == CC.STATUS_SUCCESSFUL_BUT_REDUNDANT:
if self._tag_import_options.ShouldFetchTagsEvenIfURLKnownAndFileAlreadyInDB() and self._tag_import_options.WorthFetchingTags():
downloaded_tags = gallery.GetTags( url )
file_seed.AddTags( downloaded_tags )
elif status == CC.STATUS_UNKNOWN:
( os_file_handle, temp_path ) = ClientPaths.GetTempPath()
try:
with self._lock:
self._current_action = 'downloading file'
if self._tag_import_options.WorthFetchingTags():
downloaded_tags = gallery.GetFileAndTags( temp_path, url )
file_seed.AddTags( downloaded_tags )
else:
gallery.GetFile( temp_path, url )
file_seed.CheckPreFetchMetadata( self._tag_import_options )
with self._lock:
self._current_action = 'importing file'
file_seed.Import( temp_path, self._file_import_options )
did_substantial_work = True
finally:
HydrusPaths.CleanUpTempPath( os_file_handle, temp_path )
did_substantial_work = file_seed.WriteContentUpdates( self._tag_import_options )
2018-08-01 20:44:57 +00:00
with self._lock:
should_present = self._publish_to_page and file_seed.ShouldPresent( self._file_import_options )
page_key = self._page_key
if should_present:
2018-07-18 21:07:15 +00:00
file_seed.PresentToPage( page_key )
did_substantial_work = True
except HydrusExceptions.VetoException as e:
status = CC.STATUS_VETOED
note = HydrusData.ToUnicode( e )
file_seed.SetStatus( status, note = note )
if isinstance( e, HydrusExceptions.CancelledException ):
time.sleep( 2 )
except HydrusExceptions.NotFoundException:
status = CC.STATUS_VETOED
note = '404'
file_seed.SetStatus( status, note = note )
time.sleep( 2 )
except Exception as e:
status = CC.STATUS_ERROR
file_seed.SetStatus( status, exception = e )
time.sleep( 3 )
finally:
self._file_seed_cache.NotifyFileSeedsUpdated( ( file_seed, ) )
2018-08-01 20:44:57 +00:00
with self._lock:
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
self._file_network_job = None
2018-07-18 21:07:15 +00:00
with self._lock:
self._current_action = ''
if did_substantial_work:
time.sleep( ClientImporting.DID_SUBSTANTIAL_FILE_WORK_MINIMUM_SLEEP_TIME )
2018-08-01 20:44:57 +00:00
def _WorkOnGallery( self ):
2018-07-18 21:07:15 +00:00
gallery_seed = self._gallery_seed_log.GetNextGallerySeed( CC.STATUS_UNKNOWN )
if gallery_seed is None:
return
with self._lock:
2018-08-01 20:44:57 +00:00
if self._AmOverFileLimit():
self._gallery_paused = True
return
2018-07-18 21:07:15 +00:00
next_gallery_page_hit_timestamp = self._last_gallery_page_hit_timestamp + HG.client_controller.new_options.GetInteger( 'gallery_page_wait_period_pages' )
if not HydrusData.TimeHasPassed( next_gallery_page_hit_timestamp ):
if self._current_page_index == 0:
2018-08-01 20:44:57 +00:00
page_check_status = 'checking first page ' + HydrusData.TimestampToPrettyTimeDelta( next_gallery_page_hit_timestamp, just_now_threshold = 0 )
2018-07-18 21:07:15 +00:00
else:
2018-08-01 20:44:57 +00:00
page_check_status = 'checking next page ' + HydrusData.TimestampToPrettyTimeDelta( next_gallery_page_hit_timestamp, just_now_threshold = 0 )
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
self._gallery_status = page_check_status
2018-07-18 21:07:15 +00:00
return
2018-08-01 20:44:57 +00:00
self._gallery_status = 'now checking next page'
2018-07-18 21:07:15 +00:00
if gallery_seed.WorksInNewSystem():
def status_hook( text ):
with self._lock:
2018-08-01 20:44:57 +00:00
self._gallery_status = text
2018-07-18 21:07:15 +00:00
def title_hook( text ):
return
2018-08-01 20:44:57 +00:00
network_job_factory = ClientImporting.GenerateDownloaderNetworkJobFactory( self._page_key )
2018-07-18 21:07:15 +00:00
network_job_presentation_context_factory = self._GalleryNetworkJobPresentationContextFactory
if self._file_limit is None:
max_new_urls_allowed = None
else:
2018-08-01 20:44:57 +00:00
max_new_urls_allowed = self._file_limit - self._num_new_urls_found
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
try:
( num_urls_added, num_urls_already_in_file_seed_cache, num_urls_total, result_404 ) = gallery_seed.WorkOnURL( self._gallery_seed_log, self._file_seed_cache, status_hook, title_hook, network_job_factory, network_job_presentation_context_factory, self._file_import_options, max_new_urls_allowed = max_new_urls_allowed )
self._num_new_urls_found += num_urls_added
self._num_urls_found += num_urls_total
if num_urls_added > 0:
ClientImporting.WakeRepeatingJob( self._files_repeating_job )
self._current_page_index += 1
except HydrusExceptions.NetworkException as e:
with self._lock:
self._DelayWork( 4 * 3600, HydrusData.ToUnicode( e ) )
return
except Exception as e:
gallery_seed_status = CC.STATUS_ERROR
gallery_seed_note = HydrusData.ToUnicode( e )
gallery_seed.SetStatus( gallery_seed_status, note = gallery_seed_note )
HydrusData.PrintException( e )
with self._lock:
self._gallery_paused = True
finally:
self._last_gallery_page_hit_timestamp = HydrusData.GetNow()
2018-07-18 21:07:15 +00:00
else:
2018-08-01 20:44:57 +00:00
def network_job_factory( method, url, **kwargs ):
network_job = ClientNetworkingJobs.NetworkJobDownloader( self._page_key, method, url, **kwargs )
network_job.OverrideBandwidth( 30 )
with self._lock:
self._gallery_network_job = network_job
return network_job
2018-07-18 21:07:15 +00:00
try:
gallery = ClientDownloading.GetGallery( self._gallery_identifier )
except Exception as e:
HydrusData.PrintException( e )
with self._lock:
self._files_paused = True
self._gallery_paused = True
HydrusData.ShowText( 'A downloader could not load its gallery! It has been paused and the full error has been written to the log!' )
2018-08-01 20:44:57 +00:00
return
2018-07-18 21:07:15 +00:00
gallery.SetNetworkJobFactory( network_job_factory )
num_already_in_file_seed_cache = 0
new_file_seeds = []
try:
try:
gallery_url = gallery_seed.url
( page_of_file_seeds, definitely_no_more_pages ) = gallery.GetPage( gallery_url )
finally:
self._last_gallery_page_hit_timestamp = HydrusData.GetNow()
2018-08-01 20:44:57 +00:00
# do files
2018-07-18 21:07:15 +00:00
for file_seed in page_of_file_seeds:
2018-08-01 20:44:57 +00:00
self._num_urls_found += 1
2018-07-18 21:07:15 +00:00
if self._file_seed_cache.HasFileSeed( file_seed ):
num_already_in_file_seed_cache += 1
else:
with self._lock:
2018-08-01 20:44:57 +00:00
if self._AmOverFileLimit():
self._gallery_paused = True
2018-07-18 21:07:15 +00:00
break
new_file_seeds.append( file_seed )
2018-08-01 20:44:57 +00:00
self._num_new_urls_found += 1
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
num_urls_added = self._file_seed_cache.AddFileSeeds( new_file_seeds )
# do gallery pages
2018-07-18 21:07:15 +00:00
with self._lock:
no_urls_found = len( page_of_file_seeds ) == 0
no_new_urls = len( new_file_seeds ) == 0
2018-08-01 20:44:57 +00:00
am_over_limit = self._AmOverFileLimit()
if definitely_no_more_pages or no_urls_found or no_new_urls or am_over_limit:
2018-07-18 21:07:15 +00:00
pass # dead search
else:
self._current_page_index += 1
self._AddSearchPage( self._current_page_index )
2018-08-01 20:44:57 +00:00
# report and finish up
2018-07-18 21:07:15 +00:00
status = self._query + ': ' + HydrusData.ToHumanInt( len( new_file_seeds ) ) + ' new urls found'
if num_already_in_file_seed_cache > 0:
status += ' (' + HydrusData.ToHumanInt( num_already_in_file_seed_cache ) + ' of last page already in queue)'
2018-08-01 20:44:57 +00:00
if am_over_limit:
status += ' - hit file limit'
2018-07-18 21:07:15 +00:00
gallery_seed_status = CC.STATUS_SUCCESSFUL_AND_NEW
gallery_seed_note = status
if len( new_file_seeds ) > 0:
ClientImporting.WakeRepeatingJob( self._files_repeating_job )
except Exception as e:
if isinstance( e, HydrusExceptions.NotFoundException ):
text = 'gallery 404'
gallery_seed_status = CC.STATUS_VETOED
gallery_seed_note = text
else:
text = HydrusData.ToUnicode( e )
gallery_seed_status = CC.STATUS_ERROR
gallery_seed_note = text
HydrusData.DebugPrint( traceback.format_exc() )
finally:
2018-08-01 20:44:57 +00:00
with self._lock:
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
self._gallery_network_job = None
2018-07-18 21:07:15 +00:00
gallery_seed.SetStatus( gallery_seed_status, note = gallery_seed_note )
2018-08-01 20:44:57 +00:00
self._gallery_seed_log.NotifyGallerySeedsUpdated( ( gallery_seed, ) )
with self._lock:
self._gallery_status = ''
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
return True
def CurrentlyWorking( self ):
with self._lock:
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
finished = not self._file_seed_cache.WorkToDo()
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
return not finished and not self._files_paused
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
def FilesPaused( self ):
2018-07-18 21:07:15 +00:00
with self._lock:
2018-08-01 20:44:57 +00:00
return self._files_paused
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
def GalleryFinished( self ):
with self._lock:
return not self._gallery_seed_log.WorkToDo()
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
def GalleryPaused( self ):
with self._lock:
return self._gallery_paused
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
def GetCurrentAction( self ):
2018-07-18 21:07:15 +00:00
with self._lock:
2018-08-01 20:44:57 +00:00
return self._current_action
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
def GetFileImportOptions( self ):
with self._lock:
return self._file_import_options
2018-07-18 21:07:15 +00:00
def GetFileSeedCache( self ):
2018-08-01 20:44:57 +00:00
with self._lock:
return self._file_seed_cache
def GetFileLimit( self ):
with self._lock:
return self._file_limit
2018-07-18 21:07:15 +00:00
def GetGalleryIdentifier( self ):
2018-08-01 20:44:57 +00:00
with self._lock:
return self._gallery_identifier
def GetGalleryImportKey( self ):
with self._lock:
return self._gallery_import_key
2018-07-18 21:07:15 +00:00
def GetGallerySeedLog( self ):
2018-08-01 20:44:57 +00:00
with self._lock:
return self._gallery_seed_log
def GetGalleryStatus( self ):
with self._lock:
return self._gallery_status
def GetNetworkJobs( self ):
with self._lock:
return ( self._file_network_job, self._gallery_network_job )
2018-07-18 21:07:15 +00:00
def GetOptions( self ):
with self._lock:
return ( self._file_import_options, self._tag_import_options, self._file_limit )
2018-08-01 20:44:57 +00:00
def GetPresentedHashes( self ):
with self._lock:
return self._file_seed_cache.GetPresentedHashes( self._file_import_options )
def GetQueryText( self ):
with self._lock:
return self._query
2018-07-18 21:07:15 +00:00
def GetStatus( self ):
with self._lock:
return ( self._gallery_status, self._current_action, self._files_paused, self._gallery_paused )
2018-08-01 20:44:57 +00:00
def GetTagImportOptions( self ):
with self._lock:
return self._tag_import_options
2018-07-18 21:07:15 +00:00
def GetValueRange( self ):
with self._lock:
return self._file_seed_cache.GetValueRange()
def InitialiseFirstSearchPage( self ):
with self._lock:
self._AddSearchPage( 0 )
def NotifyFileSeedsUpdated( self, file_seed_cache_key, file_seeds ):
if file_seed_cache_key == self._file_seed_cache.GetFileSeedCacheKey():
ClientImporting.WakeRepeatingJob( self._files_repeating_job )
def PausePlayFiles( self ):
with self._lock:
self._files_paused = not self._files_paused
ClientImporting.WakeRepeatingJob( self._files_repeating_job )
def PausePlayGallery( self ):
with self._lock:
self._gallery_paused = not self._gallery_paused
ClientImporting.WakeRepeatingJob( self._gallery_repeating_job )
2018-08-01 20:44:57 +00:00
def PublishToPage( self, publish_to_page ):
2018-07-18 21:07:15 +00:00
with self._lock:
self._publish_to_page = publish_to_page
2018-08-01 20:44:57 +00:00
def Repage( self, page_key ):
2018-07-18 21:07:15 +00:00
with self._lock:
2018-08-01 20:44:57 +00:00
self._page_key = page_key
2018-07-18 21:07:15 +00:00
def SetFileLimit( self, file_limit ):
with self._lock:
self._file_limit = file_limit
def SetFileImportOptions( self, file_import_options ):
with self._lock:
self._file_import_options = file_import_options
2018-08-01 20:44:57 +00:00
def SetFileSeedCache( self, file_seed_cache ):
2018-07-18 21:07:15 +00:00
with self._lock:
2018-08-01 20:44:57 +00:00
self._file_seed_cache = file_seed_cache
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
def SetGallerySeedLog( self, gallery_seed_log ):
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
with self._lock:
self._gallery_seed_log = gallery_seed_log
def SetTagImportOptions( self, tag_import_options ):
with self._lock:
self._tag_import_options = tag_import_options
def Start( self, page_key, publish_to_page ):
self._page_key = page_key
self._publish_to_page = publish_to_page
self._files_repeating_job = HG.client_controller.CallRepeating( ClientImporting.GetRepeatingJobInitialDelay(), ClientImporting.REPEATING_JOB_TYPICAL_PERIOD, self.REPEATINGWorkOnFiles )
2018-07-18 21:07:15 +00:00
self._gallery_repeating_job = HG.client_controller.CallRepeating( ClientImporting.GetRepeatingJobInitialDelay(), ClientImporting.REPEATING_JOB_TYPICAL_PERIOD, self.REPEATINGWorkOnGallery )
def REPEATINGWorkOnFiles( self ):
with self._lock:
if ClientImporting.PageImporterShouldStopWorking( self._page_key ):
self._files_repeating_job.Cancel()
return
work_pending = self._file_seed_cache.WorkToDo() and not self._files_paused
no_delays = HydrusData.TimeHasPassed( self._no_work_until )
page_shown = not HG.client_controller.PageClosedButNotDestroyed( self._page_key )
ok_to_work = work_pending and no_delays and page_shown
while ok_to_work:
try:
2018-08-01 20:44:57 +00:00
self._WorkOnFiles()
2018-07-18 21:07:15 +00:00
HG.client_controller.WaitUntilViewFree()
except Exception as e:
HydrusData.ShowException( e )
with self._lock:
if ClientImporting.PageImporterShouldStopWorking( self._page_key ):
self._files_repeating_job.Cancel()
return
work_pending = self._file_seed_cache.WorkToDo() and not self._files_paused
no_delays = HydrusData.TimeHasPassed( self._no_work_until )
page_shown = not HG.client_controller.PageClosedButNotDestroyed( self._page_key )
ok_to_work = work_pending and no_delays and page_shown
def REPEATINGWorkOnGallery( self ):
with self._lock:
if ClientImporting.PageImporterShouldStopWorking( self._page_key ):
self._gallery_repeating_job.Cancel()
return
work_pending = self._gallery_seed_log.WorkToDo() and not self._gallery_paused
no_delays = HydrusData.TimeHasPassed( self._no_work_until )
page_shown = not HG.client_controller.PageClosedButNotDestroyed( self._page_key )
ok_to_work = work_pending and no_delays and page_shown
while ok_to_work:
try:
2018-08-01 20:44:57 +00:00
self._WorkOnGallery()
2018-07-18 21:07:15 +00:00
time.sleep( 1 )
HG.client_controller.WaitUntilViewFree()
except Exception as e:
HydrusData.ShowException( e )
with self._lock:
if ClientImporting.PageImporterShouldStopWorking( self._page_key ):
self._gallery_repeating_job.Cancel()
return
work_pending = self._gallery_seed_log.WorkToDo() and not self._gallery_paused
no_delays = HydrusData.TimeHasPassed( self._no_work_until )
page_shown = not HG.client_controller.PageClosedButNotDestroyed( self._page_key )
ok_to_work = work_pending and no_delays and page_shown
HydrusSerialisable.SERIALISABLE_TYPES_TO_OBJECT_TYPES[ HydrusSerialisable.SERIALISABLE_TYPE_GALLERY_IMPORT ] = GalleryImport
class MultipleGalleryImport( HydrusSerialisable.SerialisableBase ):
SERIALISABLE_TYPE = HydrusSerialisable.SERIALISABLE_TYPE_MULTIPLE_GALLERY_IMPORT
SERIALISABLE_NAME = 'Multiple Gallery Import'
2018-08-01 20:44:57 +00:00
SERIALISABLE_VERSION = 4
2018-07-18 21:07:15 +00:00
def __init__( self, gallery_identifier = None ):
if gallery_identifier is None:
gallery_identifier = ClientDownloading.GalleryIdentifier( HC.SITE_TYPE_DEVIANT_ART )
HydrusSerialisable.SerialisableBase.__init__( self )
2018-08-01 20:44:57 +00:00
self._lock = threading.Lock()
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
self._page_key = 'initialising page key'
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
self._gallery_identifier = gallery_identifier
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
self._highlighted_gallery_import_key = None
2018-07-18 21:07:15 +00:00
new_options = HG.client_controller.new_options
self._file_limit = HC.options[ 'gallery_file_limit' ]
self._file_import_options = HG.client_controller.new_options.GetDefaultFileImportOptions( 'loud' )
self._tag_import_options = ClientImportOptions.TagImportOptions( is_default = True )
2018-08-01 20:44:57 +00:00
self._gallery_imports = HydrusSerialisable.SerialisableList()
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
self._gallery_import_keys_to_gallery_imports = {}
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
self._status_dirty = True
self._status_cache = None
self._status_cache_generation_time = 0
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
self._last_pubbed_value_range = ( 0, 0 )
self._next_pub_value_check_time = 0
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
self._importers_repeating_job = None
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
def _AddGalleryImport( self, gallery_import ):
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
gallery_import.PublishToPage( False )
gallery_import.Repage( self._page_key )
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
self._gallery_imports.append( gallery_import )
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
gallery_import_key = gallery_import.GetGalleryImportKey()
self._gallery_import_keys_to_gallery_imports[ gallery_import_key ] = gallery_import
if len( self._gallery_imports ) == 1: # maybe turn this off as a option for advanced users
self._highlighted_gallery_import_key = gallery_import_key
2018-07-18 21:07:15 +00:00
def _GetSerialisableInfo( self ):
serialisable_gallery_identifier = self._gallery_identifier.GetSerialisableTuple()
2018-08-01 20:44:57 +00:00
if self._highlighted_gallery_import_key is None:
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
serialisable_highlighted_gallery_import_key = self._highlighted_gallery_import_key
2018-07-18 21:07:15 +00:00
else:
2018-08-01 20:44:57 +00:00
serialisable_highlighted_gallery_import_key = self._highlighted_gallery_import_key.encode( 'hex' )
2018-07-18 21:07:15 +00:00
serialisable_file_import_options = self._file_import_options.GetSerialisableTuple()
serialisable_tag_import_options = self._tag_import_options.GetSerialisableTuple()
2018-08-01 20:44:57 +00:00
serialisable_gallery_imports = self._gallery_imports.GetSerialisableTuple()
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
return ( serialisable_gallery_identifier, serialisable_highlighted_gallery_import_key, self._file_limit, serialisable_file_import_options, serialisable_tag_import_options, serialisable_gallery_imports )
2018-07-18 21:07:15 +00:00
def _InitialiseFromSerialisableInfo( self, serialisable_info ):
2018-08-01 20:44:57 +00:00
( serialisable_gallery_identifier, serialisable_highlighted_gallery_import_key, self._file_limit, serialisable_file_import_options, serialisable_tag_import_options, serialisable_gallery_imports ) = serialisable_info
2018-07-18 21:07:15 +00:00
self._gallery_identifier = HydrusSerialisable.CreateFromSerialisableTuple( serialisable_gallery_identifier )
2018-08-01 20:44:57 +00:00
if serialisable_highlighted_gallery_import_key is None:
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
self._highlighted_gallery_import_key = None
2018-07-18 21:07:15 +00:00
else:
2018-08-01 20:44:57 +00:00
self._highlighted_gallery_import_key = serialisable_highlighted_gallery_import_key.decode( 'hex' )
2018-07-18 21:07:15 +00:00
self._file_import_options = HydrusSerialisable.CreateFromSerialisableTuple( serialisable_file_import_options )
self._tag_import_options = HydrusSerialisable.CreateFromSerialisableTuple( serialisable_tag_import_options )
2018-08-01 20:44:57 +00:00
self._gallery_imports = HydrusSerialisable.CreateFromSerialisableTuple( serialisable_gallery_imports )
self._gallery_import_keys_to_gallery_imports = { gallery_import.GetGalleryImportKey() : gallery_import for gallery_import in self._gallery_imports }
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
def _RegenerateStatus( self ):
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
file_seed_caches = [ gallery_import.GetFileSeedCache() for gallery_import in self._gallery_imports ]
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
self._status_cache = ClientImportFileSeeds.GenerateFileSeedCachesStatus( file_seed_caches )
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
self._status_dirty = False
self._status_cache_generation_time = HydrusData.GetNow()
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
def _RemoveGalleryImport( self, gallery_import_key ):
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
if gallery_import_key not in self._gallery_import_keys_to_gallery_imports:
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
return
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
gallery_import = self._gallery_import_keys_to_gallery_imports[ gallery_import_key ]
gallery_import.PublishToPage( False )
gallery_import.Repage( 'dead page key' )
self._gallery_imports.remove( gallery_import )
del self._gallery_import_keys_to_gallery_imports[ gallery_import_key ]
def _SetDirty( self ):
self._status_dirty = True
2018-07-18 21:07:15 +00:00
def _UpdateSerialisableInfo( self, version, old_serialisable_info ):
if version == 1:
( serialisable_gallery_identifier, serialisable_gallery_stream_identifiers, serialisable_current_query_stuff, pending_queries, get_tags_if_url_recognised_and_file_redundant, file_limit, gallery_paused, files_paused, serialisable_file_import_options, serialisable_tag_import_options, serialisable_file_seed_cache ) = old_serialisable_info
new_serialisable_info = ( serialisable_gallery_identifier, serialisable_gallery_stream_identifiers, serialisable_current_query_stuff, pending_queries, file_limit, gallery_paused, files_paused, serialisable_file_import_options, serialisable_tag_import_options, serialisable_file_seed_cache )
return ( 2, new_serialisable_info )
if version == 2:
( serialisable_gallery_identifier, serialisable_gallery_stream_identifiers, serialisable_current_query_stuff, pending_queries, file_limit, gallery_paused, files_paused, serialisable_file_import_options, serialisable_tag_import_options, serialisable_file_seed_cache ) = old_serialisable_info
gallery_seed_log = ClientImportGallerySeeds.GallerySeedLog()
serialisable_gallery_seed_log = gallery_seed_log.GetSerialisableTuple()
new_serialisable_info = ( serialisable_gallery_identifier, serialisable_gallery_stream_identifiers, serialisable_current_query_stuff, pending_queries, file_limit, gallery_paused, files_paused, serialisable_file_import_options, serialisable_tag_import_options, serialisable_gallery_seed_log, serialisable_file_seed_cache )
return ( 3, new_serialisable_info )
2018-08-01 20:44:57 +00:00
if version == 3:
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
( serialisable_gallery_identifier, serialisable_gallery_stream_identifiers, serialisable_current_query_stuff, pending_queries, file_limit, gallery_paused, files_paused, serialisable_file_import_options, serialisable_tag_import_options, serialisable_gallery_seed_log, serialisable_file_seed_cache ) = old_serialisable_info
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
( current_query, current_query_num_new_urls, serialisable_current_gallery_stream_identifier, current_gallery_stream_identifier_page_index, serialisable_current_gallery_stream_identifier_found_urls, serialisable_pending_gallery_stream_identifiers ) = serialisable_current_query_stuff
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
highlighted_gallery_import_key = None
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
serialisable_highlighted_gallery_import_key = highlighted_gallery_import_key
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
gallery_imports = HydrusSerialisable.SerialisableList()
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
gallery_identifier = HydrusSerialisable.CreateFromSerialisableTuple( serialisable_gallery_identifier )
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
file_import_options = HydrusSerialisable.CreateFromSerialisableTuple( serialisable_file_import_options )
tag_import_options = HydrusSerialisable.CreateFromSerialisableTuple( serialisable_tag_import_options )
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
gallery_seed_log = HydrusSerialisable.CreateFromSerialisableTuple( serialisable_gallery_seed_log )
file_seed_cache = HydrusSerialisable.CreateFromSerialisableTuple( serialisable_file_seed_cache )
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
if len( file_seed_cache ) > 0:
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
current_query = 'queue brought from old page'
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
gallery_import = GalleryImport( current_query, gallery_identifier )
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
gallery_import.PausePlayGallery()
gallery_import.PausePlayFiles()
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
gallery_import.SetFileLimit( file_limit )
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
gallery_import.SetFileImportOptions( file_import_options )
gallery_import.SetTagImportOptions( tag_import_options )
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
gallery_import.SetFileSeedCache( file_seed_cache )
gallery_import.SetGallerySeedLog( gallery_seed_log )
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
gallery_imports.append( gallery_import )
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
for query in pending_queries:
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
pq_gallery_identifiers = ClientDownloading.GetGalleryStreamIdentifiers( gallery_identifier )
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
for pq_gallery_identifier in pq_gallery_identifiers:
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
gallery_import = GalleryImport( 'updated stub: ' + query + ' (will not run, please re-queue)', gallery_identifier )
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
gallery_import.PausePlayGallery()
gallery_import.PausePlayFiles()
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
gallery_import.SetFileLimit( file_limit )
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
gallery_import.SetFileImportOptions( file_import_options )
gallery_import.SetTagImportOptions( tag_import_options )
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
gallery_imports.append( gallery_import )
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
serialisable_gallery_imports = gallery_imports.GetSerialisableTuple()
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
new_serialisable_info = ( serialisable_gallery_identifier, serialisable_highlighted_gallery_import_key, file_limit, serialisable_file_import_options, serialisable_tag_import_options, serialisable_gallery_imports )
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
return ( 4, new_serialisable_info )
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
def CurrentlyWorking( self ):
with self._lock:
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
return True in ( gallery_import.CurrentlyWorking() for gallery_import in self._gallery_imports )
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
def GetFileLimit( self ):
with self._lock:
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
return self._file_limit
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
def GetFileImportOptions( self ):
with self._lock:
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
return self._file_import_options
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
def GetGalleryIdentifier( self ):
with self._lock:
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
return self._gallery_identifier
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
def GetGalleryImports( self ):
with self._lock:
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
return list( self._gallery_imports )
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
def GetGalleryImportKeys( self ):
with self._lock:
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
return set( self._gallery_import_keys_to_gallery_imports.keys() )
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
def GetHighlightedGalleryImport( self ):
2018-07-18 21:07:15 +00:00
with self._lock:
2018-08-01 20:44:57 +00:00
if self._highlighted_gallery_import_key is not None:
if self._highlighted_gallery_import_key in self._gallery_import_keys_to_gallery_imports:
return self._gallery_import_keys_to_gallery_imports[ self._highlighted_gallery_import_key ]
self._highlighted_gallery_import_key = None
return None
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
def GetTagImportOptions( self ):
with self._lock:
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
return self._tag_import_options
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
def GetTotalStatus( self ):
2018-07-18 21:07:15 +00:00
with self._lock:
2018-08-01 20:44:57 +00:00
if self._status_dirty:
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
self._RegenerateStatus()
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
return self._status_cache
def GetValueRange( self ):
with self._lock:
total_value = 0
total_range = 0
for gallery_import in self._gallery_imports:
( value, range ) = gallery_import.GetValueRange()
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
if value != range:
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
total_value += value
total_range += range
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
return ( total_value, total_range )
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
def PendQuery( self, query ):
2018-07-18 21:07:15 +00:00
with self._lock:
2018-08-01 20:44:57 +00:00
gallery_identifiers = ClientDownloading.GetGalleryStreamIdentifiers( self._gallery_identifier )
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
for gallery_identifier in gallery_identifiers:
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
gallery_import = GalleryImport( query, gallery_identifier )
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
gallery_import.SetFileLimit( self._file_limit )
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
gallery_import.SetFileImportOptions( self._file_import_options )
gallery_import.SetTagImportOptions( self._tag_import_options )
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
gallery_import.InitialiseFirstSearchPage()
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
publish_to_page = False
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
gallery_import.Start( self._page_key, publish_to_page )
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
self._AddGalleryImport( gallery_import )
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
ClientImporting.WakeRepeatingJob( self._importers_repeating_job )
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
self._SetDirty()
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
def RemoveGalleryImport( self, gallery_import_key ):
2018-07-18 21:07:15 +00:00
with self._lock:
2018-08-01 20:44:57 +00:00
self._RemoveGalleryImport( gallery_import_key )
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
self._SetDirty()
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
def SetFileLimit( self, file_limit ):
2018-07-18 21:07:15 +00:00
with self._lock:
2018-08-01 20:44:57 +00:00
self._file_limit = file_limit
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
def SetFileImportOptions( self, file_import_options ):
2018-07-18 21:07:15 +00:00
with self._lock:
2018-08-01 20:44:57 +00:00
self._file_import_options = file_import_options
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
def SetGalleryIdentifier( self, gallery_identifier ):
2018-07-18 21:07:15 +00:00
with self._lock:
2018-08-01 20:44:57 +00:00
self._gallery_identifier = gallery_identifier
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
def SetHighlightedGalleryImport( self, highlighted_gallery_import ):
2018-07-18 21:07:15 +00:00
with self._lock:
2018-08-01 20:44:57 +00:00
if highlighted_gallery_import is None:
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
self._highlighted_gallery_import_key = None
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
else:
self._highlighted_gallery_import_key = highlighted_gallery_import.GetGalleryImportKey()
highlighted_gallery_import.PublishToPage( True )
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
def SetTagImportOptions( self, tag_import_options ):
2018-07-18 21:07:15 +00:00
with self._lock:
2018-08-01 20:44:57 +00:00
self._tag_import_options = tag_import_options
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
def Start( self, page_key ):
2018-07-18 21:07:15 +00:00
with self._lock:
2018-08-01 20:44:57 +00:00
self._page_key = page_key
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
# set a 2s period so the page value/range is breddy snappy
self._importers_repeating_job = HG.client_controller.CallRepeating( ClientImporting.GetRepeatingJobInitialDelay(), 2.0, self.REPEATINGWorkOnImporters )
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
for gallery_import in self._gallery_imports:
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
publish_to_page = gallery_import.GetGalleryImportKey() == self._highlighted_gallery_import_key
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
gallery_import.Start( page_key, publish_to_page )
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
def REPEATINGWorkOnImporters( self ):
2018-07-18 21:07:15 +00:00
with self._lock:
2018-08-01 20:44:57 +00:00
if ClientImporting.PageImporterShouldStopWorking( self._page_key ):
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
self._importers_repeating_job.Cancel()
2018-07-18 21:07:15 +00:00
return
2018-08-01 20:44:57 +00:00
if not self._status_dirty: # if we think we are clean
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
for gallery_import in self._gallery_imports:
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
file_seed_cache = gallery_import.GetFileSeedCache()
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
if file_seed_cache.GetStatusGenerationTime() > self._status_cache_generation_time: # has there has been an update?
self._SetDirty()
break
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
if HydrusData.TimeHasPassed( self._next_pub_value_check_time ):
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
self._next_pub_value_check_time = HydrusData.GetNow() + 5
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
current_value_range = self.GetValueRange()
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
if current_value_range != self._last_pubbed_value_range:
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
self._last_pubbed_value_range = current_value_range
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
HG.client_controller.pub( 'refresh_page_name', self._page_key )
2018-07-18 21:07:15 +00:00
HydrusSerialisable.SERIALISABLE_TYPES_TO_OBJECT_TYPES[ HydrusSerialisable.SERIALISABLE_TYPE_MULTIPLE_GALLERY_IMPORT ] = MultipleGalleryImport