8 def __init__(self, data = None):
9 # File or directory containing content
11 # True if content is in DVD format
15 # Directory containing metadata
19 # Number of pixels by which to crop the content from each edge
24 # Use deinterlacing filter
25 self.deinterlace = False
28 # Audio stream ID to play
38 f = open(os.path.join(self.data, 'info'), 'r')
53 elif key == 'content':
56 self.dvd = int(value) == 1
57 elif key == 'dvd_title':
58 self.dvd_title = int(value)
59 elif key == 'left_crop':
60 self.left_crop = int(value)
61 elif key == 'top_crop':
62 self.top_crop = int(value)
63 elif key == 'right_crop':
64 self.right_crop = int(value)
65 elif key == 'bottom_crop':
66 self.bottom_crop = int(value)
67 elif key == 'deinterlace':
68 self.deinterlace = int(value) == 1
70 self.ratio = float(value)
74 self.width = int(value)
76 self.height = int(value)
78 self.fps = float(value)
80 self.length = float(value)
82 if self.width is None or self.height is None or self.fps is None or self.length is None:
83 self.update_content_metadata()
91 f = open(os.path.join(self.data, 'info'), 'w')
92 self.write_datum(f, 'name', self.name)
93 self.write_datum(f, 'content', self.content)
94 self.write_datum(f, 'dvd', int(self.dvd))
95 self.write_datum(f, 'dvd_title', self.dvd_title)
96 self.write_datum(f, 'left_crop', self.left_crop)
97 self.write_datum(f, 'top_crop', self.top_crop)
98 self.write_datum(f, 'right_crop', self.right_crop)
99 self.write_datum(f, 'bottom_crop', self.bottom_crop)
100 self.write_datum(f, 'deinterlace', int(self.deinterlace))
101 self.write_datum(f, 'ratio', self.ratio)
102 self.write_datum(f, 'aid', self.aid)
103 self.write_datum(f, 'width', self.width)
104 self.write_datum(f, 'height', self.height)
105 self.write_datum(f, 'fps', self.fps)
106 self.write_datum(f, 'length', self.length)
108 def write_datum(self, f, key, value):
109 if value is not None:
110 print >>f,'%s %s' % (key, str(value))
112 def thumbs_dir(self):
113 t = os.path.join(self.data, 'thumbs')
123 return os.path.join(self.thumbs_dir(), str('%08d.png' % (n + 1)))
126 return len(os.listdir(self.thumbs_dir()))
128 def remove_thumbs(self):
129 shutil.rmtree(self.thumbs_dir())
131 def make_thumbs(self):
133 cl = self.player_command_line()
134 if self.length is not None:
135 sstep = self.length / num_thumbs
138 cl.extra = '-vo png -frames %d -sstep %d -nosound' % (num_thumbs, sstep)
139 os.chdir(self.thumbs_dir())
140 os.system(cl.get(True))
142 def set_dvd(self, d):
146 def set_dvd_title(self, t):
150 def set_content(self, c):
151 if c == self.content:
155 self.update_content_metadata()
157 def player_command_line(self):
158 cl = player.CommandLine()
160 cl.dvd_title = self.dvd_title
161 cl.content = self.content
164 def update_content_metadata(self):
165 if self.content is None:
173 cl = self.player_command_line()
174 cl.extra = '-identify -vo null -ao null -frames 0'
175 text = subprocess.check_output(shlex.split(cl.get(True))).decode('utf-8')
176 lines = text.split('\n')
181 if b[0] == 'ID_VIDEO_WIDTH':
182 self.width = int(b[1])
183 elif b[0] == 'ID_VIDEO_HEIGHT':
184 self.height = int(b[1])
185 elif b[0] == 'ID_VIDEO_FPS':
186 self.fps = float(b[1])
187 elif b[0] == 'ID_LENGTH':
188 self.length = float(b[1])