-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfilldb.rb
94 lines (87 loc) · 2.39 KB
/
filldb.rb
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
#!/usr/bin/env ruby
require('rubygems')
require('parseconfig')
require('dbi')
require('find')
argument = ARGV[0]
configfile = './msl.conf'
if not File.exist?(configfile)
raise RuntimeError, "No config file"
end
config = ParseConfig.new(configfile)
dbserver = config.params['database']['server']
dbname = config.params['database']['dbname']
dbuser = config.params['database']['user']
dbpass = config.params['database']['pass']
tvpaths = ['/mnt/storage3/video3', '/mnt/storage5/video5', '/mnt/storage6/video6', '/mnt/storage1/video7']
moviepaths = ['/mnt/storage1/video1', '/mnt/storage2/video2', '/mnt/storage4/video4']
begin
dbh = DBI.connect("DBI:Mysql:#{dbname}:#{dbserver}", dbuser, dbpass)
if argument == 'clean'
print "Cleaning episodes\n"
sth = dbh.prepare("SELECT path FROM ep_files")
sth.execute
while row = sth.fetch do
path = row[0]
if not File.exist?(path)
print "-"
sth2 = dbh.prepare("DELETE FROM ep_files WHERE path=?")
sth2.execute(path)
sth2.finish
end
end
sth.finish
print "\nCleaning movies\n"
sth = dbh.prepare("SELECT path FROM mov_files")
sth.execute
while row = sth.fetch do
path = row[0]
if not File.exist?(path)
print "-"
sth2 = dbh.prepare("DELETE FROM mov_files WHERE path=?")
sth2.execute(path)
sth2.finish
end
end
sth.finish
elsif argument == 'scan'
tvpaths.each {|path|
print "Scanning TV : #{path} : "
Find.find(path) do |entry|
if File.file?(entry) and entry =~ /.+\.(avi|mpg|mkv|vob|divx|flv|mp4|mpeg|wmv|rmvb|rm)$/
sth = dbh.prepare("SELECT * FROM ep_files WHERE path=?")
sth.execute(entry)
rows = sth.fetch_all.size
sth.finish
if rows==0
sth = dbh.prepare("INSERT INTO ep_files(path,datasource) VALUES (?,'tvdb')")
sth.execute(entry)
sth.finish
print "+"
end
end
end
print "\n"
}
moviepaths.each {|path|
print "Scanning Movie : #{path} : "
Find.find(path) do |entry|
if File.file?(entry) and entry =~ /.+\.(avi|mpg|mkv|vob|divx|flv|mp4|mpeg|wmv|rmvb|rm)$/
sth = dbh.prepare("SELECT * FROM mov_files WHERE path=?")
sth.execute(entry)
rows = sth.fetch_all.size
sth.finish
if rows==0
sth = dbh.prepare("INSERT INTO mov_files(path,datasource) VALUES (?,'tvdb')")
sth.execute(entry)
sth.finish
print "+"
end
end
end
print "\n"
}
end
ensure
dbh.disconnect if dbh
end