SageTV Community  

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

Notices

SageTV v9 Customizations This forums is for discussing and sharing user-created modifications for the SageTV version 9 application created by using the SageTV Studio or through the use of external plugins. Use this forum to discuss plugins for SageTV version 9 and newer.

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 12-27-2017, 09:56 AM
TwistedMelon TwistedMelon is offline
Sage Expert
 
Join Date: Aug 2005
Location: Ontario, Canada
Posts: 554
Automatically move specific favorite after each recording finishes

I started down the SJQ path but can't seem to locate the sample scripts for moving recordings.

Can anyone help with setting up SJQ and scripting recording file moves or suggest an alternative if there's some other better tool. Sage/Server is running Windows 7 at the moment.

Goal: Move files for a couple of favorites from the general recording paths into a special folder, while retaining the ability for Sage's favorite settings to see/work with the files.

I don't care if all files are moved to one specific folder on one specific drive or if I create one special folder per recording drive (faster for the file move) - but the latter is preferred is possible.

Example: favorite set to keep at most 5 episodes, need Sage to continue deleting old episodes as new ones are recorded.

The reason for the whole move operation: I've let Plex see my Sage recording folder and it's working well enough. I've recently set up a remote Plex system for my mom and thought it'd be nice to record a few shows specifically for her - which I don't want cluttering up my own experience. Moving the recordings to another folder and setting up a Plex library specifically for that folder only for her account seems like the cleanest approach. I don't mind having those shows in Sage's own recording UI.
__________________
Bruno
Twisted Melon Inc.
While you're clicking, check out my Mini Theater custom build.
Reply With Quote
  #2  
Old 12-27-2017, 11:24 AM
wayner wayner is offline
SageTVaholic
 
Join Date: Jan 2008
Location: Toronto, ON
Posts: 7,491
I built a process years ago to use Handbrake to convert Kids' shows from MPEG or TS files to MP4 files and save in a folder based off of the show name.

In other words a recording of Dora the Explorer in the TV Recording folder would move to \\servername\videos\Kids' Shows\Dora the Explorer and it would retain the same filename as it had initially. Is that what you are looking for?

I could change this process to simply move files instead. Is that what you are looking for?
__________________
New Server - Sage9 on unRAID 2xHD-PVR, HDHR for OTA
Old Server - Sage7 on Win7Pro-i660CPU with 4.6TB, HD-PVR, HDHR OTA, HVR-1850 OTA
Clients - 2xHD-300, 8xHD-200 Extenders, Client+2xPlaceshifter and a WHS which acts as a backup Sage server
Reply With Quote
  #3  
Old 12-27-2017, 11:34 AM
TwistedMelon TwistedMelon is offline
Sage Expert
 
Join Date: Aug 2005
Location: Ontario, Canada
Posts: 554
That's exactly what I'm looking for.

If it's possible to reference the target folder from the root of the volume the file is currently on, that would be ideal as then the move would be instant.

For example: all my recording folders are titled "SageTV" in the root of three drives on the Windows system. I'd love to be able to set up a target folder next to the SageTV folder on each drive instead of moving all the files to one single drive/volume. So the move would be to (parent/target) like "..\target\"

If the above isn't as easy, then all to one volume will also work.
__________________
Bruno
Twisted Melon Inc.
While you're clicking, check out my Mini Theater custom build.
Reply With Quote
  #4  
Old 12-27-2017, 11:41 AM
wayner wayner is offline
SageTVaholic
 
Join Date: Jan 2008
Location: Toronto, ON
Posts: 7,491
Actually I found one of Slugger's files that, I think, does what you want. It is called mv_show_folder.groovy

Code:
/******************************************************************************
     Move a SageTV Media File to a Folder based on the show name

     Last Modified: 02 Jan 2012
            Author: Derek Battams <derek AT battams DOT ca>
					Modified by wayner to move to Show Name folder

    Use this groovy script to move a SageTV media file object from one location
    to another.  The location is the BaseDirectory + the Show Tile
	some of the show title is Seinfeld and the Base Directory is \server1\TV Shows
    then the destination directory is \server1\TV Shows\Seinfeld\.
	Note that you have to use double slashes due to Groovy/Java
	
    The media file to be moved is defined by the SJQ4_ID environment variable;
    the SJQ4_TYPE variable must also be "MediaFile".  The destination is given
    as the first command line argument to this script.  The destination is a 
    directory.
	
	Note that after moving all of your files you should perform a rescan in Sage.
	I have removed that from Slugger's original script since I wanted to run this
	many times before doing a rescan.

******************************************************************************/

boolean testMode = false; // Don't actually move any files, just print out what would be done

// Uncomment and fill in these vars to run this script outside of SJQ
//def SJQ4_METADATA = ["SJQ4_TYPE":"MediaFile", "SJQ4_ID":"74420011"];
//def SJQ4_ARGS = ["\\\\nas\\tv"];

/******************* DO NOT EDIT BELOW THIS LINE ************************/

// But if you do then send me your bug fix patches! ;)

import org.apache.commons.io.FileUtils;
import static groovy.io.FileType.*;
import com.google.code.sagetvaddons.sjq.network.ServerClient;

String type = SJQ4_METADATA.get("SJQ4_TYPE");
String id   = SJQ4_METADATA.get("SJQ4_ID");

//Enter your base directory here:
String BaseDirectory = "\\\\Carnoustie\\Videos\\Isabella's Shows\\";

Object mediaFile = MediaFileAPI.GetMediaFileForID(id.toInteger());
String ShowName= MediaFileAPI.GetMediaTitle(mediaFile);
ShowName = (ShowName =~ /[?*\\\\/:<>|]/).replaceAll("")
println("Show ShowName is: "+ShowName);
File dest   = new File(BaseDirectory+ShowName);
println("Dest is: "+BaseDirectory+ShowName);

if(!dest.isDirectory() && !dest.mkdirs()) {
    println("Destination directory is invalid! [" + dest.getAbsolutePath() + "]");
    return 1;
}

if(!"MediaFile".equals(type) || id == null || !id.matches("\\d+")) {
    println("No media file attributes provided!");
    return 1;
}

if(mediaFile == null) {
    println("No media file for id " + id);
    return 1;
}
MediaFileAPI.SetMediaFileMetadata(mediaFile, "SJQ4_ARCHIVED", null);

if(MediaFileAPI.GetNumberOfSegments(mediaFile) == 0) {
    println("Zero file segments for media file; nothing to move!");
    return 1;
}

println("Moving " + Arrays.toString(MediaFileAPI.GetSegmentFiles(mediaFile)) + " to destination: " + dest.getAbsolutePath());
// Copy all segments then delete the originals if more than one segment otherwise just do a filesystem move op
if(MediaFileAPI.GetNumberOfSegments(mediaFile) == 1) {
    try {
        if(!testMode)
            FileUtils.moveFileToDirectory(MediaFileAPI.GetFileForSegment(mediaFile, 0), dest, false);
        else
            println("Would move: " + MediaFileAPI.GetFileForSegment(mediaFile, 0));
    } catch(IOException e) {
        println("Failed to move file to destination!");
        e.printStackTrace();
        return 1;
    }
} else {
    def copied = [];
    // Copy the files to their new home
    for(File segment : MediaFileAPI.GetSegmentFiles(MediaFileAPI.GetMediaFileForID(id.toInteger()))) {
        try {
            if(!testMode) {
                FileUtils.copyFileToDirectory(segment, dest, true);
                copied.add(new File(dest, segment.getName()));
                println("\tCopy of '" + segment.getAbsolutePath() + "' completed...");
            } else {
                println("\tWould move: " + segment.getAbsolutePath());
            }
        } catch(IOException e) {
            println("Error copying segment '" + segment.getAbsolutePath() + "' to destination!");
            e.printStackTrace();
            copied.each {
                if(!it.delete())
                    println("Failed to delete '" + it.getAbsolutePath() + "'");
            }
            return 1;
        }
    }
}

println("Moving artifacts...");
mvArtifacts(id.toInteger(), dest, testMode);

return 0;

def mvArtifacts(int mfId, File dest, boolean testMode) {
    for(File segment : MediaFileAPI.GetSegmentFiles(MediaFileAPI.GetMediaFileForID(mfId))) {
        String prefix = segment.getName().substring(0, segment.getName().lastIndexOf('.'));
        File baseDir = new File(segment.getParent());
        baseDir.eachFileMatch FILES, {!new File(baseDir, it.toString()).equals(segment) &&  it.toString().startsWith(prefix)}, {
            File artifact = new File(baseDir, it.getName());
            if(!testMode) {
                FileUtils.moveFileToDirectory artifact, dest, false;
            } else
                println("Would move artifact: " + artifact.getAbsolutePath());
        }
    }
}
__________________
New Server - Sage9 on unRAID 2xHD-PVR, HDHR for OTA
Old Server - Sage7 on Win7Pro-i660CPU with 4.6TB, HD-PVR, HDHR OTA, HVR-1850 OTA
Clients - 2xHD-300, 8xHD-200 Extenders, Client+2xPlaceshifter and a WHS which acts as a backup Sage server
Reply With Quote
  #5  
Old 12-27-2017, 11:48 AM
TwistedMelon TwistedMelon is offline
Sage Expert
 
Join Date: Aug 2005
Location: Ontario, Canada
Posts: 554
How do I install the script and configure it for specific shows? I get that SJQ4_ID identifies the show to operate on, but where is this defined and how is it passed to this script?

I've installed SJQ from the plugins menu but have never used it before.
__________________
Bruno
Twisted Melon Inc.
While you're clicking, check out my Mini Theater custom build.
Reply With Quote
  #6  
Old 12-27-2017, 11:54 AM
wayner wayner is offline
SageTVaholic
 
Join Date: Jan 2008
Location: Toronto, ON
Posts: 7,491
Do you know if SJQ is working in your system? If it is and is properly configured then you should see an entry for SJQ on your Setup menu. This may require an additional plugin.

On my System I have three SJQ plugins installed. SJQ, SJQ UI and SJQ Agent (Task Client). Once the SJQ UI is installed you should see the item on your setup menu. First you have to make sure that you have a client running, then you have to Create Tasks for the client.

Do you have all three plugins installed? There should be links to the User Guide that are from within the last year or so. The original guides are gone but I asked Slugger to move them to a new website so you should see the instructions, although the screenshots may be broken.
__________________
New Server - Sage9 on unRAID 2xHD-PVR, HDHR for OTA
Old Server - Sage7 on Win7Pro-i660CPU with 4.6TB, HD-PVR, HDHR OTA, HVR-1850 OTA
Clients - 2xHD-300, 8xHD-200 Extenders, Client+2xPlaceshifter and a WHS which acts as a backup Sage server
Reply With Quote
  #7  
Old 12-27-2017, 12:18 PM
TwistedMelon TwistedMelon is offline
Sage Expert
 
Join Date: Aug 2005
Location: Ontario, Canada
Posts: 554
All three installed now - I was missing the UI component as I didn't know it existed (wasn't along side the other two).

After reloading the UI, where is the menu item supposed to appear? Didn't notice it in any of the sub-menus of detailed setup.

I can open SJQ's timing preferences from the Installed Plugins list, but that's clearly not it.

So in summary, I have only done the following: installed the three plugins and reloaded the UI.

Going to look for the instructions link from the plugin details page.
__________________
Bruno
Twisted Melon Inc.
While you're clicking, check out my Mini Theater custom build.
Reply With Quote
  #8  
Old 12-27-2017, 12:31 PM
TwistedMelon TwistedMelon is offline
Sage Expert
 
Join Date: Aug 2005
Location: Ontario, Canada
Posts: 554
Found a copy of the user guide here: https://sourceforge.net/p/tmiranda-s...UserInterface/

And it looks like I need to do some as-yet unknown maintenance to get SJQ to show up. It's supposed to appear directly under Setup (Setup -> Sage Job Queue (SJQ)), but it's no on my system. I'm using some UI mods though -> MBDiamond and ADM to customize the menus.

Don't know where to start looking yet, but I have to pause this for a day or so or my wife's going to kill me - company will be over in about 30 minutes.
__________________
Bruno
Twisted Melon Inc.
While you're clicking, check out my Mini Theater custom build.
Reply With Quote
  #9  
Old 12-27-2017, 12:45 PM
KarylFStein KarylFStein is offline
Sage Fanatic
 
Join Date: Apr 2006
Location: Westland, Michigan, USA
Posts: 999
Quote:
Originally Posted by TwistedMelon View Post
Found a copy of the user guide here: https://sourceforge.net/p/tmiranda-s...UserInterface/

And it looks like I need to do some as-yet unknown maintenance to get SJQ to show up. It's supposed to appear directly under Setup (Setup -> Sage Job Queue (SJQ)), but it's no on my system. I'm using some UI mods though -> MBDiamond and ADM to customize the menus.

Don't know where to start looking yet, but I have to pause this for a day or so or my wife's going to kill me - company will be over in about 30 minutes.
If you're using ADM you'll have to add the item. It's been a while since I used that, but think that there's a "Copy" action you can do to pull the SJQ option into your menu.
__________________
Home Network: https://karylstein.com/technology.html
Reply With Quote
  #10  
Old 12-27-2017, 12:58 PM
wayner wayner is offline
SageTVaholic
 
Join Date: Jan 2008
Location: Toronto, ON
Posts: 7,491
Or are you using Gemstone? Temporarily switch back to the default SageTV UI. Or do the compy menu item that Karyl mentions. I can't remember how to do that but jusjoken would be able to tell you.
__________________
New Server - Sage9 on unRAID 2xHD-PVR, HDHR for OTA
Old Server - Sage7 on Win7Pro-i660CPU with 4.6TB, HD-PVR, HDHR OTA, HVR-1850 OTA
Clients - 2xHD-300, 8xHD-200 Extenders, Client+2xPlaceshifter and a WHS which acts as a backup Sage server
Reply With Quote
  #11  
Old 12-27-2017, 01:32 PM
TwistedMelon TwistedMelon is offline
Sage Expert
 
Join Date: Aug 2005
Location: Ontario, Canada
Posts: 554
No, just MBDiamond on top of v7 STV in Sage9 with ADM to disable a lot of menus/items.

Have just a few minutes to spare...

Enabled ADM's "Copy Mode" and I can see SJQ in the Settings Menu - but I have no idea how to copy it to my menu structure so it stay in place after turning off copy mode. It doesn't appear inside ADM's configuration structure and I don't see any copy action if it I could see what to copy.

This is enough to get me started though, now I can reference the user guide to figure out how to install and activate the script.
__________________
Bruno
Twisted Melon Inc.
While you're clicking, check out my Mini Theater custom build.

Last edited by TwistedMelon; 12-27-2017 at 01:34 PM.
Reply With Quote
  #12  
Old 12-28-2017, 08:44 AM
TwistedMelon TwistedMelon is offline
Sage Expert
 
Join Date: Aug 2005
Location: Ontario, Canada
Posts: 554
Just looking at this now and thankfully found this image from wayner



I'll report back soon with results - I suspect I might have to create a dummy instance of the trigger on some other show I already have recorded to test this. I've also modified the script to try and reference the destination path based on the current path using ".." for parent and removed the show name folder.
__________________
Bruno
Twisted Melon Inc.
While you're clicking, check out my Mini Theater custom build.

Last edited by TwistedMelon; 12-28-2017 at 08:50 AM.
Reply With Quote
  #13  
Old 12-28-2017, 09:15 AM
TwistedMelon TwistedMelon is offline
Sage Expert
 
Join Date: Aug 2005
Location: Ontario, Canada
Posts: 554
Tried it on an existing recording via Recording List and it produced a fail. No log output - does that mean the script was never run?

As in the screenshot, I used forward slashes on the path for the script - should this be backslashes on Windows system? I don't know if Sage cares about that.


EDIT:

Found an issue with the script path that was preventing it from launching (bad filename). I've been editing using the Android Mini Client and noticed that after typing a PERIOD, the next letter entered will always be preceded with a space, so the file extension was coming up ". groovy" and there's apparently no way to edit/fix it. Now I'm editing directly on the server's Sage instance via remote desktop and after correcting the path it's working!

Right now I've set recordings to be moved to one specific volume/folder and it's working as expected, with the need to do a manual library rescan as mentioned in the script.


TODO:

The base path for SJQ scripts seems to be the SageTV installation folder - I need to get the current recording folder or the root of the recording folder path (drive letter or UNC volume) so that I can ideally have the recordings moved (re-linked) without copying to a different volume

Can anyone help in extracting the current drive letter or recording folder path from the AbsolutePath of the recording being worked on?

I also need to clear the archive flag for the moved recordings so that the "keep only" favorite option can delete older episodes as necessary. I also need to fire off a rescan - this can be after every recording since there's nothing else in the import paths.
__________________
Bruno
Twisted Melon Inc.
While you're clicking, check out my Mini Theater custom build.

Last edited by TwistedMelon; 12-28-2017 at 10:26 AM.
Reply With Quote
  #14  
Old 12-28-2017, 09:33 AM
wayner wayner is offline
SageTVaholic
 
Join Date: Jan 2008
Location: Toronto, ON
Posts: 7,491
On my Win systems I have forward slashes as well - it looks exactly like the screenshot.

With no log entry that likely means it wasn't run. Were both logs blank? There is a test log and a task log. I access the logs via the web UI as there is a way to add SJQ menu items to the Web UI so that you can see and do most of the SJQ work from there.

You may also want to check the actual log test files in your Sage directory - it should be something like /plugins/sjq/sjq.log
__________________
New Server - Sage9 on unRAID 2xHD-PVR, HDHR for OTA
Old Server - Sage7 on Win7Pro-i660CPU with 4.6TB, HD-PVR, HDHR OTA, HVR-1850 OTA
Clients - 2xHD-300, 8xHD-200 Extenders, Client+2xPlaceshifter and a WHS which acts as a backup Sage server
Reply With Quote
  #15  
Old 12-28-2017, 10:47 AM
TwistedMelon TwistedMelon is offline
Sage Expert
 
Join Date: Aug 2005
Location: Ontario, Canada
Posts: 554
It seems to be working now as expected, at least in testing on previously recorded episodes. I just need to make the path changes and other extras mentioned above and let it run on an upcoming recording.
__________________
Bruno
Twisted Melon Inc.
While you're clicking, check out my Mini Theater custom build.
Reply With Quote
  #16  
Old 12-28-2017, 12:44 PM
TwistedMelon TwistedMelon is offline
Sage Expert
 
Join Date: Aug 2005
Location: Ontario, Canada
Posts: 554
GrayWolf's mod to Slugger's script takes care of the archive property:

https://forums.sagetv.com/forums/sho...postcount=1041
__________________
Bruno
Twisted Melon Inc.
While you're clicking, check out my Mini Theater custom build.
Reply With Quote
  #17  
Old 12-30-2017, 11:05 AM
TwistedMelon TwistedMelon is offline
Sage Expert
 
Join Date: Aug 2005
Location: Ontario, Canada
Posts: 554
Having an issue with triggering the SJQ task on a favorite - it's not working.

I can add the task to an existing recording and it fires off and does its job right away. Setting the same task on a favorite "sticks" but doesn't seem to do anything when the recording ends. To be clear, on the favorite, I'm setting the task on the "Recording Stop" trigger.

Any ideas of where to look to find more info on why this is happening (or not happening)?

* I have the commercial detector plugin installed and that processes the recordings with comskip at some point after recording ends (according to its defaults, like if nothing else is recording, etc..) - might this be a factor?
__________________
Bruno
Twisted Melon Inc.
While you're clicking, check out my Mini Theater custom build.

Last edited by TwistedMelon; 12-30-2017 at 11:08 AM.
Reply With Quote
  #18  
Old 01-02-2018, 08:04 PM
TwistedMelon TwistedMelon is offline
Sage Expert
 
Join Date: Aug 2005
Location: Ontario, Canada
Posts: 554
The Comskip process firing off after recordings end prevented the SJQ task from running. Disabling Comskip during the hours of the recordings lets everything work as expected. yay!
__________________
Bruno
Twisted Melon Inc.
While you're clicking, check out my Mini Theater custom build.
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
Move recordings automatically? Grasshopper SageTV Software 0 06-28-2013 12:57 PM
How do I automatically stop a video after it finishes dvd_maniac SageTV Software 1 03-02-2011 08:07 PM
How do you automatically move Movie recordings to your My Videos area? gveres SageMC Custom Interface 14 01-11-2010 08:19 AM
Automatically move a file at the end of a rec. fabiotv SageTV Software 9 08-26-2009 07:28 AM
Prevent recording a favorite on a specific channel BLS SageTV Software 4 08-29-2003 01:05 PM


All times are GMT -6. The time now is 03:24 PM.


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