Jump to content

Using librarymanager to update images in 4.8.0.9 beta


mickle026

Recommended Posts

mickle026

Has something changed in 4.8.0.9 beta because library manager doesn't seem to be working as it did

var ImageList = new ItemImageInfo { Path = NewPath, Type = ImageType.Primary };

PersonDataBaseItem.SetImage(ImageList, 0);

libraryManager.UpdateImages(PersonDataBaseItem);

This works in the stable server but doesn't seem to in this beta?

When i check after editing the Primary image the primary image path has updated, but when I come out and go back the primary image path is empty again.

 

25.Sep.2022  -  02.07.37 Get Metadata or Refresh Metadata for Person Name: Alexis Fawx
25.Sep.2022  -  02.07.37 Person Internal (Item) ID: 209844 
25.Sep.2022  -  02.07.37 Person BaseItem ID (GUID): 07f74ff1-8e80-42d8-ac00-ace29e024a1d 
25.Sep.2022  -  02.07.37 Current Person PrimaryImagePath:  
25.Sep.2022  -  02.07.37 Alexis Fawx has no primary image, getting one ..... 
25.Sep.2022  -  02.07.39 Status Code: OK 
25.Sep.2022  -  02.07.44 File was Downloaded to: C:\Users\xxxx\AppData\Roaming\Emby-Server\programdata\metadata\IAFD\07\07f74ff1-8e80-42d8-ac00-ace29e024a1d\Alexis Fawx.jpg 
25.Sep.2022  -  02.07.44 Image was set succesfully
25.Sep.2022  -  02.07.44 Library Updated succesfully
25.Sep.2022  -  02.07.44 Updated Primary image Path: C:\Users\xxxx\AppData\Roaming\Emby-Server\programdata\metadata\IAFD\07\07f74ff1-8e80-42d8-ac00-ace29e024a1d\Alexis Fawx.jpg
25.Sep.2022  -  02.07.44 Job Completed!

Going back into the person..


25.Sep.2022  -  02.08.08 Get Metadata or Refresh Metadata for Person Name: Alexis Fawx
25.Sep.2022  -  02.08.08 Person Internal (Item) ID: 209844 
25.Sep.2022  -  02.08.08 Person BaseItem ID (GUID): 07f74ff1-8e80-42d8-ac00-ace29e024a1d 
25.Sep.2022  -  02.08.08 Current Person PrimaryImagePath:  
25.Sep.2022  -  02.08.08 Alexis Fawx has no primary image, getting one ..... 
25.Sep.2022  -  02.08.09 Status Code: OK 
25.Sep.2022  -  02.08.11 File was Downloaded to: C:\Users\xxxx\AppData\Roaming\Emby-Server\programdata\metadata\IAFD\07\07f74ff1-8e80-42d8-ac00-ace29e024a1d\Alexis Fawx.jpg 
25.Sep.2022  -  02.08.11 Image was set succesfully
25.Sep.2022  -  02.08.11 Library Updated succesfully
25.Sep.2022  -  02.08.11 Updated Primary image Path: C:\Users\xxxx\AppData\Roaming\Emby-Server\programdata\metadata\IAFD\07\07f74ff1-8e80-42d8-ac00-ace29e024a1d\Alexis Fawx.jpg
25.Sep.2022  -  02.08.11 Job Completed!

Converted the full function to an async task and its working

25.Sep.2022  -  02.21.24 Get Metadata or Refresh Metadata for Person Name: Ana Marco
25.Sep.2022  -  02.21.24 Person Internal (Item) ID: 217702 
25.Sep.2022  -  02.21.24 Person BaseItem ID (GUID): 776a168b-3566-4244-833d-248e26239ab8 
25.Sep.2022  -  02.21.24 Current Person PrimaryImagePath:  
25.Sep.2022  -  02.21.24 Ana Marco has no primary image, getting one ..... 
25.Sep.2022  -  02.21.25 Status Code: OK 
25.Sep.2022  -  02.21.26 File was Downloaded to: C:\Users\xxxx\AppData\Roaming\Emby-Server\programdata\metadata\IAFD\77\776a168b-3566-4244-833d-248e26239ab8\Ana Marco.jpg 
25.Sep.2022  -  02.21.26 Image was set succesfully
25.Sep.2022  -  02.21.26 Library Updated succesfully
25.Sep.2022  -  02.21.26 Updated Primary image Path: C:\Users\xxxx\AppData\Roaming\Emby-Server\programdata\metadata\IAFD\77\776a168b-3566-4244-833d-248e26239ab8\Ana Marco.jpg
25.Sep.2022  -  02.21.26 Job Completed!

2nd person entry (click)

25.Sep.2022  -  02.21.28 Get Metadata or Refresh Metadata for Person Name: Ana Marco
25.Sep.2022  -  02.21.28 Person Internal (Item) ID: 217702 
25.Sep.2022  -  02.21.28 Person BaseItem ID (GUID): 776a168b-3566-4244-833d-248e26239ab8 
25.Sep.2022  -  02.21.28 Current Person PrimaryImagePath: C:\Users\xxxx\AppData\Roaming\Emby-Server\programdata\metadata\IAFD\77\776a168b-3566-4244-833d-248e26239ab8\Ana Marco.jpg 

Whats different?

Edited by mickle026
Link to comment
Share on other sites

HI, well first of all I would use IProviderManager.SaveImage instead of what you're doing. It will do the work for you and then you just have to save the item back to the database after.

Link to comment
Share on other sites

mickle026

Hi Thanks for that but im a a bit confused.   My file is located in a folder on the disk.  Not at an Url address.

 

This is from older EMBY sourcode

        public Task SaveImage(BaseItem item, Stream source, string mimeType, ImageType type, int? imageIndex, CancellationToken cancellationToken)
        {
            return new ImageSaver(ConfigurationManager, _libraryMonitor, _fileSystem, _logger).SaveImage(item, source, mimeType, type, imageIndex, cancellationToken);
        }
                var url = image.Url;

                try
                {
                    var response = await provider.GetImageResponse(url, cancellationToken).ConfigureAwait(false);

                    await _providerManager.SaveImage(item, response.Content, response.ContentType, type, null, cancellationToken).ConfigureAwait(false);

                    result.UpdateType = result.UpdateType | ItemUpdateType.ImageUpdate;
                    return true;
                }
                catch (HttpException ex)
                {
                    // Sometimes providers send back bad url's. Just move to the next image
                    if (ex.StatusCode.HasValue && ex.StatusCode.Value == HttpStatusCode.NotFound)
                    {
                        continue;
                    }
                    break;
                }

 

This indicates that the file is a data stream.  I already have the file on disk in the cache.

 

var tokenSource = new CancellationTokenSource();
var token = tokenSource.Token;

var fileStream = _fileSystem.GetFileStream(TempFile, FileOpenMode.Open, FileAccessMode.Read, FileShareMode.ReadWrite, true);

await providerManager.SaveImage(IAFDPersonData, fileStream, TempFile, ImageType.Primary, null, token).ConfigureAwait(false);

If i try putting it in a stream then saveimage highlights and .SaveImage states that  no overload takes 6 arguments.

Untitled.thumb.png.c5b4a5ba7fd2a1cd6e35f3cd0c1ed235.png

Can you advise how to use this?

 

Link to comment
Share on other sites

mickle026
5 hours ago, Luke said:

I would still do what I suggested and use the path as the url. The core server will figure it out.

OK so i have done as suggested and Emby puts the image in Emby's people folder as an auto_poster and creates an nfo,
but my problem persists, it seems as if the db is locked ??

var tokenSource = new CancellationTokenSource();
var token = tokenSource.Token;
var libraryOptions = libraryManager.GetLibraryOptions(IAFDPersonData);
await providerManager.SaveImage(IAFDPersonData, libraryOptions, TempFile, ImageType.Primary, 0, true, token);

libraryManager.UpdateImages(IAFDPersonData);

The persons image thumbnail doesn't update.  and a re-entry of that person shows that the primary image doesn't exist in the db.
Its there on the disk, but Emby doesn't use it and the primary image path is back to being empty.

Its like its not saving to the db permanently <++ This is my problem

Capture.JPG.9140742e2d38218c6dd52623b3f45fc6.JPG

Capture3.thumb.JPG.767119723babeefe12d8cde3cea5a859.JPGCapture4.JPG.1dd793bd540f45599ff1ffa1f10e5960.JPG

 

After 1st run, image is acquired and set , Emby saves it to the People Folder as auto_poster and generates an nfo

 

Capture5.JPG.0bfcb43f7e44c5ad70c68c4072d1574f.JPG

 

When I exit the page and return, it runs again because there is no primary image path in the database.

Evenif I do this

var PersonImage = new PersonInfo { ImageUrl = IAFDPersonData.PrimaryImagePath };
var PersonList = new List<PersonInfo>();
PersonList.Add(PersonImage);
libraryManager.UpdatePeople(IAFDPersonData, PersonList, false);

The next page entry shows no primary image was saved.

 

So to update the image in the db I tried

this

libraryManager.UpdateImages(IAFDPersonData);

and this

var ImageList = new ItemImageInfo { Path = TempFile, Type = ImageType.Primary };
IAFDPersonData.SetImage(ImageList, 0);
libraryManager.UpdateImages(IAFDPersonData);

and this

libraryManager.UpdateItem(IAFDPersonData, IAFDPersonData, ItemUpdateType.ImageUpdate);

I do not have any errors in any logs

It seems as if the database could be locked ??? - commits don't seem to be happening.

Link to comment
Share on other sites

mickle026

Something odd is happening.

 

Restart Emby its still not updating.

Reboot the whole machine, start Emby - its working for a while and later stops again.

I will investigate further, something must be locking the database ...

Link to comment
Share on other sites

mickle026

OK, I think I found the issue and not sure how to proceed

The database wont update after it finds a person that has an invalid GUUID, as all the people are added the same way I have no idea why a few have invalid guuids.

26.Sep.2022  -  15.06.54 ------------------------------------------------------------------------------------
26.Sep.2022  -  15.06.54 Get Metadata or Refresh Metadata for Person Name: Keisha Grey
26.Sep.2022  -  15.06.54 Keisha Grey - Wait for results
26.Sep.2022  -  15.06.54 Person Stored ID (GUUID): 00000000-0000-0000-0000-000000000000 
26.Sep.2022  -  15.06.54 Keisha Grey Internal (Item) ID: 211704 
26.Sep.2022  -  15.07.00 ------------------------------------------------------------------------------------
26.Sep.2022  -  15.07.00 Get Metadata or Refresh Metadata for Person Name: Samantha Rone
26.Sep.2022  -  15.07.00 Samantha Rone - Wait for results
26.Sep.2022  -  15.07.00 Person Stored ID (GUUID): 7c64ad9f-fd07-4260-85f1-330aa9830b73 
26.Sep.2022  -  15.07.00 Samantha Rone Internal (Item) ID: 211754 
26.Sep.2022  -  15.07.00 Person BaseItem ID (GUUID): 7c64ad9f-fd07-4260-85f1-330aa9830b73 
26.Sep.2022  -  15.07.00 Current Person PrimaryImagePath:  
26.Sep.2022  -  15.07.03 Samantha Rone has no primary image, attempting to get one ..... 
26.Sep.2022  -  15.07.03 Samantha Rone has no Date Of Birth, attempting to get one ..... 
26.Sep.2022  -  15.07.06 Samantha Rone - Updated Primary image Path: C:\Users\mike\AppData\Roaming\Emby-Server\programdata\metadata\people\Samantha Rone\auto_poster.jpg
26.Sep.2022  -  15.07.06 Samantha Rone - Job Completed!
26.Sep.2022  -  15.07.17 ------------------------------------------------------------------------------------
26.Sep.2022  -  15.07.17 Get Metadata or Refresh Metadata for Person Name: Samantha Rone
26.Sep.2022  -  15.07.17 Samantha Rone - Wait for results
26.Sep.2022  -  15.07.17 Person Stored ID (GUUID): 7c64ad9f-fd07-4260-85f1-330aa9830b73 
26.Sep.2022  -  15.07.17 Samantha Rone Internal (Item) ID: 211754 
26.Sep.2022  -  15.07.17 Person BaseItem ID (GUUID): 7c64ad9f-fd07-4260-85f1-330aa9830b73 
26.Sep.2022  -  15.07.17 Current Person PrimaryImagePath:  
26.Sep.2022  -  15.07.20 Samantha Rone has no primary image, attempting to get one ..... 
26.Sep.2022  -  15.07.20 Samantha Rone has no Date Of Birth, attempting to get one ..... 
26.Sep.2022  -  15.07.22 Samantha Rone - Updated Primary image Path: C:\Users\mike\AppData\Roaming\Emby-Server\programdata\metadata\people\Samantha Rone\auto_poster.jpg
26.Sep.2022  -  15.07.22 Samantha Rone - Job Completed!

So after I looked at the top actress, the database stopped updating. (seems to be locked)

IAFDPersonData = libraryManager.GetItemById(IAFDPersonBaseItemID);

This is enought to cause it to lock. Im wondering if librarymanager gets stuck somehow, maybe just waiting for a response?

As i have to reboot, and not just restart emby, it must be sql that gets in this state.

If i reboot the machine and dont come across an invalid guuid, they all work.

 

I could do with a test for an invalid guuid and repair so that I can test this for validity and repair it before calling library manager.

 var IAFDPersonBaseItemID = IAFDPersonsBaseItem.Items[0].Item1.Id;

For now to prevent the lockup i am doing this

string GuidTest = libraryManager.GetGuid(IAFDPersonBaseItemInternalID).ToString();

if (GuidTest == "00000000-0000-0000-0000-000000000000")
{
   log.IAFDLogToMyFile(MyLog, DateTime.Now.ToString("dd.MMM.yyy  -  HH'.'mm'.'ss") + $" {info.Name} - has an invalid GUID, cannot continue ");
   log.IAFDLogToMyFile(MyLog, DateTime.Now.ToString("dd.MMM.yyy  -  HH'.'mm'.'ss") + $" {info.Name} - Remove and re-add this person to repair ");
   return;
}

 

Any advice on how to fix this issue internally?

 

Edited by mickle026
Link to comment
Share on other sites

mickle026

Well , it seems that update commit fails also happen when people have valid guids too ...... goodness me - i thought i had found the reason.

definately happens with an invalid guuid though.

Something else is also triggering it, its got to be.

Going to try removing the whole library, rescanning, re adding and rescanning, to see if that fixes it.

 

Edited by mickle026
Link to comment
Share on other sites

mickle026
4 hours ago, mickle026 said:

Well , it seems that update commit fails also happen when people have valid guids too ...... goodness me - i thought i had found the reason.

definately happens with an invalid guuid though.

Something else is also triggering it, its got to be.

Going to try removing the whole library, rescanning, re adding and rescanning, to see if that fixes it.

 

Removed the library, readded and rescanned, now everyone has valid guuids.

They still fail to update

 

Something is just plain weird

022-09-26 19:56:40.491 Debug App: Running IAFD_People for Dredd
2022-09-26 19:56:40.507 Debug SqliteItemRepository: GetInternalId from a1b669c1-1b4a-4cb6-9129-fe2c0b5da915
2022-09-26 19:57:06.107 Debug ProviderManager: Saving image to C:\Users\mike\AppData\Roaming\Emby-Server\programdata\metadata\people\Dredd\auto_poster.jpg
2022-09-26 19:57:06.119 Info ProviderManager: Deleting previous image C:\Users\mike\AppData\Roaming\Emby-Server\programdata\metadata\IAFD\a1\a1b669c1-1b4a-4cb6-9129-fe2c0b5da915\Dredd.jpg
2022-09-26 19:57:06.120 Debug SqliteItemRepository: Public GetItemLinks

This entry in Emby Logs with debug logging shows emby removing the old entry.

But no image was shown in Emby when you viewed the person or click them
No image was stored in PrimaryImagePath

No entries for SqliteItemRepository for any save or update methods in the log.

 

Its working inside a  Task method thats not waited.  What has waiting got to do with library updates?

Task.Run(() => IFADGetPersonNameData(info));

 

Edited by mickle026
Link to comment
Share on other sites

6 hours ago, mickle026 said:

Removed the library, readded and rescanned, now everyone has valid guuids.

They still fail to update

 

Something is just plain weird

022-09-26 19:56:40.491 Debug App: Running IAFD_People for Dredd
2022-09-26 19:56:40.507 Debug SqliteItemRepository: GetInternalId from a1b669c1-1b4a-4cb6-9129-fe2c0b5da915
2022-09-26 19:57:06.107 Debug ProviderManager: Saving image to C:\Users\mike\AppData\Roaming\Emby-Server\programdata\metadata\people\Dredd\auto_poster.jpg
2022-09-26 19:57:06.119 Info ProviderManager: Deleting previous image C:\Users\mike\AppData\Roaming\Emby-Server\programdata\metadata\IAFD\a1\a1b669c1-1b4a-4cb6-9129-fe2c0b5da915\Dredd.jpg
2022-09-26 19:57:06.120 Debug SqliteItemRepository: Public GetItemLinks

This entry in Emby Logs with debug logging shows emby removing the old entry.

But no image was shown in Emby when you viewed the person or click them
No image was stored in PrimaryImagePath

No entries for SqliteItemRepository for any save or update methods in the log.

 

Its working inside a  Task method thats not waited.  What has waiting got to do with library updates?

Task.Run(() => IFADGetPersonNameData(info));

 

You have to save the item to the database. The providermanager method doesn't do that for you, so you're probably missing that.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...