def testMode = false // If true, only print out which media files would be queued up, don't actually add the tasks to the queue def mediaMask = "T" // What types of media should be scanned? (T = TV, M = Music, V = Imported Video, D = DVD, B = BluRay, P = Pictures; TMV = TV + Music + Imports, etc.) def taskIds = ["CUT","HANDBRAKE"] // Multiple tasks can be listed, separated by commas def needsProcessing(Object mediaFile) { // This function could be written in a much more condensed manner, but I'm breaking it up for the sake of readability // Personally, I don't comskip until the recording is done, so don't queue up recordings in progress // if(MediaFileAPI.IsFileCurrentlyRecording(mediaFile)) // return false // Let's also skip it if it's from a channel known not to have commercials (adjust the regex accordingly) // if(AiringAPI.GetAiringChannelName(mediaFile) =~ /HBO.*|SPEED.*/) // return false // Let's also skip it if there is already an edl file for the media file; adjust the extensions, if necessary if(hasArtifacts(mediaFile, ["edl1"])) // This function is defined at the bottom of the file return true // Let's also skip it if there is already an edl file for the media file; adjust the extensions, if necessary // if(hasArtifacts(mediaFile, ["edl"])) // This function is defined at the bottom of the file // return true // I don't like comskipping hockey and football games, I just have the skip ahead set properly on my remote so don't bother // if(MediaFileAPI.GetMediaTitle(mediaFile) =~ /NFL Football|MLB Baseball|NHL Hockey|College Football|College Basketball/) // return false // All our tests have passed so return false return false } /***** END CONFIG BLOCK *****/ /***** DO NOT MODIFY BELOW THIS LINE *****/ import com.google.code.sagetvaddons.sjq.network.ServerClient import com.google.code.sagetvaddons.metadata.Factory import org.apache.commons.io.FilenameUtils import org.apache.commons.io.FileUtils def sc = !testMode ? new ServerClient() : null MediaFileAPI.GetMediaFiles("T").each { mediaFile -> if (MediaFileAPI.IsTVFile(mediaFile)){ if (needsProcessing(mediaFile)) { if (!testMode) { taskIds.each { id -> sc.addTask(id, Factory.getMap(mediaFile)) println "Will queue up '${MediaFileAPI.GetMediaTitle(mediaFile)}' (${MediaFileAPI.GetMediaFileID(mediaFile)})" } } else println "Would queue up '${MediaFileAPI.GetMediaTitle(mediaFile)}' (${MediaFileAPI.GetMediaFileID(mediaFile)}); skipped because test mode is TRUE" } } } if(sc != null) sc.close() return 0 // Returns true if any segment of the given media file has at least one artifact of any of the given artifact extensions; false otherwise def hasArtifacts(Object mediaFile, List exts) { for(def it : MediaFileAPI.GetSegmentFiles(mediaFile)) { def absPath = it.getAbsolutePath() def dir = FilenameUtils.getFullPath(absPath) def base = FilenameUtils.getBaseName(absPath) for(def ext : exts) { def artifact = "${dir}${base}.$ext" def artifactRename = "${dir}${base}.edl2" if(Utility.IsFilePath(artifact)){ FileUtils.moveFile(new File(artifact), new File(artifactRename)) return true } } } return false } // Let's set TASK_Status to 'running'. // MediaFileAPI.SetMediaFileMetadata(mediaFile, 'TASK_Status', 'CUT_QUEUED')