Skip to content

Fix catalog importer#119

Open
LoloZarro wants to merge 1 commit intolostb1t:mainfrom
LoloZarro:catalog_importer_fix
Open

Fix catalog importer#119
LoloZarro wants to merge 1 commit intolostb1t:mainfrom
LoloZarro:catalog_importer_fix

Conversation

@LoloZarro
Copy link

Fix catalog import:

  • Collections not getting created or updated
  • Collection getting recreated instead of updated
  • Collection overwriting themself
  • No safeguards for catalogs having less item than configured and constantly looping over the same items
  • No checks for existing items in the collection, leading to the same items getting imported and the collection not progressing
  • Import will now only stop after having imported reaching the configured amount for actual new items added to it
  • Every catalog in the settings will get it's own collection (e.g. Netflix -> Netflix movies & Netflix series)
  • Minor changes

@LoloZarro
Copy link
Author

Do not merge yet, still concluding my tests.

@LoloZarro
Copy link
Author

@lostb1t
Test OK!

Test Results

  • Catalogs are correctly imported
  • Catalogs are correctly grouped into Collections
  • Catalog import will create a collection for each catalog
  • Catalog import will now always update the collection if the setting is enabled
  • Catalog import will now correctly expand the according collection instead of recreating it each run
  • Catalog import will now run until the configured amount of new items are saved
  • Catalog import will now detect if a catalog delivers the same items each time and abort the catalog import after 3 tries

@j4ckgrey
Copy link
Contributor

Do not merge yet got me wondering 😂 is he gonna read your PR?

@LoloZarro LoloZarro force-pushed the catalog_importer_fix branch from e18bcb6 to 6df8eb4 Compare February 28, 2026 22:42
@lostb1t
Copy link
Owner

lostb1t commented Mar 1, 2026

There's a reason collections items are cleared before inserting. To preserve the ordering of the catalog.

@LoloZarro LoloZarro force-pushed the catalog_importer_fix branch from 6df8eb4 to ca36a68 Compare March 1, 2026 12:51
@LoloZarro
Copy link
Author

@lostb1t
Changed, it will now always empty the collection and populate the items in order received from the catalog.

@lostb1t
Copy link
Owner

lostb1t commented Mar 1, 2026

Any AI used?

@LoloZarro
Copy link
Author

Only for research and boilerplate, every line was written by me.

@LoloZarro LoloZarro force-pushed the catalog_importer_fix branch from ca36a68 to df77f62 Compare March 1, 2026 14:01
@LoloZarro
Copy link
Author

@lostb1t
I will now trigger a library scan after importing the catalogs. This should mitigate the issue, where the Collections Library will appear empty after modifying the collections.

I only did limited testing, but it seems to work so far.
If you want I can remove it and make a separate PR after merging this.

@lostb1t
Copy link
Owner

lostb1t commented Mar 1, 2026

im a bit confused on what this Pr actually does different then the current code. Im aware if the empty collection folder but what other issues did you encounter that made you make this PR?

@LoloZarro
Copy link
Author

There are several things mentioned in the first comment.


Collections not getting created or updated:
The previous code never updated the catalogs if the items exceeded max items for that catalog.
Example:
Catalog limit is 100 -> logic will fetch items -> gets 99 -> adds items to the library -> then fetches the next page -> gets 99 -> adds 1 item to the library then aborts without updating the catalog


Collection getting recreated instead of updated
The previous code never actually updated the collections, instead it recreated the collection with the set limit.

Example:
I set the limit to 10 -> Collection will not always contain 10 items (the 10 newest)

The collection never progressed which makes the global limit useless. Now it will only stop after importing the set amount of actual new items configured in the setting.

Example:
I set the limit to 10 -> Collection already contains 10 items -> it will now loop until it encounters 10 items not yet in the collection -> library will contain 20 items after the import.


No safeguards for catalogs having less item than configured and constantly looping over the same items
Previous code unnecessarily looped over the same items over and over again if it got less than the limit set in the setting.

Example:
Netflix Top 10 will always deliver 10 items, if I set the limit to 1000 it will loop 100 times over the same 10 items. Now it will detect stale results and abort.


Every catalog in the settings will get it's own collection (e.g. Netflix -> Netflix movies & Netflix series)
The previous code had a bug, where it would create the collections for the catalog, unfortunately it would overwrite itself if a catalog had the same name.

Example:
Netflix catalog has one for movies and series.
Before it would create a collection Netflix with the provider for series, import it then go to the next catalog which would be Netflix movies and would then update the collection Netflix and overwrite the provider with the movies.

Collection providers can only contain one value for the same key.

Now every catalog you see in the settings will get it's own collection.


There were some other things, but this should give you an overview of the key changes.

cfg.MovieFolder = _manager.TryGetMovieFolder(cfg);
cfg.SeriesFolder = _manager.TryGetSeriesFolder(cfg);

cfg.MovieFolder = _manager.TryGetConfigFolder(cfg.MoviePath);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whats the reason this has been moved?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Passing the whole Plugin config just to extract a string property seems excessive.

GelatoPlugin.Instance.SaveConfiguration();
}

public CatalogConfig? GetCatalogConfig(string id, string type)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whats the reason this has been moved?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This just fetches something from the config and does not really belong in the service in my opinion. It can also be static and does not have any dependencies.

The helper can be called from anywhere without having to inject the CatalogService just for this.

{
private const string ProviderKey = "Stremio";

// TODO: Add property for "FullName" on CatalogConfig Object and use that instead of manually creating it here.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not do this todo?

existingCollectionIds = currentCollectionItems.ToHashSet();
}

if (existingCollectionIds?.Count >= cfg.MaxCollectionItems)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Catalogs are dynamic, this prevents new items to shown up in collections.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a collection reaches the max items configured in the settings, it should not be expanded further, that seems fine to me.

Granted, the check in the beginning should be removed or at least tied to the above block as it would currently block new items from even getting imported in the library.

Proposal:
I will remove the check in the beginning.
When updating the collection I will check if the max size has been reached and then only update the collection with the newest items up to the max configured collection size.

Would that work for you?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but that results in the exact same logic as there is now? Currently it purges all items in a collection and reinsterts.

Are you maybe talking about MaxItems instead of MaxCollectionItems?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The MaxItems setting on the Catalogs themself are now being used to set the amount of new items (not currently present in the collection), while the MaxCollectionItems are used to limit how many items the collection will include in total (it's the upper cap).

The current logic does not use the MaxCollection items.

The MaxItems currently limits the size of the Collection instead of using the MaxCollectionItems.

If you set the MaxItems setting on the Catalog in the settings the resulting size will always be that value. If you set it to 50 and run the import twice the collection will contain 50 items.

With this change if you set it to 50 and run it twice it will contain 100.

Copy link
Author

@LoloZarro LoloZarro Mar 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed it as proposed. The check is still there and will generate a warning, but it will continue with adding new items to the library and will update the collection with the newest amount of items configured in MaxCollectionItems.

So even if the max size has been reached the collection will be updated and contain newest items up to the configured cap.


allSeenLibraryCatalogItems.Add(item);

if (existingCollectionIds?.Contains(item.Id) ?? true)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

existing checks arent needed as its cleared

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comment above

var currentChildren = collection.GetLinkedChildren().Select(i => i.Id).ToArray();
var currentChildrenSet = new HashSet<Guid>(currentChildren);

var newItems = allRetrievedCatalogItems
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

existing checks arent needed as its cleared

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comment above

- Collections not getting created or updated
- Collection getting recreated instead of updated
- Collection overwriting themself
- No safeguards for catalogs having less item than configured and constantly looping over the same items
- No checks for existing items in the collection, leading to the same items getting imported and the collection not progressing
- Import will now only stop after having imported reaching the configured amount for actual new items added to it
- Every catalog in the settings will get it's own collection (e.g. Netflix -> Netflix movies & Netflix series)
- Minor changes
@LoloZarro LoloZarro force-pushed the catalog_importer_fix branch from df77f62 to 609c424 Compare March 1, 2026 20:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants