rubyVDRconvert 0.0.7 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/file_dir.rb +27 -28
- data/lib/recording.rb +3 -6
- data/lib/recording_ts.rb +22 -14
- data/lib/recording_vdr.rb +22 -15
- data/lib/recordings.rb +2 -6
- metadata +2 -2
data/lib/file_dir.rb
CHANGED
@@ -2,35 +2,34 @@ require 'find'
|
|
2
2
|
|
3
3
|
class FileDir
|
4
4
|
def self.delete!(filedir)
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
end
|
5
|
+
begin
|
6
|
+
case Dir.exist?(filedir)
|
7
|
+
when true
|
8
|
+
begin
|
9
|
+
Dir.rmdir(filedir)
|
10
|
+
rescue
|
11
|
+
Dir.foreach(filedir) { | entry |
|
12
|
+
delete!(filedir + '/' + entry) unless (entry == ".") or (entry == "..")
|
13
|
+
}
|
14
|
+
retry
|
15
|
+
end
|
16
|
+
else
|
17
|
+
File.delete(filedir)
|
18
|
+
end
|
19
|
+
rescue
|
20
|
+
$stderr.puts "Failed to delete #{filedir}"
|
21
|
+
end
|
23
22
|
end
|
24
23
|
def self.mkdirtree(directory)
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
24
|
+
begin
|
25
|
+
Dir.mkdir(directory)
|
26
|
+
rescue SystemCallError => ex
|
27
|
+
parent = File.dirname(directory)
|
28
|
+
# Prevent an endless loop
|
29
|
+
return true if Dir.exist?(directory)
|
30
|
+
raise ex if parent.length == '/'
|
31
|
+
self.mkdirtree(parent)
|
32
|
+
retry
|
33
|
+
end
|
35
34
|
end
|
36
35
|
end
|
data/lib/recording.rb
CHANGED
@@ -19,7 +19,7 @@ class Recording
|
|
19
19
|
@timestamp = File.mtime(@directory + '/index')
|
20
20
|
load_info
|
21
21
|
determine_stream_type
|
22
|
-
|
22
|
+
puts "New recording: #{@friendly_name}"
|
23
23
|
end
|
24
24
|
def marshal_dump()
|
25
25
|
[ @directory, @recording, @title, @subtitle, @friendly_name, @target_dir, @processed, @timestamp, @recording_time ]
|
@@ -37,10 +37,9 @@ class Recording
|
|
37
37
|
end
|
38
38
|
def delete!()
|
39
39
|
@mutex.synchronize {
|
40
|
+
@recording.delete! if @recording
|
40
41
|
@recording = nil
|
41
42
|
GC.start
|
42
|
-
p "Deleting....", self, @target_dir
|
43
|
-
FileDir.delete!(@target_dir)
|
44
43
|
}
|
45
44
|
end
|
46
45
|
def load_info()
|
@@ -53,10 +52,8 @@ class Recording
|
|
53
52
|
case line[0..1]
|
54
53
|
when 'T '
|
55
54
|
@title = line[2..256].chomp
|
56
|
-
p "Found title: #{@title}"
|
57
55
|
when 'S '
|
58
56
|
@subtitle = line[2..256].chomp
|
59
|
-
p "Found subtitle: #{@subtitle}"
|
60
57
|
when 'E '
|
61
58
|
@recording_time = Time.at(line.split[2].to_i)
|
62
59
|
end
|
@@ -81,7 +78,7 @@ class Recording
|
|
81
78
|
end
|
82
79
|
end
|
83
80
|
def process!()
|
84
|
-
|
81
|
+
puts "Processing of #{@friendly_name} started..."
|
85
82
|
@mutex.synchronize{
|
86
83
|
@processed = true if @recording.process!
|
87
84
|
}
|
data/lib/recording_ts.rb
CHANGED
@@ -2,21 +2,29 @@ require 'file_dir'
|
|
2
2
|
|
3
3
|
class RecordingTS
|
4
4
|
def initialize(recording)
|
5
|
-
|
5
|
+
@parent = recording
|
6
|
+
@target_file = nil
|
6
7
|
end
|
7
8
|
def process!()
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
9
|
+
@target_file = @parent.target_dir + "/#{@parent.friendly_name}.ts"
|
10
|
+
FileDir.mkdirtree(@parent.target_dir)
|
11
|
+
tf = File.new(@target_file, 'wb:ascii-8bit')
|
12
|
+
source_files = Dir.glob("#{@parent.directory}/*.ts")
|
13
|
+
source_files.sort!
|
14
|
+
source_files.each { | source_file |
|
15
|
+
sf = File.new(source_file, 'rb:ascii-8bit')
|
16
|
+
while not sf.eof?
|
17
|
+
tf.write(sf.read(1*(2**20))) # Only read some bytes at once
|
18
|
+
sleep(0.01) # Be friendly to other processes
|
19
|
+
end
|
20
|
+
sf.close
|
21
|
+
}
|
22
|
+
end
|
23
|
+
def delete!()
|
24
|
+
begin
|
25
|
+
puts "Removing file #{@target_file}"
|
26
|
+
File.delete(@target_file) if @target_file
|
27
|
+
rescue
|
28
|
+
end
|
21
29
|
end
|
22
30
|
end
|
data/lib/recording_vdr.rb
CHANGED
@@ -1,21 +1,28 @@
|
|
1
1
|
class RecordingVDR
|
2
2
|
def initialize(recording)
|
3
|
-
|
3
|
+
@parent = recording
|
4
|
+
@target_file = nil
|
4
5
|
end
|
5
6
|
def process!()
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
7
|
+
return false
|
8
|
+
@target_file = @parent.target_dir + "/#{@parent.friendly_name}.ts"
|
9
|
+
FileDir.mkdirtree(@parent.target_dir)
|
10
|
+
tf = File.new(@target_file, 'wb:ascii-8bit')
|
11
|
+
source_files = Dir.glob("#{@parent.directory}/*.ts")
|
12
|
+
source_files.sort!
|
13
|
+
source_files.each { | source_file |
|
14
|
+
sf = File.new(source_file, 'rb:ascii-8bit')
|
15
|
+
while not sf.eof?
|
16
|
+
tf.write(sf.read(1*(2**20))) # Only read some bytes at once
|
17
|
+
sleep(0.01) # Be friendly to other processes
|
18
|
+
end
|
19
|
+
sf.close
|
20
|
+
}
|
21
|
+
end
|
22
|
+
def delete!()
|
23
|
+
begin
|
24
|
+
File.delete(@target_file) if @target_file
|
25
|
+
rescue
|
26
|
+
end
|
20
27
|
end
|
21
28
|
end
|
data/lib/recordings.rb
CHANGED
@@ -19,14 +19,13 @@ class Recordings
|
|
19
19
|
found_directories << directory
|
20
20
|
if @recordings_db[directory] == nil then
|
21
21
|
# Found a new entry
|
22
|
-
|
23
|
-
p add(directory)
|
22
|
+
add(directory)
|
24
23
|
end
|
25
24
|
end
|
26
25
|
end
|
27
26
|
}
|
28
27
|
@recordings_db.each { | recording |
|
29
|
-
|
28
|
+
puts "Removing recording: #{recording}"
|
30
29
|
recording[1].delete! unless found_directories.include?(recording[1].directory)
|
31
30
|
}
|
32
31
|
end
|
@@ -47,11 +46,8 @@ class Recordings
|
|
47
46
|
# TODO: Add a new recording that was found in the specified directory
|
48
47
|
# Ensure that VDR has finished writing the recording by checking the mtime of the index file
|
49
48
|
# Wait at least 30 seconds after VDR has finished
|
50
|
-
p Time.now - File.mtime(directory + '/index')
|
51
49
|
return false unless (Time.now - File.mtime(directory + '/index')) > 30
|
52
|
-
p "Old enough... continuing."
|
53
50
|
@recordings_db[directory] = Recording.new(directory)
|
54
51
|
@recordings_db[directory].process!
|
55
|
-
p @recordings_db[directory]
|
56
52
|
end
|
57
53
|
end
|