hydrus/include/ClientImportGallery.py

1303 lines
43 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'
2018-09-05 20:52:32 +00:00
SERIALISABLE_VERSION = 2
2018-07-18 21:07:15 +00:00
2018-09-05 20:52:32 +00:00
def __init__( self, query = None, source_name = None, initial_search_urls = 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
2018-09-05 20:52:32 +00:00
if source_name is None:
2018-07-18 21:07:15 +00:00
2018-09-05 20:52:32 +00:00
source_name = 'unknown'
if initial_search_urls is None:
initial_search_urls = []
2018-07-18 21:07:15 +00:00
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-09-05 20:52:32 +00:00
self._source_name = source_name
2018-07-18 21:07:15 +00:00
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._gallery_seed_log = ClientImportGallerySeeds.GallerySeedLog()
2018-09-05 20:52:32 +00:00
gallery_seeds = [ ClientImportGallerySeeds.GallerySeed( url ) for url in initial_search_urls ]
self._gallery_seed_log.AddGallerySeeds( gallery_seeds )
2018-07-18 21:07:15 +00:00
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' )
2018-09-12 21:36:26 +00:00
HG.client_controller.sub( self, 'NotifyGallerySeedsUpdated', 'gallery_seed_log_gallery_seeds_updated' )
2018-07-18 21:07:15 +00:00
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_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-09-05 20:52:32 +00:00
return ( serialisable_gallery_import_key, self._creation_time, self._query, self._source_name, 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-09-05 20:52:32 +00:00
( serialisable_gallery_import_key, self._creation_time, self._query, self._source_name, 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
2018-08-01 20:44:57 +00:00
self._gallery_import_key = serialisable_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 )
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-15 20:40:30 +00:00
def _NetworkJobFactory( self, *args, **kwargs ):
network_job = ClientNetworkingJobs.NetworkJobDownloader( self._gallery_import_key, *args, **kwargs )
return network_job
2018-09-05 20:52:32 +00:00
def _UpdateSerialisableInfo( self, version, old_serialisable_info ):
if version == 1:
( 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 ) = old_serialisable_info
gallery_identifier = HydrusSerialisable.CreateFromSerialisableTuple( serialisable_gallery_identifier )
source_name = ClientDownloading.ConvertGalleryIdentifierToGUGName( gallery_identifier )
new_serialisable_info = ( serialisable_gallery_import_key, self._creation_time, self._query, source_name, 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 )
return ( 2, new_serialisable_info )
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:
2018-09-05 20:52:32 +00:00
def status_hook( text ):
2018-08-01 20:44:57 +00:00
2018-07-18 21:07:15 +00:00
with self._lock:
2018-09-05 20:52:32 +00:00
self._current_action = text
2018-07-18 21:07:15 +00:00
2018-09-05 20:52:32 +00:00
did_substantial_work = file_seed.WorkOnURL( self._file_seed_cache, status_hook, self._NetworkJobFactory, self._FileNetworkJobPresentationContextFactory, self._file_import_options, self._tag_import_options )
with self._lock:
2018-07-18 21:07:15 +00:00
2018-09-05 20:52:32 +00:00
should_present = self._publish_to_page and file_seed.ShouldPresent( self._file_import_options )
2018-07-18 21:07:15 +00:00
2018-09-05 20:52:32 +00:00
page_key = self._page_key
2018-07-18 21:07:15 +00:00
2018-09-05 20:52:32 +00:00
if should_present:
2018-07-18 21:07:15 +00:00
2018-09-05 20:52:32 +00:00
file_seed.PresentToPage( page_key )
2018-08-01 20:44:57 +00:00
2018-09-05 20:52:32 +00:00
did_substantial_work = True
2018-07-18 21:07:15 +00:00
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
2018-08-15 20:40:30 +00:00
self._gallery_status = ''
2018-08-01 20:44:57 +00:00
return
2018-07-18 21:07:15 +00:00
2018-08-22 21:10:59 +00:00
self._gallery_status = 'checking next page'
2018-07-18 21:07:15 +00:00
2018-08-22 21:10:59 +00:00
2018-09-05 20:52:32 +00:00
def file_seeds_callable( file_seeds ):
2018-08-22 21:10:59 +00:00
2018-09-05 20:52:32 +00:00
if self._file_limit is None:
2018-07-18 21:07:15 +00:00
2018-09-05 20:52:32 +00:00
max_new_urls_allowed = None
2018-07-18 21:07:15 +00:00
2018-09-05 20:52:32 +00:00
else:
2018-07-18 21:07:15 +00:00
2018-09-05 20:52:32 +00:00
max_new_urls_allowed = self._file_limit - self._num_new_urls_found
2018-07-18 21:07:15 +00:00
2018-09-05 20:52:32 +00:00
return ClientImporting.UpdateFileSeedCacheWithFileSeeds( self._file_seed_cache, file_seeds, max_new_urls_allowed )
2018-07-18 21:07:15 +00:00
2018-09-05 20:52:32 +00:00
def status_hook( text ):
with self._lock:
2018-08-01 20:44:57 +00:00
2018-09-05 20:52:32 +00:00
self._gallery_status = text
2018-08-01 20:44:57 +00:00
2018-07-18 21:07:15 +00:00
2018-09-05 20:52:32 +00:00
def title_hook( text ):
2018-07-18 21:07:15 +00:00
2018-09-05 20:52:32 +00:00
return
2018-08-01 20:44:57 +00:00
2018-09-05 20:52:32 +00:00
try:
2018-07-18 21:07:15 +00:00
2018-09-05 20:52:32 +00:00
( num_urls_added, num_urls_already_in_file_seed_cache, num_urls_total, result_404, added_new_gallery_pages, stop_reason ) = gallery_seed.WorkOnURL( 'download page', self._gallery_seed_log, file_seeds_callable, status_hook, title_hook, self._NetworkJobFactory, self._GalleryNetworkJobPresentationContextFactory, self._file_import_options )
2018-07-18 21:07:15 +00:00
2018-09-05 20:52:32 +00:00
self._num_new_urls_found += num_urls_added
self._num_urls_found += num_urls_total
2018-07-18 21:07:15 +00:00
2018-09-05 20:52:32 +00:00
if num_urls_added > 0:
2018-08-01 20:44:57 +00:00
2018-09-05 20:52:32 +00:00
ClientImporting.WakeRepeatingJob( self._files_repeating_job )
2018-07-18 21:07:15 +00:00
2018-09-05 20:52:32 +00:00
self._current_page_index += 1
except HydrusExceptions.NetworkException as e:
with self._lock:
2018-07-18 21:07:15 +00:00
2018-09-05 20:52:32 +00:00
self._DelayWork( 4 * 3600, HydrusData.ToUnicode( e ) )
2018-07-18 21:07:15 +00:00
2018-09-05 20:52:32 +00:00
return
except Exception as e:
gallery_seed_status = CC.STATUS_ERROR
gallery_seed_note = HydrusData.ToUnicode( e )
2018-07-18 21:07:15 +00:00
gallery_seed.SetStatus( gallery_seed_status, note = gallery_seed_note )
2018-09-05 20:52:32 +00:00
HydrusData.PrintException( e )
with self._lock:
self._gallery_paused = True
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
2018-10-03 21:00:15 +00:00
def CanRetryFailed( self ):
with self._lock:
return self._file_seed_cache.GetFileSeedCount( CC.STATUS_ERROR ) > 0
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
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-15 20:40:30 +00:00
def GetCreationTime( self ):
with self._lock:
return self._creation_time
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
2018-08-01 20:44:57 +00:00
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-09-05 20:52:32 +00:00
def GetSourceName( self ):
2018-07-18 21:07:15 +00:00
with self._lock:
2018-09-05 20:52:32 +00:00
return self._source_name
2018-07-18 21:07:15 +00:00
2018-09-05 20:52:32 +00:00
def GetStatus( self ):
2018-08-01 20:44:57 +00:00
with self._lock:
2018-09-05 20:52:32 +00:00
return ( self._gallery_status, self._current_action, self._files_paused, self._gallery_paused )
2018-08-01 20:44:57 +00:00
2018-09-05 20:52:32 +00:00
def GetTagImportOptions( self ):
2018-07-18 21:07:15 +00:00
with self._lock:
2018-09-05 20:52:32 +00:00
return self._tag_import_options
2018-07-18 21:07:15 +00:00
2018-09-05 20:52:32 +00:00
def GetValueRange( self ):
2018-07-18 21:07:15 +00:00
with self._lock:
2018-09-05 20:52:32 +00:00
return self._file_seed_cache.GetValueRange()
2018-07-18 21:07:15 +00:00
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 )
2018-09-12 21:36:26 +00:00
def NotifyGallerySeedsUpdated( self, gallery_seed_log_key, gallery_seeds ):
if gallery_seed_log_key == self._gallery_seed_log.GetGallerySeedLogKey():
ClientImporting.WakeRepeatingJob( self._gallery_repeating_job )
2018-07-18 21:07:15 +00:00
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
2018-10-03 21:00:15 +00:00
def RetryFailed( self ):
with self._lock:
self._file_seed_cache.RetryFailures()
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 )
2018-09-19 21:54:51 +00:00
network_engine_good = not HG.client_controller.network_engine.IsBusy()
2018-07-18 21:07:15 +00:00
2018-09-19 21:54:51 +00:00
ok_to_work = work_pending and no_delays and page_shown and network_engine_good
2018-07-18 21:07:15 +00:00
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 )
2018-09-19 21:54:51 +00:00
network_engine_good = not HG.client_controller.network_engine.IsBusy()
2018-07-18 21:07:15 +00:00
2018-09-19 21:54:51 +00:00
ok_to_work = work_pending and no_delays and page_shown and network_engine_good
2018-07-18 21:07:15 +00:00
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 )
2018-09-19 21:54:51 +00:00
network_engine_good = not HG.client_controller.network_engine.IsBusy()
2018-07-18 21:07:15 +00:00
2018-09-19 21:54:51 +00:00
ok_to_work = work_pending and no_delays and page_shown and network_engine_good
2018-07-18 21:07:15 +00:00
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 )
2018-09-19 21:54:51 +00:00
network_engine_good = not HG.client_controller.network_engine.IsBusy()
2018-07-18 21:07:15 +00:00
2018-09-19 21:54:51 +00:00
ok_to_work = work_pending and no_delays and page_shown and network_engine_good
2018-07-18 21:07:15 +00:00
2018-08-15 20:40:30 +00:00
with self._lock:
self._gallery_status = ''
2018-07-18 21:07:15 +00:00
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-09-05 20:52:32 +00:00
SERIALISABLE_VERSION = 5
2018-07-18 21:07:15 +00:00
2018-09-05 20:52:32 +00:00
def __init__( self, gug_key_and_name = None ):
2018-07-18 21:07:15 +00:00
2018-09-05 20:52:32 +00:00
if gug_key_and_name is None:
2018-07-18 21:07:15 +00:00
2018-09-05 20:52:32 +00:00
gug_key_and_name = ( HydrusData.GenerateKey(), 'unknown source' )
2018-07-18 21:07:15 +00:00
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-09-05 20:52:32 +00:00
self._gug_key_and_name = gug_key_and_name
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-08 20:29:54 +00:00
self._last_time_imports_changed = HydrusData.GetNowPrecise()
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-08 20:29:54 +00:00
self._last_time_imports_changed = HydrusData.GetNowPrecise()
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 ):
2018-09-05 20:52:32 +00:00
( gug_key, gug_name ) = self._gug_key_and_name
serialisable_gug_key_and_name = ( gug_key.encode( 'hex' ), gug_name )
2018-07-18 21:07:15 +00:00
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-09-05 20:52:32 +00:00
return ( serialisable_gug_key_and_name, 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-09-05 20:52:32 +00:00
( serialisable_gug_key_and_name, 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
2018-09-05 20:52:32 +00:00
( serialisable_gug_key, gug_name ) = serialisable_gug_key_and_name
self._gug_key_and_name = ( serialisable_gug_key.decode( 'hex' ), gug_name )
2018-07-18 21:07:15 +00:00
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 )
2018-08-08 20:29:54 +00:00
self._last_time_imports_changed = HydrusData.GetNowPrecise()
2018-08-01 20:44:57 +00:00
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
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-09-05 20:52:32 +00:00
gallery_import = GalleryImport( query = current_query, source_name = 'updated from old system', initial_search_urls = [] )
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
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
2018-09-05 20:52:32 +00:00
if version == 4:
( serialisable_gallery_identifier, serialisable_highlighted_gallery_import_key, file_limit, serialisable_file_import_options, serialisable_tag_import_options, serialisable_gallery_imports ) = old_serialisable_info
gallery_identifier = HydrusSerialisable.CreateFromSerialisableTuple( serialisable_gallery_identifier )
( gug_key, gug_name ) = ClientDownloading.ConvertGalleryIdentifierToGUGKeyAndName( gallery_identifier )
serialisable_gug_key_and_name = ( HydrusData.GenerateKey().encode( 'hex' ), gug_name )
new_serialisable_info = ( serialisable_gug_key_and_name, serialisable_highlighted_gallery_import_key, file_limit, serialisable_file_import_options, serialisable_tag_import_options, serialisable_gallery_imports )
return ( 5, new_serialisable_info )
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
2018-09-05 20:52:32 +00:00
def GetGalleryImports( self ):
2018-08-01 20:44:57 +00:00
with self._lock:
2018-07-18 21:07:15 +00:00
2018-09-05 20:52:32 +00:00
return list( self._gallery_imports )
2018-07-18 21:07:15 +00:00
2018-08-01 20:44:57 +00:00
2018-09-05 20:52:32 +00:00
def GetGUGKeyAndName( self ):
2018-08-01 20:44:57 +00:00
with self._lock:
2018-07-18 21:07:15 +00:00
2018-09-05 20:52:32 +00:00
return self._gug_key_and_name
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
2018-09-05 20:52:32 +00:00
def GetInitialSearchText( self ):
return HG.client_controller.network_engine.domain_manager.GetInitialSearchText( self._gug_key_and_name )
2018-08-08 20:29:54 +00:00
def GetLastTimeImportsChanged( self ):
with self._lock:
return self._last_time_imports_changed
def GetNumGalleryImports( self ):
with self._lock:
return len( self._gallery_imports )
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
2018-09-05 20:52:32 +00:00
def PendQuery( self, query_text ):
2018-07-18 21:07:15 +00:00
2018-08-08 20:29:54 +00:00
created_import = None
2018-07-18 21:07:15 +00:00
with self._lock:
2018-09-05 20:52:32 +00:00
gug = HG.client_controller.network_engine.domain_manager.GetGUG( self._gug_key_and_name )
2018-07-18 21:07:15 +00:00
2018-09-05 20:52:32 +00:00
if gug is None:
2018-07-18 21:07:15 +00:00
2018-09-05 20:52:32 +00:00
HydrusData.ShowText( 'Could not find a Gallery URL Generator for "' + self._gug_key_and_name[1] + '"!' )
2018-07-18 21:07:15 +00:00
2018-09-05 20:52:32 +00:00
return None
2018-07-18 21:07:15 +00:00
2018-09-05 20:52:32 +00:00
self._gug_key_and_name = gug.GetGUGKeyAndName() # just a refresher, to keep up with any changes
initial_search_urls = gug.GenerateGalleryURLs( query_text )
if len( initial_search_urls ) == 0:
2018-07-18 21:07:15 +00:00
2018-09-05 20:52:32 +00:00
HydrusData.ShowText( 'The Gallery URL Generator "' + self._gug_key_and_name[1] + '" did not produce any URLs!' )
2018-07-18 21:07:15 +00:00
2018-09-05 20:52:32 +00:00
return None
2018-08-08 20:29:54 +00:00
2018-07-18 21:07:15 +00:00
2018-09-05 20:52:32 +00:00
gallery_import = GalleryImport( query = query_text, source_name = self._gug_key_and_name[1], initial_search_urls = initial_search_urls )
gallery_import.SetFileLimit( self._file_limit )
gallery_import.SetFileImportOptions( self._file_import_options )
gallery_import.SetTagImportOptions( self._tag_import_options )
publish_to_page = False
gallery_import.Start( self._page_key, publish_to_page )
self._AddGalleryImport( gallery_import )
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-09-05 20:52:32 +00:00
return gallery_import
2018-08-08 20:29:54 +00:00
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-09-05 20:52:32 +00:00
def SetGUGKeyAndName( self, gug_key_and_name ):
2018-07-18 21:07:15 +00:00
with self._lock:
2018-09-05 20:52:32 +00:00
self._gug_key_and_name = gug_key_and_name
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