diff --git a/db_schema.sql b/db_schema.sql index 30c5c5827f9d5a9d5b8c5281094d98daac3149a1..503102d79aff48c0134c8a4b86439f52d87d0308 100644 --- a/db_schema.sql +++ b/db_schema.sql @@ -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, diff --git a/sorter.py b/sorter.py index 31ae38a3095a7f452bd5ccc371a73e81e1b1e114..44eb20c9a1d7d2e3af97b8ca05b5f0c68f9b7ebd 100644 --- a/sorter.py +++ b/sorter.py @@ -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 diff --git a/templates/feed.rss b/templates/feed.rss index f3c987193d7831ff09d4943ad6a8c9305997702a..4dd51930991a300ce1fb1f1fd9cf4503005cc2d5 100644 --- a/templates/feed.rss +++ b/templates/feed.rss @@ -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 }}"/>