SageTV Community  

Go Back   SageTV Community > SageTV Development and Customizations > SageTV Studio
Forum Rules FAQs Community Downloads Today's Posts Search

Notices

SageTV Studio Discussion related to the SageTV Studio application produced by SageTV. Questions, issues, problems, suggestions, etc. relating to the Studio software application should be posted here.

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 02-17-2010, 03:41 PM
PLUCKYHD PLUCKYHD is offline
SageTVaholic
 
Join Date: Dec 2007
Posts: 6,257
Any well to tell when Sage Is importing new media?

I am wondering if there is an easy way to tell when Sage is scanning for new media (the period check it does be it 2 hours or whatever the setting). I would like to fire off a scan of my own when it is finished. If it is in the API I missed it I am sure

TIA
skye
Reply With Quote
  #2  
Old 02-17-2010, 04:11 PM
stuckless's Avatar
stuckless stuckless is offline
SageTVaholic
 
Join Date: Oct 2007
Location: London, Ontario, Canada
Posts: 9,713
Quote:
Originally Posted by PLUCKYHD View Post
I am wondering if there is an easy way to tell when Sage is scanning for new media (the period check it does be it 2 hours or whatever the setting). I would like to fire off a scan of my own when it is finished. If it is in the API I missed it I am sure

TIA
skye
PLUCKY, check out the mediafile_metadata_parser_plugins in the Sage.properties. It's what BMT uses to fetch metadata for the automatic plugin. It is called each time a new file is added to the sagetv library. It will be called when SageTV does does it's periodic refresh and it finds new files.

Be careful when you use this method because if you start calling MediaFileMetadata apis on this newly added file, then it may trigger sagetv to call your plugin again, and result in an endless loop. (bmt 3.0 had that issue)

Last edited by stuckless; 02-17-2010 at 04:14 PM.
Reply With Quote
  #3  
Old 02-17-2010, 04:15 PM
stanger89's Avatar
stanger89 stanger89 is offline
SageTVaholic
 
Join Date: May 2003
Location: Marion, IA
Posts: 15,188
Check the stock UI, it puts up an icon when a scan is going on.
Reply With Quote
  #4  
Old 02-17-2010, 04:52 PM
PLUCKYHD PLUCKYHD is offline
SageTVaholic
 
Join Date: Dec 2007
Posts: 6,257
Quote:
Originally Posted by stuckless View Post
PLUCKY, check out the mediafile_metadata_parser_plugins in the Sage.properties. It's what BMT uses to fetch metadata for the automatic plugin. It is called each time a new file is added to the sagetv library. It will be called when SageTV does does it's periodic refresh and it finds new files.

Be careful when you use this method because if you start calling MediaFileMetadata apis on this newly added file, then it may trigger sagetv to call your plugin again, and result in an endless loop. (bmt 3.0 had that issue)
I knew you would know because you did it with BMT.

I am not calling mediafilemetadata apis so I should be okay then.

Thanks will give this a look better than writing the route I was going and loaded a class at startup.
Reply With Quote
  #5  
Old 02-18-2010, 07:59 AM
PLUCKYHD PLUCKYHD is offline
SageTVaholic
 
Join Date: Dec 2007
Posts: 6,257
Hey Sean,

Having a issue here. Does it want a runnable clase like the load_atstartup does? It throws this error when trying to load

Code:
Error instantiating metadata parser plugin of:java.lang.ClassCastException: smm.LoadSMMWorker cannot be cast to sage.MediaFileMetadataParser
No sure what it means by cannot be cast to sage.MediaFileMetadataParser.
The wierd thing is is does show my logging like it is working after that error.

Also after checking not sure this is the way I want to go as it calls this class on every video file it is importing correct? I more or less just need to have mine call once after importing is finished.
Reply With Quote
  #6  
Old 02-18-2010, 08:42 AM
stuckless's Avatar
stuckless stuckless is offline
SageTVaholic
 
Join Date: Oct 2007
Location: London, Ontario, Canada
Posts: 9,713
Your class needs to implement the sage.MediaFileMetadataParser
Code:
public class LoadSMMWorker implements sage.MediaFileMetadataParser {
}
Reply With Quote
  #7  
Old 02-18-2010, 08:49 AM
stuckless's Avatar
stuckless stuckless is offline
SageTVaholic
 
Join Date: Oct 2007
Location: London, Ontario, Canada
Posts: 9,713
Quote:
Originally Posted by PLUCKYHD View Post
Also after checking not sure this is the way I want to go as it calls this class on every video file it is importing correct? I more or less just need to have mine call once after importing is finished.
Yeah, this is called for EVERY media file (videos, recordings, pictures and music). You'd have to use the file extension to determine if you wanted to handle this file or not.

For bmt, in 4.0, I allow the user to specify which file types they want to handle in the automatic metadata plugin.

This won't help you much today... but in phoenix, there is an EventBus, where developers can subscribe to certain events. Currently there is an event that is fired each time a new MediaFile is successfully added to the wiz.bin. I'm actually using this model in the automatic plugin. ie, I register an event handler for media and the automatic plugin simple fires the event that then later gets picked up by the event handlers. This allows me to background process the requests instead of having them block, like they do in 3.x.
Reply With Quote
  #8  
Old 02-18-2010, 09:16 AM
PLUCKYHD PLUCKYHD is offline
SageTVaholic
 
Join Date: Dec 2007
Posts: 6,257
Quote:
Originally Posted by stuckless View Post
Yeah, this is called for EVERY media file (videos, recordings, pictures and music). You'd have to use the file extension to determine if you wanted to handle this file or not.

For bmt, in 4.0, I allow the user to specify which file types they want to handle in the automatic metadata plugin.

This won't help you much today... but in phoenix, there is an EventBus, where developers can subscribe to certain events. Currently there is an event that is fired each time a new MediaFile is successfully added to the wiz.bin. I'm actually using this model in the automatic plugin. ie, I register an event handler for media and the automatic plugin simple fires the event that then later gets picked up by the event handlers. This allows me to background process the requests instead of having them block, like they do in 3.x.
Thanks for the teaser Sean . I think for now since I don't need it fired on every video file only once I will keep it running in the startup loadable classes and have it's own 2 hour (or user preferred time interval) for automatic scanning.

While I got your attention since that is the route I am going for now. It is my understanding that by using setDaemon(true) and making my thread a demon thread it will automatically be killed when the sage service stops. Also it is my understanding that it will automatically be started when the sage service starts regardless of when SageTV Ui instance starts. Is that correct? The reason I ask is because I see no logging happening when the sagetv service starts but do see the entry starting the thread when a instance of sagetv starts.

thanks again
Reply With Quote
  #9  
Old 02-18-2010, 09:34 AM
Opus4's Avatar
Opus4 Opus4 is offline
Administrator
 
Join Date: Sep 2003
Location: NJ
Posts: 19,624
Check out the MediaFilesImported hook. It provides a list of newly imported files too.

- Andy
__________________
SageTV Open Source v9 is available.
- Read the SageTV FAQ. Older PDF User's Guides mostly still apply: SageTV V7.0 & SageTV Studio v7.1.
- Hauppauge remote help: 1) Basics/Extending it 2) Replace it 3) Use it w/o needing focus
- HD Extenders: A) FAQs B) URC MX-700 remote setup
Note: This is a users' forum; see the Rules. For official tech support fill out a Support Request.
Reply With Quote
  #10  
Old 02-18-2010, 09:40 AM
PLUCKYHD PLUCKYHD is offline
SageTVaholic
 
Join Date: Dec 2007
Posts: 6,257
Quote:
Originally Posted by Opus4 View Post
Check out the MediaFilesImported hook. It provides a list of newly imported files too.

- Andy
Thanks Andy I think I want to stay out of the STV requirement for this thread but am I correct in my assumption above about startup runnable classes?

My simple thought there is start the thread and in run have a
Code:
while(true){

     try {
			Thread.sleep(amount of time to wait between scans);
		} catch (InterruptedException ex) {
			 System.out.println("daemonServer: sleep exception: " + ex);}
		
              
          Run my code}
Does that seem like a good simple way to achieve a rescan of my own database?
Reply With Quote
  #11  
Old 02-18-2010, 10:39 AM
stuckless's Avatar
stuckless stuckless is offline
SageTVaholic
 
Join Date: Oct 2007
Location: London, Ontario, Canada
Posts: 9,713
Quote:
Originally Posted by PLUCKYHD View Post
Thanks Andy I think I want to stay out of the STV requirement for this thread but am I correct in my assumption above about startup runnable classes?

My simple thought there is start the thread and in run have a
Code:
while(true){

     try {
			Thread.sleep(amount of time to wait between scans);
		} catch (InterruptedException ex) {
			 System.out.println("daemonServer: sleep exception: " + ex);}
		
              
          Run my code}
Does that seem like a good simple way to achieve a rescan of my own database?
Plucky, I'd avoid creating your own threads, if at all possible, unless you fully understand how to manage threads. ie, you need to manage the shut down of your thead, etc. Also, depending on what you thread is doing, it can have an impact on overall performance.

Any time you can leverage an existing hook instead of writing your own thread and thread monitoring, you'll be better off. ie, using the medailfe metadata parser plugin hook would be a better than managing your own thread, since sage is going to configure a directory scanning intervalue, etc. You don't want too many independant threads all doing file scans.

If you do ahead with your own thread, then be sure to research how to manage the shutdown of your thread... ie, while (true) is not good. Also research the InterruptedException, since you are expected to handle it correctly if you catch it.
Reply With Quote
  #12  
Old 02-18-2010, 10:51 AM
PLUCKYHD PLUCKYHD is offline
SageTVaholic
 
Join Date: Dec 2007
Posts: 6,257
Quote:
Originally Posted by stuckless View Post
Plucky, I'd avoid creating your own threads, if at all possible, unless you fully understand how to manage threads. ie, you need to manage the shut down of your thead, etc. Also, depending on what you thread is doing, it can have an impact on overall performance.

Any time you can leverage an existing hook instead of writing your own thread and thread monitoring, you'll be better off. ie, using the medailfe metadata parser plugin hook would be a better than managing your own thread, since sage is going to configure a directory scanning intervalue, etc. You don't want too many independant threads all doing file scans.

If you do ahead with your own thread, then be sure to research how to manage the shutdown of your thread... ie, while (true) is not good. Also research the InterruptedException, since you are expected to handle it correctly if you catch it.
I will admit I am still learning the thread thing. The problem with leveraging an existing hook is then the process is only done when the UI is open and that is not going to help me much. Also it was my understanding and I could have read wrong that with a daemon thread it was automatically shutdown when the JVM is ended (or sagetv service stopped in this case) and that is why I chose that route so I wouldn't have to worry about the thread staying open.

The problem with the mediafile parser class it that it would call my searching for every single video file when I only need it called once after finished not for every video file. (I am checking a sql database on this call nothing to do with sagedb just need it ran at a regular interval).

I am reading up on InterruptedException now seems simple to handle it.

Again my goal is also not to screw anything up and if I am still misunderstanding or going about this wrong please don't hesitate to let me know
Reply With Quote
  #13  
Old 02-18-2010, 11:04 AM
stuckless's Avatar
stuckless stuckless is offline
SageTVaholic
 
Join Date: Oct 2007
Location: London, Ontario, Canada
Posts: 9,713
If you create threads, then you can prevent the jvm from cleanly shutting down. ie, the jvm exits when all threads are exited. Sometimes this can be as simple as adding a shutdown hook that notifies your thread to exit.
Reply With Quote
  #14  
Old 02-18-2010, 11:06 AM
Fuzzy's Avatar
Fuzzy Fuzzy is offline
SageTVaholic
 
Join Date: Sep 2005
Location: Jurupa Valley, CA
Posts: 9,957
Is there a way you can sync up your sql database one record at a time? So sage finds a new file, and it then handles creating the data in your sql?
__________________
Buy Fuzzy a beer! (Fuzzy likes beer)

unRAID Server: i7-6700, 32GB RAM, Dual 128GB SSD cache and 13TB pool, with SageTVv9, openDCT, Logitech Media Server and Plex Media Server each in Dockers.
Sources: HRHR Prime with Charter CableCard. HDHR-US for OTA.
Primary Client: HD-300 through XBoxOne in Living Room, Samsung HLT-6189S
Other Clients: Mi Box in Master Bedroom, HD-200 in kids room
Reply With Quote
  #15  
Old 02-18-2010, 11:16 AM
PLUCKYHD PLUCKYHD is offline
SageTVaholic
 
Join Date: Dec 2007
Posts: 6,257
Quote:
Originally Posted by stuckless View Post
If you create threads, then you can prevent the jvm from cleanly shutting down. ie, the jvm exits when all threads are exited. Sometimes this can be as simple as adding a shutdown hook that notifies your thread to exit.
Okay that makes sense I can add a shutdown hook easily enough

Quote:
Originally Posted by Fuzzy View Post
Is there a way you can sync up your sql database one record at a time? So sage finds a new file, and it then handles creating the data in your sql?
The problem lies in that I am not just looking for new files but also updated metadata (Mymovies searches for updated metadata as well as new files) so searching them one a time wouldn't be ideal as it would leave out any changed files.) I know BMT touches the files to achieve change status but I am trying to avoid having to do that.

nothing is ever easy
Reply With Quote
  #16  
Old 02-18-2010, 12:39 PM
PLUCKYHD PLUCKYHD is offline
SageTVaholic
 
Join Date: Dec 2007
Posts: 6,257
Also should mention that I am not actually writing to the wiz.bin in this process so I guess that is why it doesn't make sense for me to do it per file.
Reply With Quote
  #17  
Old 02-19-2010, 07:04 AM
jphipps jphipps is offline
Sage Expert
 
Join Date: Aug 2006
Location: Maryland
Posts: 512
I use a background thread running in the server that waits on a serial blocking queue, and I use the metadata plugin call to drop an object onto the queue and process getting the metadata and inserting the data into the database in that background thread, so it doesn't hold up any of the normal sage processing...

Thanks,
Jeff
Reply With Quote
  #18  
Old 02-21-2010, 11:17 AM
stuckless's Avatar
stuckless stuckless is offline
SageTVaholic
 
Join Date: Oct 2007
Location: London, Ontario, Canada
Posts: 9,713
Plucky, something else to consider, rather than managing your own thread, is to use the java Timer and TimerTask. What you are trying to do, is basicly why these classes were added to the java standard library.

The simple use case is something like this...
Code:
TimerTask task = new TimerTask() {
    public void run() {
        /// check for new files, and add them to the database
    }
}

Timer timer = new Timer(true);
time.schedule(task, Calendar.getInstance().getTime(), (60*60*1000));
This basically will schedule your task to run every 1 hour (60*60*1000ms) until the jvm shuts down, but you don't have to manage the thread code, etc.

For more information on the Timer check out the javadoc.
Reply With Quote
  #19  
Old 02-21-2010, 11:51 AM
PLUCKYHD PLUCKYHD is offline
SageTVaholic
 
Join Date: Dec 2007
Posts: 6,257
Quote:
Originally Posted by stuckless View Post
Plucky, something else to consider, rather than managing your own thread, is to use the java Timer and TimerTask. What you are trying to do, is basicly why these classes were added to the java standard library.

The simple use case is something like this...
Code:
TimerTask task = new TimerTask() {
    public void run() {
        /// check for new files, and add them to the database
    }
}

Timer timer = new Timer(true);
time.schedule(task, Calendar.getInstance().getTime(), (60*60*1000));
This basically will schedule your task to run every 1 hour (60*60*1000ms) until the jvm shuts down, but you don't have to manage the thread code, etc.

For more information on the Timer check out the javadoc.
Thanks Sean I will read up on that from your example it looks a better route to go. I have been running my thread all weekend and starting and stopping it without any problems but your above post about using while(true) scared me a bit even though I am not seeing issues your proposal makes me feel better/safer and I will probably go that route. I am guessing the run thread would automatically kill itself after running since there is no looping?

Thanks again Sean for all your willingness to help me out when I need it.
Reply With Quote
  #20  
Old 02-21-2010, 11:55 AM
PLUCKYHD PLUCKYHD is offline
SageTVaholic
 
Join Date: Dec 2007
Posts: 6,257
This part of the java doc scares me a bit

"After the last live reference to a Timer object goes away and all outstanding tasks have completed execution, the timer's task execution thread terminates gracefully (and becomes subject to garbage collection). However, this can take arbitrarily long to occur. By default, the task execution thread does not run as a daemon thread, so it is capable of keeping an application from terminating. If a caller wants to terminate a timer's task execution thread rapidly, the caller should invoke the the timer's cancel method. "

I don't want my scanning to keep sage service from being able to shut down if it is in the process where as the deamon thread I am running now just gets killed regardless if it is in process or not. Of course it may be arbitrary because at max I don't see my process running more than 20seconds for a total rebuild....

Still reading
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Why do files still show up in Media Center when I'm not importing them anymore?!?! Chriscic SageTV Software 5 09-08-2008 11:57 AM
What is the process for importing media from PCs on network? sashimi SageTV Software 3 08-28-2008 07:12 PM
Importing media Mike SageTV Software 4 12-22-2006 04:43 PM
Importing Media Files mkriger SageTV Media Extender 2 06-02-2006 09:09 PM
Help importing media: does Sage even read the properties file? silkshadow SageTV Software 9 04-05-2006 10:47 AM


All times are GMT -6. The time now is 12:57 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2023, vBulletin Solutions Inc.
Copyright 2003-2005 SageTV, LLC. All rights reserved.