Custom Columns for Movies and TV

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
VeeGee

Custom Columns for Movies and TV

Post by VeeGee »

Good evening all,
Today I created 2 Custom Columns and I'd like to share them. I have movie/TV folders and files in name (year) format. I wanted new columns that rearrange The, A movies and a column to show just the year.

For example,
Image-016.png
Image-016.png (3 KiB) Viewed 1075 times
This way I can have a few more sorting options without having to rename my folders or files. Plus I've been wanting to do some more scripting and use Custom Columns.

Here are my snippets of code. As I experiment more I'm sure they can be shortened by quite a bit. I'm also sure highend will have a one-line solution to replace them :biggrin:

Movie Title :

Code: Select all

$base = getpathcomponent(<cc_name>, "base");
$defaultmodamount = 7;

if(strpos($base, "A ") == 0) {
	$startend = 2;
	if(strpos($base, ")") > 0) {
		$modamount = $defaultmodamount;
	} else {
		$modamount = 0;
	}
	$modlength = $strlen($base) - $modamount;
} elseif(strpos($base, "The") == 0) {
	$startend = 4;
	if(strpos($base, ")") > 0) {
		$modamount = 11;
	} else {
		$modamount = 0;
	}
	$modlength = strlen($base) - $modamount;
} else {
	if(strpos($base, ")") > 0) {
		return substr($base, 0, strlen($base) - $defaultmodamount);
		exit;
	} else {
		return $base;
		exit;
	}
}

$basea = substr($base, $startend, strlen($base) - $startend);
$baseb = substr($basea, 0, $modlength);
$basec = substr($base, 0, strlen($base) - $defaultmodamount);

if(strpos($base, "A ") == 0) {
	return trim($baseb . ", A");
} elseif(strpos($base, "The") == 0) {
	return trim($baseb . ", The");
} else {
	return trim($basec);
}
Movie Year :

Code: Select all

$base = getpathcomponent(<cc_name>, "base");
if(strpos($base, ")") > 0) {
	return substr($base, -5, 4);
}
I hope someone else can enjoy these !

highend
Posts: 13327
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Custom Columns for Movies and TV

Post by highend »

I'm also sure highend will have a one-line solution to replace them
^^

Title (it also recognizes & removes e.g. "[2016]" or just "2016" as the year as well...)

Code: Select all

return regexreplace(regexreplace(gpc(<cc_item>, "base"), "^(A|The) (.*)", "$2, $1"), "[ ]*?(\(|\[)?(\d{4})(\)|\])?[ ]*?");

Year:

Code: Select all

return regexmatches(gpc(<cc_item>, "base"), "\d{4}");
Btw, you don't need exit in a custom column script when the command above is a return. It will automatically leave the script at that point
One of my scripts helped you out? Please donate via Paypal

VeeGee

Re: Custom Columns for Movies and TV

Post by VeeGee »

Your one-liners are amazing, thank you highend. Regex gets me every time. I read and try, rinse and repeat and is still hard to grasp. I use https://regex101.com/ quite often when I am trying to get one working. Most of the ones I am currently using/working on are for PHP or JS.

Thanks again for your contributions.

Post Reply