Skip to content
Snippets Groups Projects
Commit 0ad8cc94 authored by Julian Rother's avatar Julian Rother
Browse files

Added duration field to videos table and extended rss feed accordingly

parent 4c247d43
No related branches found
No related tags found
No related merge requests found
......@@ -229,7 +229,8 @@ CREATE TABLE IF NOT EXISTS `videos_data` (
`file_size` bigINTEGER NOT NULL DEFAULT '-1',
`video_format` INTEGER NOT NULL,
`hash` varchar(32) NOT NULL,
`source` INTEGER
`source` INTEGER,
`duration` INTEGER NOT NULL
);
CREATE TABLE IF NOT EXISTS `announcements` (
`id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
......
......@@ -35,16 +35,16 @@ def update_video_metadata(jobid, jobtype, data, state, status):
if video['hash'] and video['hash'] != status['hash']:
print('Hash mismatch for video', data['video_id'])
return
modify('UPDATE videos_data SET hash = ?, file_size = ? WHERE id = ?',
status['hash'], status['filesize'], data['video_id'])
modify('UPDATE videos_data SET hash = ?, file_size = ?, duration = ? WHERE id = ?',
status['hash'], status['filesize'], data['duration'], data['video_id'])
def insert_video(lectureid, dbfilepath, fileformatid, hash="", filesize=-1):
def insert_video(lectureid, dbfilepath, fileformatid, hash="", filesize=-1, duration=-1):
visible = query('SELECT courses.autovisible FROM courses JOIN lectures ON lectures.course_id = courses.id WHERE lectures.id = ?', lectureid)[0]['autovisible']
video_id = modify('''INSERT INTO videos_data
(lecture_id, visible, path, video_format, title, comment, internal, file_modified, time_created, time_updated, created_by, hash, file_size)
(lecture_id, visible, path, video_format, title, comment, internal, file_modified, time_created, time_updated, created_by, hash, file_size, duration)
VALUES
(?, ?, ?, ?, "", "", "", ?, ?, ?, ?, ?, ?)''',
lectureid, visible, dbfilepath, fileformatid, datetime.now(), datetime.now(), datetime.now(), -1, hash, filesize)
(?, ?, ?, ?, "", "", "", ?, ?, ?, ?, ?, ?, ?)''',
lectureid, visible, dbfilepath, fileformatid, datetime.now(), datetime.now(), datetime.now(), -1, hash, filesize, duration)
query('INSERT INTO sortlog (lecture_id,video_id,path,`when`) VALUES (?,?,?,?)', lectureid, video_id, dbfilepath, datetime.now())
schedule_thumbnail(lectureid)
schedule_job('probe', {'path': dbfilepath, 'lecture_id': lectureid, 'video_id': video_id, 'import-chapters': True})
......@@ -79,12 +79,12 @@ def insert_transcoded_video(jobid, jobtype, data, state, status):
return
visible = query('SELECT courses.autovisible FROM courses JOIN lectures ON lectures.course_id = courses.id WHERE lectures.id = ?', data['lecture_id'])[0]['autovisible']
video_id = modify('''INSERT INTO videos_data
(lecture_id, visible, path, video_format, title, comment, internal, file_modified, time_created, time_updated, created_by, hash, file_size, source)
(lecture_id, visible, path, video_format, title, comment, internal, file_modified, time_created, time_updated, created_by, hash, file_size, source, duration)
VALUES
(?, ?, ?, ?, "", "", "", ?, ?, ?, ?, ?, ?, ?)''',
(?, ?, ?, ?, "", "", "", ?, ?, ?, ?, ?, ?, ?, ?)''',
data['lecture_id'], visible, data['output']['path'], data['format_id'],
datetime.now(), datetime.now(), datetime.now(), -1, status['hash'],
status['filesize'], data['source_id'])
status['filesize'], status['duration'], data['source_id'])
schedule_thumbnail(data['lecture_id'])
video = query('SELECT videos.*, "format" AS sep, formats.* FROM videos JOIN formats ON formats.id = videos.video_format WHERE videos.id = ?', video_id)[0]
lecture = query('SELECT * FROM lectures WHERE id = ?', data['lecture_id'])[0]
......@@ -221,7 +221,7 @@ def sort_autoencode():
def handle_published_video(jobid, jobtype, data, state, status):
if 'lecture_id' not in data or 'format_id' not in data:
return
insert_video(data['lecture_id'], data['path'], data['format_id'], hash=status['hash'], filesize=status['filesize'])
insert_video(data['lecture_id'], data['path'], data['format_id'], hash=status['hash'], filesize=status['filesize'], duration=status['duration'])
@app.route('/internal/sort/now')
@mod_required
......
......@@ -18,7 +18,7 @@
{% endif %}
{%- endmacro %}
<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:psc="http://podlove.org/simple-chapters" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
<rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:psc="http://podlove.org/simple-chapters" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" version="2.0">
<channel>
<title>{{ title(format) }}</title>
<link>{{ url_for('course', handle=course.handle, _external=True) }}</link>
......@@ -48,6 +48,9 @@
{% if item.speaker and item.speaker != course.organizer %}
<dc:creator>{{ item.speaker|e }}</dc:creator>
{% endif %}
{% if item.video.duration > 0 %}
<itunes:duration>{{ item.video.duration }}</itunes:duration>
{% endif %}
<psc:chapters xmlns:psc="http://podlove.org/simple-chapters" version="1.2">
{% for chapter in chapters|selectattr('lecture_id','equalto',item.id) %}
<psc:chapter start="{{ chapter.time }}" title="{{ chapter.text }}"/>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment