Exemple #1
0
    def GetServiceKeysToContentUpdates(
            self,
            status: int,
            media_result: ClientMediaResult.MediaResult,
            filterable_tags: typing.Iterable[str],
            external_filterable_tags=None,
            external_additional_service_keys_to_tags=None):

        if external_filterable_tags is None:

            external_filterable_tags = set()

        if external_additional_service_keys_to_tags is None:

            external_additional_service_keys_to_tags = ClientTags.ServiceKeysToTags(
            )

        filterable_tags = HydrusTags.CleanTags(filterable_tags)

        service_keys_to_tags = ClientTags.ServiceKeysToTags()

        for service_key in HG.client_controller.services_manager.GetServiceKeys(
                HC.REAL_TAG_SERVICES):

            service_additional_tags = set()

            if service_key in external_additional_service_keys_to_tags:

                service_additional_tags.update(
                    external_additional_service_keys_to_tags[service_key])

            if service_key in self._service_keys_to_service_tag_import_options:

                service_tag_import_options = self._service_keys_to_service_tag_import_options[
                    service_key]

                service_filterable_tags = set(filterable_tags)

                service_filterable_tags.update(external_filterable_tags)

                service_tags = service_tag_import_options.GetTags(
                    service_key, status, media_result, service_filterable_tags,
                    service_additional_tags)

            else:

                service_tags = service_additional_tags

            if len(service_tags) > 0:

                service_keys_to_tags[service_key] = service_tags

        hash = media_result.GetHash()

        service_keys_to_content_updates = ClientData.ConvertServiceKeysToTagsToServiceKeysToContentUpdates(
            {hash}, service_keys_to_tags)

        return service_keys_to_content_updates
Exemple #2
0
 def GetServiceKeysToContentUpdates( self, media_result: ClientMediaResult.MediaResult, names_and_notes: typing.Collection[ typing.Tuple[ str, str ] ] ):
     
     content_updates = []
     
     if self._get_notes:
         
         hash = media_result.GetHash()
         
         notes_manager = media_result.GetNotesManager()
         
         existing_names_to_notes = dict( notes_manager.GetNamesToNotes() )
         
         for ( name, note ) in names_and_notes:
             
             if name in self._names_to_name_overrides:
                 
                 name = self._names_to_name_overrides[ name ]
                 
             elif self._all_name_override is not None:
                 
                 name = self._all_name_override
                 
             
             if name in existing_names_to_notes:
                 
                 name_exists = True
                 
                 existing_note = existing_names_to_notes[ name ]
                 
                 name_and_note_exists = existing_note == note
                 
                 new_note_is_an_extension = existing_note in note
                 
             else:
                 
                 name_exists = False
                 name_and_note_exists = False
                 new_note_is_an_extension = False
                 
             
             do_it = True
             
             if name_and_note_exists:
                 
                 do_it = False
                 
             elif name_exists:
                 
                 if new_note_is_an_extension and self._extend_existing_note_if_possible:
                     
                     pass # yes let's do it with current name and note
                     
                 else:
                     
                     if self._conflict_resolution == NOTE_IMPORT_CONFLICT_IGNORE:
                         
                         do_it = False
                         
                     elif self._conflict_resolution == NOTE_IMPORT_CONFLICT_RENAME:
                         
                         existing_names = set( existing_names_to_notes.keys() )
                         
                         name = HydrusData.GetNonDupeName( name, existing_names )
                         
                     elif self._conflict_resolution == NOTE_IMPORT_CONFLICT_APPEND:
                         
                         existing_note = existing_names_to_notes[ name ]
                         
                         sep = os.linesep * 2
                         
                         note = sep.join( ( existing_note, note ) )
                         
                     
                 
             
             if do_it:
                 
                 existing_names_to_notes[ name ] = note
                 
                 content_updates.append( HydrusData.ContentUpdate( HC.CONTENT_TYPE_NOTES, HC.CONTENT_UPDATE_SET, ( hash, name, note ) ) )
                 
             
         
     
     service_keys_to_content_updates = {}
     
     if len( content_updates ) > 0:
         
         service_keys_to_content_updates[ CC.LOCAL_NOTES_SERVICE_KEY ] = content_updates
         
     
     return service_keys_to_content_updates