-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathnfo-tool.pl
More file actions
executable file
·103 lines (96 loc) · 2.52 KB
/
nfo-tool.pl
File metadata and controls
executable file
·103 lines (96 loc) · 2.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/perl
# Perl Based .nfo updater for Emby/Plex/XMBC
#
# Very simple design, only tested on Emby
# Allows updating of year, actor, studio and tags
# Silly Duplicate Detection
use Getopt::Long;
GetOptions ("nfo=s" => \$nfo_file,
"actor=s" => \$actor_test,
"year=i" => \$year,
"studio=s" => \$studio,
"tag=s" => \$tag,
"debug=s" => \$debug)
or die("Error in command line arguments\n");
if (!$nfo_file) {
die ("No nfo_file given");
}
if (!$actor_test && !$year && !$studio && !$tag) {
die ("At least on checkfield is mandatory");
}
if ($debug) {
print "NFO: ".$nfo_file."\n";
}
$nfo_file_w = $nfo_file.".tmp";
open NFO_FILE,"<$nfo_file" or die "Error opening NFO File";
open (my $wfh, '>', $nfo_file_w) or die "Error opening Temp File";
$line = 0;
while (<NFO_FILE>) {
$parse = $_;
if ($line == 0) {
if ($parse =~ /xml/) {
if ($debug) {
print "XML Found\n";
}
} else {
die "No XML File";
}
}
if ($actor_test && $parse =~ /<name>$actor_test</ ) {
$actor_exists = 1;
if ($debug) {
print $actor_test." is here\n";
}
}
if ($tag && $parse =~ /<tag>$tag</ ) {
$tag_exists = 1;
if ($debug) {
print $tag." is here\n";
}
}
if ($studio && $parse =~ /<studio>/ ) {
if ($parse =~ /<studio>$studio</ ) {
$studio_exists = 1;
} else {
$studio_exists = 0;
$studio_differs = 1;
}
if ($debug) {
print $studio." is here\n";
}
}
if ($year && $parse =~ /<year>/ ) {
if ($parse =~ /<year>$year</ ) {
$year_exists = 1;
} else {
$year_exists = 1;
$year_differs = 1;
}
if ($debug) {
if ($year_differs) {
print $parse." is here not ".$year."\n";
} else {
print $year." is here\n";
}
}
}
if ($parse =~ /<fileinfo>/ ) {
if ($actor_test && $actor_exists < 1) {
print $wfh " <actor>\n <name>$actor_test</name>\n </actor>\n";
}
if ($tag && $tag_exists < 1) {
print $wfh " <tag>$tag</tag>\n";
}
}
if ($parse =~ /<runtime>/ && $year && !$year_exists) {
print $wfh " <year>$year</year>\n";
}
if ($parse =~ /<fileinfo>/ && $studio && !$studio_exists) {
print $wfh " <studio>$studio</studio>\n";
}
print $wfh "$parse";
$line++;
}
close PW_FILE;
close $whf;
rename $nfo_file_w, $nfo_file;