[Debconf-video-commits] r729 - package/trunk/src/prerolls

Ben Hutchings benh at alioth.debian.org
Sun Nov 6 16:41:50 UTC 2011


Author: benh
Date: 2011-11-06 16:41:49 +0000 (Sun, 06 Nov 2011)
New Revision: 729

Added:
   package/trunk/src/prerolls/insert_prerolls.py
Log:
Add script to insert preroll files as recordings in the database

Added: package/trunk/src/prerolls/insert_prerolls.py
===================================================================
--- package/trunk/src/prerolls/insert_prerolls.py	                        (rev 0)
+++ package/trunk/src/prerolls/insert_prerolls.py	2011-11-06 16:41:49 UTC (rev 729)
@@ -0,0 +1,87 @@
+#!/usr/bin/python
+
+import mx.DateTime
+import os.path
+import sys
+
+if __name__ == '__main__':
+    sys.path.insert(0, '/usr/share/debconf-video-store')
+from debconfvideo import config, database
+
+def timestamp(s):
+    return mx.DateTime.strptime(s, '%Y-%m-%d %H:%M:%S')
+
+def main():
+    cur = database.get_cursor()
+
+    cur.execute('SELECT conference_id FROM conference'
+                ' WHERE title = %(title)s',
+                {'title': config['CONFERENCE_NAME']})
+    conf_id = cur.fetchone()[0]
+
+    # XXX should be in configuration
+    preroll_duration = mx.DateTime.DateTimeDeltaFromSeconds(5)
+
+    # For all recorded events in this conference, find whether they
+    # have a pre-roll and what the earliest recording time is.
+    event_info = {}
+    cur.execute("""
+SELECT event.event_id, event.conference_room, recording_filename, recording_time
+FROM event, video_event_recording, video_recording
+WHERE event.event_id = video_event_recording.event_id
+      AND video_event_recording.recording_id = video_recording.id
+      AND event.conference_id = %(conf_id)s
+""",
+                {'conf_id': conf_id})
+    for event_id, conf_room, rec_filename, rec_time in cur.fetchall():
+        rec_time = timestamp(rec_time)
+        try:
+            preroll_filename, min_rec_time = event_info[event_id][1:]
+        except KeyError:
+            preroll_filename, min_rec_time = None, None
+        if min_rec_time is None or rec_time < min_rec_time:
+            min_rec_time = rec_time
+        if rec_filename.endswith('_preroll.dv'):
+            preroll_filename = rec_filename
+        event_info[event_id] = conf_room, preroll_filename, min_rec_time
+
+    # Insert 'recording' for each preroll file that exists and is not
+    # yet in the database.  Warn about each missing preroll file.
+    for event_id, (conf_room, preroll_filename, min_rec_time) \
+            in event_info.items():
+        insert_preroll = preroll_filename is None
+        if insert_preroll:
+            preroll_filename = os.path.abspath('%s_preroll.dv' % event_id)
+        if not os.path.isfile(preroll_filename):
+            print >>sys.stderr, 'WARN: No such file', preroll_filename
+        else if insert_preroll:
+            cur.execute("""
+INSERT INTO video_recording(recording_time, recording_filename,
+                            file_status_id, recording_duration,
+                            conference_id, conference_room)
+VALUES (%(preroll_time)s, %(preroll_filename)s,
+        (SELECT id FROM video_file_status WHERE file_status_code = 'A'),
+        %(preroll_duration)s, %(conf_id)s, %(conf_room)s)
+""",
+                        {'preroll_time': str(min_rec_time - preroll_duration),
+                         'preroll_filename': preroll_filename,
+                         'preroll_duration': str(preroll_duration),
+                         'conf_id': conf_id,
+                         'conf_room': conf_room})
+            # XXX Shouldn't we be able to get the new id as a result
+            # of running the above statement?
+            cur.execute("""
+INSERT INTO video_event_recording(event_id, recording_id, start_time, end_time)
+VALUES (%(event_id)s,
+        (SELECT id FROM video_recording
+         WHERE recording_filename = %(preroll_filename)s),
+        '00:00:00', %(preroll_duration)s)
+""",
+                        {'event_id': event_id,
+                         'preroll_filename': preroll_filename,
+                         'preroll_duration': str(preroll_duration)})
+
+    cur.execute("COMMIT")
+
+if __name__ == '__main__':
+    main()


Property changes on: package/trunk/src/prerolls/insert_prerolls.py
___________________________________________________________________
Added: svn:executable
   + *




More information about the Debconf-video-commits mailing list