Skip to content

Commit

Permalink
added two new scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
revenz committed Sep 1, 2023
1 parent ec3d94e commit 868cc62
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 0 deletions.
52 changes: 52 additions & 0 deletions Scripts/System/DownloadClients/DeleteRogueUNPACKDirectories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
* @name Delete Rogue _UNPACK_ Directories
* @description Will check any _UNPACK_ directories, and if they haven't be modified in 24 hours will delete that directory
* @revision 1
* @minimumVersion 1.0.0.0
*/

let folders = Variables['RogueUnpackDirectoryList'];
if(!folders){
Logger.WLog('RogueUnpackDirectoryList variable not defined.')
return;
}

folders = folders.trim().split('\n');
if(!folders.length){
Logger.WLog('RogueUnpackDirectoryList variable has no folders.')
return;
}

for(let folder of folders)
{
var dir = new System.IO.DirectoryInfo(folder);
if(dir.Exists === false)
continue;
Logger.ILog('Checking diretory: ' + folder);

const cutoffDate = new Date(Date.now() - (24 * 60 * 60 * 1000));
let subdirs = dir.GetDirectories('_UNPACK_*', System.IO.SearchOption.AllDirectories);
for(let subdir of subdirs)
{
if(subdirs.Exists === false)
continue;

Logger.ILog('Found _UNPACK_ directory:' + subdir.FullName);

if (subdir.LastWriteTime > cutoffDate || subdir.CreationTime > cutoffDate)
{
Logger.ILog('Directory was written/created recently: ' + subdir.FullName);
continue;
}

try
{
Logger.ILog('Deleting rogue directory: ' + subdir.FullName);
subdir.Delete(true);
}
catch(err)
{
Logger.WLog('Failed to delete directory: ' + ex.Message);
}
}
}
59 changes: 59 additions & 0 deletions Scripts/System/File/AddMKVExtension.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/**
* @name Add MKV extension to files without an extension
* @description Monitors the directories listed in the variable AddExtensionDirectoryList and any file thats found without an extenion, MKV will be added to it
* @revision 1
* @minimumVersion 1.0.0.0
*/

let folders = Variables['AddExtensionDirectoryList'];
if(!folders){
Logger.WLog('AddExtensionDirectoryList variable not defined.')
return;
}

folders = folders.trim().split('\n');
if(!folders.length){
Logger.WLog('AddExtensionDirectoryList variable has no folders.')
return;
}

for(let folder of folders)
{

var dir = new System.IO.DirectoryInfo(folder);
Logger.ILog('Dir exists:' + dir.Exists);
var files = dir.GetFiles("*", System.IO.SearchOption.AllDirectories);

Logger.ILog('Files: ' + files.length);

for(var file of files)
{
let name = file.FullName;

if(name.endsWith('.mp4.mkv') || name.endsWith('.avi.mkv')){
file.MoveTo(name.substring(0, name.length - 4));
continue;
}

if(name !== file.Directory.FullName && name.indexOf('.mkv.mkv') < 0)
{
let index = name.lastIndexOf('.');
if(index > 0)
{
let extension = name.substring(index + 1);
Logger.ILog('Extension: '+ extension);
if(extension.length < 5)
continue;
}
}
if (file.Length < 200000000)
continue;

if(name.indexOf('.mkv.mkv') > 0)
name = name.replace(/\.mkv/g, '');

Logger.ILog("Adding MKV extension to file: " + file.FullName);

file.MoveTo(name + ".mkv");
}
}

0 comments on commit 868cc62

Please sign in to comment.