rubyVDRconvert 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/recording.rb +65 -61
- data/lib/recordings.rb +40 -38
- metadata +3 -3
data/lib/recording.rb
CHANGED
@@ -7,79 +7,83 @@ require 'file_dir'
|
|
7
7
|
class Recording
|
8
8
|
attr_reader :directory, :target_dir, :processed, :friendly_name
|
9
9
|
def initialize(directory)
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
10
|
+
@mutex = Mutex.new
|
11
|
+
@directory = directory
|
12
|
+
@recording = nil
|
13
|
+
@title = nil
|
14
|
+
@subtitle = nil
|
15
|
+
@friendly_name = nil
|
16
|
+
@recording_time = nil
|
17
|
+
@target_dir = nil
|
18
|
+
@processed = false
|
19
|
+
@timestamp = File.mtime(@directory + '/index')
|
20
|
+
load_info
|
21
|
+
determine_stream_type
|
22
|
+
p "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 ]
|
26
26
|
end
|
27
27
|
def marshal_load(variables)
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
28
|
+
@mutex = Mutex.new
|
29
|
+
@directory = variables[0]
|
30
|
+
@recording = variables[1]
|
31
|
+
@friendly_name = variables[4]
|
32
|
+
@target_dir = variables[5]
|
33
|
+
@processed = variables[6]
|
34
|
+
@timestamp = variables[7]
|
35
|
+
load_info
|
36
36
|
|
37
37
|
end
|
38
38
|
def delete!()
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
39
|
+
@mutex.synchronize {
|
40
|
+
@recording = nil
|
41
|
+
GC.start
|
42
|
+
p "Deleting....", self, @target_dir
|
43
|
+
FileDir.delete!(@target_dir)
|
44
|
+
}
|
45
45
|
end
|
46
46
|
def load_info()
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
47
|
+
begin
|
48
|
+
info = File.read(@directory + '/info')
|
49
|
+
rescue
|
50
|
+
return
|
51
|
+
end
|
52
|
+
info.each_line { | line |
|
53
|
+
case line[0..1]
|
54
|
+
when 'T '
|
55
|
+
@title = line[2..256].chomp
|
56
|
+
p "Found title: #{@title}"
|
57
|
+
when 'S '
|
58
|
+
@subtitle = line[2..256].chomp
|
59
|
+
p "Found subtitle: #{@subtitle}"
|
60
|
+
when 'E '
|
61
|
+
@recording_time = Time.at(line.split[2].to_i)
|
62
|
+
end
|
63
|
+
}
|
64
|
+
@title = 'Unknown' if not @title
|
65
|
+
@subtitle = 'Unknown' if not @subtitle
|
66
|
+
title = @title
|
67
|
+
subtitle = @subtitle
|
68
|
+
title.gsub!('/', '!')
|
69
|
+
subtitle.gsub!('/', '!')
|
70
|
+
@target_dir = "/video/#{title}/#{subtitle}"
|
71
|
+
@friendly_name = "#{@recording_time.strftime("%y%m%d-%H%M")} - #{title}"
|
68
72
|
end
|
69
73
|
def determine_stream_type()
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
74
|
+
case
|
75
|
+
when File.file?(@directory + '/00001.ts')
|
76
|
+
@recording = RecordingTS.new(self)
|
77
|
+
when File.file?(@directory + '/00001.vdr')
|
78
|
+
@recording = RecordingVDR.new(self)
|
79
|
+
else
|
80
|
+
raise 'Unknown recording'
|
81
|
+
end
|
78
82
|
end
|
79
83
|
def process!()
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
+
p "Starting processing of #{@friendly_name}"
|
85
|
+
@mutex.synchronize{
|
86
|
+
@processed = true if @recording.process!
|
87
|
+
}
|
84
88
|
end
|
85
89
|
end
|
data/lib/recordings.rb
CHANGED
@@ -5,51 +5,53 @@ require 'recording'
|
|
5
5
|
|
6
6
|
class Recordings
|
7
7
|
def initialize()
|
8
|
-
|
8
|
+
@recordings_db = Hash.new
|
9
9
|
end
|
10
10
|
def scan()
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
11
|
+
basedir = '/vdr'
|
12
|
+
found_directories = Array.new
|
13
|
+
Find.find(basedir) { | entry |
|
14
|
+
entry.force_encoding('BINARY')
|
15
|
+
# Look for the index file created by VDR
|
16
|
+
if File.basename(entry) == "index" then
|
17
|
+
directory = File.dirname(entry)
|
18
|
+
unless directory.end_with?('.del') # These directories have been marked as deleted from VDR...
|
19
|
+
found_directories << directory
|
20
|
+
if @recordings_db[directory] == nil then
|
21
|
+
# Found a new entry
|
22
|
+
p directory
|
23
|
+
p add(directory)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
}
|
28
|
+
@recordings_db.each { | recording |
|
29
|
+
p recording.class, recording
|
30
|
+
recording[1].delete! unless found_directories.include?(recording[1].directory)
|
31
|
+
}
|
30
32
|
end
|
31
33
|
def dump()
|
32
|
-
|
33
|
-
|
34
|
-
|
34
|
+
File.open('/vdr/rubyVDRconvert.recordings.marshal', 'wb:ascii-8bit') { | f |
|
35
|
+
f.write(Marshal.dump(@recordings_db))
|
36
|
+
}
|
35
37
|
end
|
36
38
|
def load()
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
39
|
+
begin
|
40
|
+
data = File.read('/vdr/rubyVDRconvert.recordings.marshal')
|
41
|
+
@recordings_db = Marshal.load(data)
|
42
|
+
rescue
|
43
|
+
@recordings_db = Hash.new
|
44
|
+
end
|
43
45
|
end
|
44
46
|
def add(directory)
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
47
|
+
# TODO: Add a new recording that was found in the specified directory
|
48
|
+
# Ensure that VDR has finished writing the recording by checking the mtime of the index file
|
49
|
+
# Wait at least 30 seconds after VDR has finished
|
50
|
+
p Time.now - File.mtime(directory + '/index')
|
51
|
+
return false unless (Time.now - File.mtime(directory + '/index')) > 30
|
52
|
+
p "Old enough... continuing."
|
53
|
+
@recordings_db[directory] = Recording.new(directory)
|
54
|
+
@recordings_db[directory].process!
|
55
|
+
p @recordings_db[directory]
|
54
56
|
end
|
55
57
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 7
|
9
|
+
version: 0.0.7
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Daniel Frank
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-
|
17
|
+
date: 2010-12-07 00:00:00 +01:00
|
18
18
|
default_executable:
|
19
19
|
dependencies: []
|
20
20
|
|