Jump to content


Photo

Dynamic folder content in channel plugin


  • Please log in to reply
27 replies to this topic

#1 ZR1000A1 OFFLINE  

ZR1000A1

    Member

  • Members
  • 15 posts
  • Local time: 12:41 PM

Posted 14 November 2019 - 11:59 AM

I'm working on a channel plugin that contains nested folders. I need to be able to update the content of a folder dynamically every time the folder is entered. Is it possible?

I've tried few things (based on examples and info I could find), but nothing works. Basically, I need

public Task<ChannelItemResult> GetChannelItems(InternalChannelItemQuery query, CancellationToken cancellationToken)

method to be called every time a user enters a folder.

 

I tried:

1. Implement

IHasCacheKey 
public string GetCacheKey(string userId)

method and return random string. Does not help. Actually, I don't even see (in the Debugger) that this method gets called at all.

 

2. Many examples shows a use of

ISupportsLatestMedia
Task<IEnumerable<ChannelItemInfo>> GetLatestMedia(ChannelLatestMediaSearch request, CancellationToken cancellationToken)

but the interface does not have this method anymore and I couldn't find definition of ChannelLatestMediaSearch anywhere. But, that's probably irrelevant to my issue anyway...

 

As there is absolutely no objects/interfaces documentations, I'd like to know if there is any way to have a folder content updated every time the folder is entered?

 

Thanks


Edited by ZR1000A1, 14 November 2019 - 12:29 PM.


#2 Luke OFFLINE  

Luke

    System Architect

  • Administrators
  • 142518 posts
  • Local time: 12:41 PM

Posted 14 November 2019 - 12:59 PM

Hi, it's no longer possible. Channel contents are updated in a background process now. This prevents stalling the UI due to channels responding slowly, and it also allows integration with all Emby features by having the content available in the database.



#3 ZR1000A1 OFFLINE  

ZR1000A1

    Member

  • Members
  • 15 posts
  • Local time: 12:41 PM

Posted 14 November 2019 - 01:09 PM

Thanks for the quick reply.

Unfortunately, that makes the plugin I was going to implement totally useless. So, no reason to waste any more time... :( :( :( :(



#4 Luke OFFLINE  

Luke

    System Architect

  • Administrators
  • 142518 posts
  • Local time: 12:41 PM

Posted 14 November 2019 - 01:12 PM

A 3-6 hour refresh interval is not sufficient?



#5 ZR1000A1 OFFLINE  

ZR1000A1

    Member

  • Members
  • 15 posts
  • Local time: 12:41 PM

Posted 14 November 2019 - 01:40 PM

Unfortunately, not. The content is changing dynamically and the streams may or may not be available at the time. The idea was to make HTTP request to a server and based on its response populate folders and create media items.

Yes, it may slow down UI and I agree that it should not be the default behavior. But, it would be nice feature to have allowing a plugin to provide items update via callback



#6 pünktchen ONLINE  

pünktchen

    Advanced Member

  • Members
  • 2260 posts
  • Local time: 06:41 PM

Posted 15 November 2019 - 03:10 AM

Look at one of the live tv plugins. They have a "ContentChanged" event in their recording channel. Maybe you can call this event every time a user enters a subfolder category.

#7 Luke OFFLINE  

Luke

    System Architect

  • Administrators
  • 142518 posts
  • Local time: 12:41 PM

Posted 15 November 2019 - 03:37 AM

Oh yes didn't think of that.

#8 ZR1000A1 OFFLINE  

ZR1000A1

    Member

  • Members
  • 15 posts
  • Local time: 12:41 PM

Posted 15 November 2019 - 03:08 PM

Look at one of the live tv plugins. They have a "ContentChanged" event in their recording channel. Maybe you can call this event every time a user enters a subfolder category.

 

Thank you. I've looked at DVBViewerTVPlugin plugin (https://github.com/M...rdingChannel.cs). The "ContentChanged" event is called on timer there. Do you know how I can call it when a user enters a subfolder? How does the  channel know (what method/event is called in the channel) when a user enters a subfolder?


Edited by ZR1000A1, 15 November 2019 - 03:09 PM.


#9 Luke OFFLINE  

Luke

    System Architect

  • Administrators
  • 142518 posts
  • Local time: 12:41 PM

Posted 15 November 2019 - 03:22 PM

 

How does the  channel know (what method/event is called in the channel) when a user enters a subfolder?

 

 

There's no way to know this. The best you could do is trigger it really often, like every minute or so.



#10 ZR1000A1 OFFLINE  

ZR1000A1

    Member

  • Members
  • 15 posts
  • Local time: 12:41 PM

Posted 18 November 2019 - 10:58 AM

There's no way to know this. The best you could do is trigger it really often, like every minute or so.

 

Thanks!

One more question. The channel implements:

IRequiresMediaInfoCallback
public async Task<IEnumerable<MediaSourceInfo>> GetChannelItemMediaInfo(string id, CancellationToken cancellationToken)

But, the method gets called only once. As soon as it returns MediaInfo, the server does not call this method again.

Is it possible to force the server to call the method every time a user selects the media item?



#11 Luke OFFLINE  

Luke

    System Architect

  • Administrators
  • 142518 posts
  • Local time: 12:41 PM

Posted 18 November 2019 - 11:29 AM

Did you try playing it?

#12 ZR1000A1 OFFLINE  

ZR1000A1

    Member

  • Members
  • 15 posts
  • Local time: 12:41 PM

Posted 18 November 2019 - 12:01 PM

Did you try playing it?

 

Yes.

The channel creates a media type item (without media info). When a user selects the item, GetChannelItemMediaInfo() gets called, it returns media info and plays a stream fine. But if the play stops and the user selects the same item again, the server does not call GetChannelItemMediaInfo() anymore (does it cache media info???).

In my case the underlying media info path (stream URL) can be changed over time and I'd like GetChannelItemMediaInfo() to be called every time the user plays the item, so I can provide an up-to-date URL. Is it possible?

 

UPDATE:

After farther testing it appears that the server does call GetChannelItemMediaInfo() again, but only if the item is selected to play after a few minutes of being stopped. It's good enough for me, but I'd like to know what causes the delay and whether it's configurable?


Edited by ZR1000A1, 18 November 2019 - 01:06 PM.


#13 Luke OFFLINE  

Luke

    System Architect

  • Administrators
  • 142518 posts
  • Local time: 12:41 PM

Posted 18 November 2019 - 01:21 PM

It's something that can be reviewed in the future. Thanks.

#14 ZR1000A1 OFFLINE  

ZR1000A1

    Member

  • Members
  • 15 posts
  • Local time: 12:41 PM

Posted 18 November 2019 - 01:31 PM

Thanks Luke!

BTW, is there any way to display a custom error message to a user in cases when a stream failed to play?



#15 Luke OFFLINE  

Luke

    System Architect

  • Administrators
  • 142518 posts
  • Local time: 12:41 PM

Posted 18 November 2019 - 01:32 PM

It's not currently possible. Thanks.

#16 ZR1000A1 OFFLINE  

ZR1000A1

    Member

  • Members
  • 15 posts
  • Local time: 12:41 PM

Posted 21 November 2019 - 01:25 AM

When I install my plugin on Linux (Ubuntu 18.40) and new items are added, I see a lot of the same errors in the log (but the plugin still seems to work fine):

2019-11-21 00:00:33.739 Error BaseItem: Error refreshing item
	*** Error Report ***
	Version: 4.2.1.0
	Command line: /opt/emby-server/system/EmbyServer.dll -programdata /var/lib/emby -ffdetect /opt/emby-server/bin/ffdetect -ffmpeg /opt/emby-server/bin/ffmpeg -ffprobe /opt/emby-server/bin/ffprobe -restartexitcode 3 -updatepackage emby-server-deb_{version}_amd64.deb
	Operating system: Unix 4.15.0.58
	64-Bit OS: True
	64-Bit Process: True
	User Interactive: True
	Runtime: file:///opt/emby-server/system/System.Private.CoreLib.dll
	Processor count: 4
	Program data path: /var/lib/emby
	Application directory: /opt/emby-server/system
	System.NullReferenceException: System.NullReferenceException: Object reference not set to an instance of an object.
	   at Emby.Server.Implementations.IO.SharpCifsFileSystem.IsEnabledForPath(String path)
	   at Emby.Server.Implementations.IO.ManagedFileSystem.GetDirectoryName(String path)
	   at MediaBrowser.Controller.Entities.Video.get_ContainingFolderPath()
	   at MediaBrowser.Controller.Entities.Movies.Movie.BeforeMetadataRefresh(Boolean replaceAllMetdata)
	   at MediaBrowser.Providers.Manager.MetadataService`2.RefreshMetadata(BaseItem item, MetadataRefreshOptions refreshOptions, CancellationToken cancellationToken)
	   at MediaBrowser.Controller.Entities.BaseItem.RefreshMetadata(MetadataRefreshOptions options, CancellationToken cancellationToken)
	   at MediaBrowser.Controller.Entities.Folder.RefreshMetadataRecursive(BaseItem[] children, MetadataRefreshOptions refreshOptions, Boolean recursive, IProgress`1 progress, CancellationToken cancellationToken)
	Source: Emby.Server.Implementations
	TargetSite: Boolean IsEnabledForPath(System.String)

That doesn't happen on Windows server (no errors in the log)

Any idea what can cause the exception on Linux?



#17 ZR1000A1 OFFLINE  

ZR1000A1

    Member

  • Members
  • 15 posts
  • Local time: 12:41 PM

Posted 21 November 2019 - 12:13 PM

UPDATE:

After farther investigation, it looks like deletion of an item (not addition) causes the error above. Just before the error, there are these lines in the log:

2019-11-21 03:26:24.063 Info App: Removing item from database, Type: Movie, Name: 720p, Path: , Id: 13434
2019-11-21 03:26:24.063 Info App: Deleting path /data/embymetadata/metadata/library/95/95601cbdc28d4110ac614d09bcbaf6b5
2019-11-21 03:26:24.064 Info App: Removing item from database, Type: Movie, Name: 720p 60fps, Path: , Id: 13435
2019-11-21 03:26:24.064 Info App: Deleting path /data/embymetadata/metadata/library/22/227e3ff5ff7947c0bbaece7ef2dd5139
2019-11-21 03:26:24.066 Info App: Removing item from database, Type: Movie, Name: 504p, Path: , Id: 13436
2019-11-21 03:26:24.066 Info App: Deleting path /data/embymetadata/metadata/library/70/70e6b06ca8194095823787c3e767631c
2019-11-21 03:26:24.067 Info App: Removing item from database, Type: Movie, Name: 216p, Path: , Id: 13437
2019-11-21 03:26:24.067 Info App: Deleting path /data/embymetadata/metadata/library/fd/fd31c7d2b6154a5aa244ce50029becf9
2019-11-21 03:26:24.068 Info App: Removing item from database, Type: Movie, Name: 288p, Path: , Id: 13438
2019-11-21 03:26:24.068 Info App: Deleting path /data/embymetadata/metadata/library/86/86a2f22577a24367a9c45332b5c1dcd9
2019-11-21 03:26:24.069 Info App: Removing item from database, Type: Movie, Name: 360p, Path: , Id: 13439
2019-11-21 03:26:24.069 Info App: Deleting path /data/embymetadata/metadata/library/25/252464a04608413a8d829319daf697d3
2019-11-21 03:26:24.070 Info App: Removing item from database, Type: Movie, Name: 540p, Path: , Id: 13440
2019-11-21 03:26:24.070 Info App: Deleting path /data/embymetadata/metadata/library/a5/a599fcc4f6d547e992304ae731e03164
2019-11-21 03:26:24.072 Info App: Removing item from database, Type: Movie, Name: 720p, Path: , Id: 13441
2019-11-21 03:26:24.072 Info App: Deleting path /data/embymetadata/metadata/library/38/3894c8899b2d473499235ee9da7e5b94
2019-11-21 03:26:24.073 Info App: Removing item from database, Type: Movie, Name: 720p 60fps, Path: , Id: 13442
2019-11-21 03:26:24.073 Info App: Deleting path /data/embymetadata/metadata/library/5f/5f14fdec0d1b4acb8341582a0c9e7840

Some paths, like "/data/embymetadata/metadata/library/5f/", don't actually exist.

Is it a bug in the server?



#18 ZR1000A1 OFFLINE  

ZR1000A1

    Member

  • Members
  • 15 posts
  • Local time: 12:41 PM

Posted 21 November 2019 - 09:57 PM

Another weird thing. When item ID contains '+' (plus sign), like AAAA|BBBB|CCC+|DDDD (I use '|' as a separator), the server fails to play this item! The error is:

2019-11-21 19:08:31.177 Error HttpServer: Error processing request
	*** Error Report ***
	Version: 4.2.1.0
	Command line: /opt/emby-server/system/EmbyServer.dll -programdata /var/lib/emby -ffdetect /opt/emby-server/bin/ffdetect -ffmpeg /opt/emby-server/bin/ffmpeg -ffprobe /opt/emby-server/bin/ffprobe -restartexitcode 3 -updatepackage emby-server-deb_{version}_amd64.deb
	Operating system: Unix 4.15.0.58
	64-Bit OS: True
	64-Bit Process: True
	User Interactive: True
	Runtime: file:///opt/emby-server/system/System.Private.CoreLib.dll
	Processor count: 4
	Program data path: /var/lib/emby
	Application directory: /opt/emby-server/system
	System.ArgumentNullException: System.ArgumentNullException: Value cannot be null.
	Parameter name: mediaSource
	   at Emby.Server.MediaEncoding.Encoder.EncodingHelper.AttachMediaSourceInfo(EncodingJobInfo state, MediaSourceInfo mediaSource, String requestedUrl)
	   at Emby.Server.MediaEncoding.Api.BaseStreamingService.GetState(StreamRequest request, Boolean requiresOutputPath, CancellationToken cancellationToken)
	   at Emby.Server.MediaEncoding.Api.Hls.DynamicHlsService.GetMasterPlaylistInternal(StreamRequest request, String method)
	   at Emby.Server.Implementations.Services.ServiceController.GetTaskResult(Task task)
	   at Emby.Server.Implementations.Services.ServiceHandler.ProcessRequestAsync(HttpListenerHost appHost, IRequest httpReq, IResponse httpRes, RestPath restPath, String responseContentType, CancellationToken cancellationToken)
	   at Emby.Server.Implementations.HttpServer.HttpListenerHost.RequestHandler(IRequest httpReq, ReadOnlyMemory`1 urlString, ReadOnlyMemory`1 host, ReadOnlyMemory`1 localPath, CancellationToken cancellationToken)
	Source: Emby.Server.MediaEncoding
	TargetSite: Void AttachMediaSourceInfo(Emby.Server.MediaEncoding.Encoder.EncodingJobInfo, MediaBrowser.Model.Dto.MediaSourceInfo, System.String)

As soon as I replace '+' with '_', the item plays fine.

It would be really helpful to know any other restrictions in item's ID...

Thanks



#19 Luke OFFLINE  

Luke

    System Architect

  • Administrators
  • 142518 posts
  • Local time: 12:41 PM

Posted 22 November 2019 - 12:47 PM

Yea avoid | as the server will also add that and sometimes try to split the Id, so it's not expecting your id will have that.



#20 ZR1000A1 OFFLINE  

ZR1000A1

    Member

  • Members
  • 15 posts
  • Local time: 12:41 PM

Posted 23 November 2019 - 04:43 PM

Yea avoid | as the server will also add that and sometimes try to split the Id, so it's not expecting your id will have that.

Thanks!

What character would you recommend to use as a spliter?

 

One more question. Is it possible for a channel to provide a default folder's sorting criteria (field, like item name, create date, etc. and order - ascending/descending), or it's completely upto a client?


Edited by ZR1000A1, 23 November 2019 - 04:44 PM.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users