[Synology] Linux script -Conflict Override and Mdate/touch and possible improvement suggestions

Running FileBot from the console, Groovy scripting, shell scripts, etc
Post Reply
Seger
Posts: 5
Joined: 21 Aug 2018, 08:47

[Synology] Linux script -Conflict Override and Mdate/touch and possible improvement suggestions

Post by Seger »

Hello, everybody,

I also have a DS2415+ (Synology: Filbot including JD in the latest Linux version with license), only 2 things I would like to get solved, maybe you can help me?


1.

I would like to give the date of the actual move to the moved files like the function "touch" or "mdate" if you know what I mean. Background is that I have some scripts running that access the modification date of the respective.mkv files.



2.

Code:

Code: Select all

—conflict override
does not work as desired, I always want to overwrite everything when I download something and it already exists. Under Windows this also works, but somehow not by script.

For your understanding, here are my scripts:

Code: Select all

#!/bin/sh
LOG="/volume1/DiskStation/Programme/Skripte/1LOGS/amc.log"
EXC="/volume1/DiskStation/Programme/Skripte/1LOGS/amc.txt"
SERIEN="/volume1/DiskStation/Upload_Download/Testumgebung/Serien/{n} ({y})/Staffel {s}/{n} - {s00e00} - {t}"
FILME="/volume1/DiskStation/Upload_Download/Testumgebung/Filme/{collection}\{n.colon(' - ')} ({y}) [{vf}]\{n.colon(' - ')} ({y}) [{vf}]"
UNSORTIERT="/volume1/{file.structurePathTail}"

##FileBot ausführen
/var/packages/filebot/target/filebot.sh -script fn:amc --lang de --log-file $LOG --action move "$1" --conflict override -non-strict --order Airdate --def excludeList=$EXC --def "seriesFormat=$SERIEN" "movieFormat=$FILME" "unsortedFormat=$UNSORTIERT" --def unsorted=y "artwork=n" --def clean=y

## Aufräumen, --def root löscht den Unterordner mit
/var/packages/filebot/target/filebot.sh -script fn:cleaner "$1" --def root=y

Maybe you notice other things, added and changed some things last night. I always welcome suggestions for improvement.

THANKS for your help.

VG
Seger
User avatar
rednoah
The Source
Posts: 22994
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: [Synology] Linux script -Conflict Override and Mdate/touch and possible improvement suggestions

Post by rednoah »

1.
You use --def exec for that, e.g.

Code: Select all

--def exec="touch {quote f}"

2.
Not sure about this one. --conflict override will always override. Behavior on Windows and Linux is the same because the code is the same. If this doesn't work as expected, there's probably an issue with your call, and the logs will likely contains some hints.


3.
--output is notably absent. --output must always be defined. It's not just used for formats. The recommended best practice is to use absolute --output paths and relative formats. Also makes things more readable.


4.
Using filebot is generally more readable & reliable than /var/packages/filebot/target/filebot.sh and doesn't require you to know where / how Synology installs packages.
:idea: Please read the FAQ and How to Request Help.
Seger
Posts: 5
Joined: 21 Aug 2018, 08:47

Re: [Synology] Linux script -Conflict Override and Mdate/touch and possible improvement suggestions

Post by Seger »

1.
I installed, THANK YOU! I hope I have the code cell installed in the right place, test will be pushed immediately.

2.
The error in the log: already exists
I've already read that the script always makes sure that there's always a better version, but that's not always true and I know what to add to the download. In my example, it is an Asycron fix, or an extended version that I want to write about the old, although the file is a little smaller (just better encoded). In Windows, as I said with the button Override force the move, which command forces it because regardless of the protection?

3.
Since I do not know exactly what you mean, my English is horrible and the Translator is not clean. Can you perhaps my code what you mean with absolute --output paths and relative formats? Do you mean the mix of the target sources or what exactly do you mean?

4.
I installed, THANK YOU!

Enclosed I send you again my current code, maybe you can make the optimizations on that?

Code: Select all

#!/bin/sh

LOG="/volume1/DiskStation/Programme/Skripte/1LOGS/amc.log"
EXC="/volume1/DiskStation/Programme/Skripte/1LOGS/amc.txt"
SERIEN="/volume1/DiskStation/Upload_Download/Testumgebung/Serien/{n} ({y})/Staffel {s}/{n} - {s00e00} - {t}"
FILME="/volume1/DiskStation/Upload_Download/Testumgebung/Filme/{collection}\{n.colon(' - ')} ({y}) [{vf}]\{n.colon(' - ')} ({y}) [{vf}]"
UNSORTIERT="/volume1/DiskStation/Upload_Download/Testumgebung/UNSORTIERT/{file.parentFile.name}"

##FileBot ausführen
Filebot -script fn:amc --lang de --log-file $LOG --action move "$1" --conflict override --def exec="touch {quote f}" -non-strict --order Airdate --def "seriesFormat=$SERIEN" "movieFormat=$FILME" "unsortedFormat=$UNSORTIERT" --def unsorted=y "artwork=n" --def clean=y

## Aufräumen, --def root löscht den Unterordner mit
Filebot -script fn:cleaner "$1" --def root=y
thank you for your help!

Seger
User avatar
rednoah
The Source
Posts: 22994
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: [Synology] Linux script -Conflict Override and Mdate/touch and possible improvement suggestions

Post by rednoah »

2.
Please post the full log on pastebin so I can have a look:
https://pastebin.com/


3.
I mean doing things this way:

Code: Select all

--output "/volume1/DiskStation" --def seriesFormat="{n} ({y})/Staffel {s}/{n} - {s00e00} - {t}" ...

4.
I'm actually not sure if Filebot works. Is bash case-insensitive by default? IDK. I'd stick to the official command filebot which is all lower-case.
:idea: Please read the FAQ and How to Request Help.
Seger
Posts: 5
Joined: 21 Aug 2018, 08:47

Re: [Synology] Linux script -Conflict Override and Mdate/touch and possible improvement suggestions

Post by Seger »

Madness, how quickly you help me, thank you!

2.
Attached the log to the test.
https://pastebin.com/sGsL6auU

Edit:have just seen that it has now funtkioniert. But maybe you can see more suggestions for improvement while we're at it. Otherwise, just a big thank you!

Edit 2:

where I have just now seen that he has not deleted the folder, source folder has not deleted, because there was probably still a *. Url file in it. Otherwise I always deleted all files and folders with a different script:

del / s * .htm * .html * .txt * .url * .idx * .sfv * .srr * .nfo * .sub * .gif * .jpg * jpg_1 * .png * .jpeg * .JAcheck
for / D / R %% g in (sample *, proof *, subs *, subs *) do rd / s / q "%% g"

Can you just delete these things? I always do not want samples.

3.
Got it, you want to have the variables up from the script and write everything in a code cell. I will adjust that at once (not done at the top of the log). Is for me as a beginner :-), but always a little easier, but understand the point with the error rate. Or let's talk about it ;-)

The other points are already running :-), thanks again!

Seger
User avatar
rednoah
The Source
Posts: 22994
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: [Synology] Linux script -Conflict Override and Mdate/touch and possible improvement suggestions

Post by rednoah »

2.
The log shows that override is working just fine. The original file is deleted, and then the new file is moved.

The cleaner script is very conservative and tries not to delete files that might be important. Best to do it yourself if you know what you want and don't want. Though url files should be on the list of files to delete. If you have samples, it's more likely that you have samples above the file size limit, which is 100 MB by default, but can be changed via options:
viewtopic.php?f=4&t=5#p1341
:idea: Please read the FAQ and How to Request Help.
Seger
Posts: 5
Joined: 21 Aug 2018, 08:47

Re: [Synology] Linux script -Conflict Override and Mdate/touch and possible improvement suggestions

Post by Seger »

Hey me again,

I've taken a little bit of the Cleaner theme and now I see that there is already a script that contains all my endings:

https://github.com/filebot/scripts/blob ... ner.groovy

I just tried everything as you wanted to tell me by link to test. But I recognized one of my problems in the above script "// NOTE: some smb filesystem implementations are buggy and known to incorrectly return filesize 0 for all files".

Now I ask myself the question, how perhaps I integrate the above-mentioned script into my script or just a line of text which reflects exactly that. I just do not want to have any folders or files except the main movie, just like in the script.

A short question of understanding still too min and max option, the standards must nevertheless so e.g. be overwritten or?

Edit: ok I have called the script locally for test purposes and it works so far, but a file "Internet link (.URL)" with 206 bytes remains in the folder and thus blocks the deletion of the folder.

Code: Select all

filebot -script "/volume1/DiskStation/Programme/Skripte/Filebot/cleaner.sh" --action test "/volume1/DiskStation/Upload_Download/1 Download/Departed.Unter.Feinden.2006"
Code cleaner.sh:

Code: Select all

#!/usr/bin/env filebot -script


def deleteRootFolder = any{ root.toBoolean() }{ false }

def ignore  = any{ ignore }{ /extrathumbs/ }
def exts    = any{ exts }{ /jpg|jpeg|png|gif|ico|nfo|info|xml|htm|html|log|m3u|cue|srt|sub|idx|smi|sup|md5|sfv|txt|rtf|url|db|dna|log|tgmd|json|data|ignore|srv|srr|nzb|vbs|ini|vsmeta/ }
def terms   = any{ terms }{ /sample|trailer|extras|deleted.scenes|music.video|scrapbook|DS_Store/ }
def minsize = any{ minsize.toLong() }{ 20 * 1024 * 1024 }
def maxsize = any{ maxsize.toLong() }{ 100 * 1024 * 1024 }


def testRun = _args.action.equalsIgnoreCase('test')


/*
 * Delete orphaned "clutter" files like nfo, jpg, etc and sample files
 */
def isClutter = { f ->
	// whitelist
	if (f.path.findMatch(ignore))
		return false

	// file is either too small to have meaning, or to large to be considered clutter
	def fsize = f.length()

	// path contains blacklisted terms or extension is blacklisted
	if (f.extension ==~ exts && fsize < maxsize)
		return true

	if (f.path.findMatch(/\b(/ + terms + /)\b/) && fsize < maxsize)
		return true

	// NOTE: some smb filesystem implementations are buggy and known to incorrectly return filesize 0 for all files
	if (f.isVideo() && fsize < minsize && fsize > 0)
		return true

	return false
}


def clean = { f ->
	log.info "Delete $f"

	// do a dry run via --action test
	if (testRun) {
		return false
	}

	return f.isDirectory() ? f.deleteDir() : f.delete()
}


// memoize media folder status for performance
def hasMediaFiles = { dir -> dir.isDirectory() && dir.getFiles().find{ (it.isVideo() || it.isAudio()) && !isClutter(it) } }.memoize()

// delete clutter files in orphaned media folders
args.getFiles{ isClutter(it) && !hasMediaFiles(it.dir) }.each{ clean(it) }

// delete empty folders but exclude given args
args.getFolders().sort().reverse().each{
	if (it.isDirectory() && !it.hasFile{ it.isDirectory() || !isClutter(it) }) {
		if (deleteRootFolder || !args.contains(it))
			clean(it)
	}
}
https://pastebin.com/btjwtDE0

Thank you for your help
Seger
User avatar
rednoah
The Source
Posts: 22994
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: [Synology] Linux script -Conflict Override and Mdate/touch and possible improvement suggestions

Post by rednoah »

I don't see any reason why it wouldn't work for URL files when it works for everything else on the list of extension. If it's not working for you, there might be a different reason unrelated to the URL file.

e.g. works for me:

Code: Select all

PS C:\> filebot -script fn:cleaner .\Test\
Delete C:\Test\Avatar.url
Delete C:\Test\Avatar-sample.mp4
Done ?(?????)?
:idea: Please read the FAQ and How to Request Help.
Seger
Posts: 5
Joined: 21 Aug 2018, 08:47

Re: [Synology] Linux script -Conflict Override and Mdate/touch and possible improvement suggestions

Post by Seger »

Hey you,

I believe that everything works for me too, but the file that I'm talking about is an exam without file extension. When I call the property search, the properties tell me: Internet shortcut (.URL) but just without file extension. Test.url or test.html also work, but not this link. Unfortunately, I can not upload a file here. The link also works like any self-made URL link, but the strange thing is that Chrome's icon appears, e.g. is not displayed. This file is included in every download of the page and refers only to the page.

Do you have any idea? Can I still deliver something for you?

Edit: https://picload.org/view/dllpiwdw/unbenannt.jpg.html
Edit 2: https://pastebin.com/PiXAu8B1

Thanks and best regards
Seger
User avatar
rednoah
The Source
Posts: 22994
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: [Synology] Linux script -Conflict Override and Mdate/touch and possible improvement suggestions

Post by rednoah »

Well, I'd start by checking what the actual file path / extension of that file is. It's not URL. It's probably LNK. A Windows Link file, like the links on your desktop.

LNK is not on the list of extensions by default so it's not commonly used for this purpose on Windows, and never on any other platform.
:idea: Please read the FAQ and How to Request Help.
Post Reply