-
Notifications
You must be signed in to change notification settings - Fork 3
/
mkmovies2mysql.pl
executable file
·164 lines (138 loc) · 3.16 KB
/
mkmovies2mysql.pl
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#!/usr/bin/perl -w
# ---------------
sub mysql_drop() {
print "DROP TABLE Media;
DROP TABLE Data;
DROP TABLE Genres;
DROP TABLE Casts;
DROP TABLE Directors;
DROP TABLE Types;
DROP TABLE ISOs;
DROP TABLE Years;
";
}
# ---------------
sub mysql_create() {
print "CREATE TABLE Media
(
Name varchar(128) PRIMARY KEY,
Title varchar(64),
Year int,
Plot varchar(256)
);
CREATE TABLE Data
(
Name varchar(128),
URL varchar(64),
File varchar(128)
);
CREATE TABLE Genres
(
Name varchar(128),
Genre varchar(64)
);
CREATE TABLE Casts
(
Name varchar(128),
Cast varchar(64)
);
CREATE TABLE Directors
(
Name varchar(128),
Director varchar(64)
);
CREATE TABLE Types
(
Type varchar(64) PRIMARY KEY
);
CREATE TABLE ISOs
(
Title varchar(64) PRIMARY KEY
);
CREATE TABLE Years
(
Year int PRIMARY KEY
);
";
}
# ---------------
sub mysql_insert() {
$file = shift;
$name = shift;
$title = shift;
$url = shift;
$year = shift;
$genres = shift;
$casts = shift;
$directors = shift;
$plot = shift;
$year = 0 if(!$year);
$title =~ s/ \(.*//;
$title =~ s/ - $//;
$title =~ s/ \(ISO\)//;
$plot =~ s/.*: //;
$plot =~ s/\"/\'/g;
$plot =~ s/\<br\>$//i;
$casts =~ s/, /, /g;
$casts =~ s/ /, /g;
if(! defined($DATA{lc($name)})) {
$DATA{lc($name)} = "$file;$name;$title;$url;$year;$genres;$casts;$directors;$plot";
print "INSERT INTO Media VALUES (\"$name\", \"$title\", $year, \"$plot\");\n";
print "INSERT INTO Data VALUES (\"$name\", \"$url\", \"$file\");\n";
if(($file =~ /\/ISOs\//) || ($title =~ /ISO/i)) {
if(! defined($ISOs{lc($title)})) {
$ISOs{lc($title)} = $title;
print "INSERT INTO ISOs VALUES (\"$title\");\n";
}
}
if(($year > 0) && (! defined($YEARS{$year}))) {
$YEARS{$year} = $year;
print "INSERT INTO Years VALUES (\"$year\");\n";
}
@genres = split(', ', $genres);
for $genre (@genres) {
print "INSERT INTO Genres VALUES (\"$name\", \"$genre\");\n";
if(! defined($GENRES{lc($genre)})) {
$GENRES{lc($genre)} = $genre;
print "INSERT INTO Types VALUES (\"$genre\");\n";
}
}
@casts = split(', ', $casts);
for $cast (@casts) {
$cast =~ s/^\ //;
$cast =~ s/\|.*//;
if(($cast !~ /^$/) &&
($cast !~ /&#x/) &&
($cast !~ /\| See full cast/i) &&
($cast !~ /crew/))
{
print "INSERT INTO Casts VALUES (\"$name\", \"$cast\");\n";
}
}
@directors = split(', ', $directors);
for $director (@directors) {
if(($director !~ /^$/) &&
($director ne '1') &&
($director !~ /more credit/) &&
($director !~ /See full technical specs/i) &&
($director !~ /^&#x/))
{
print "INSERT INTO Directors VALUES (\"$name\", \"$director\");\n";
}
}
print "\n";
}
}
# ---------------
&mysql_drop();
&mysql_create();
open(LIST, "/share/.Torrents/Unsorted/.list")
|| die("Can't open file, $!\n");
while(! eof(LIST)) {
$line = <LIST>;
chomp($line);
($file, $name, $title, $url, $year, $genres, $casts, $directors, $plot)
= split(';', $line);
&mysql_insert($file, $name, $title, $url, $year, $genres, $casts, $directors, $plot);
}
close(LIST);