Setting 0.8.2.dev in configure.ac as well
[larjonas-mediagoblin.git] / mediagoblin / media_types / video / models.py
blob4d539e7bf47eadd34af54809fa1784929002ae1c
1 # GNU MediaGoblin -- federated, autonomous media hosting
2 # Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS.
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU Affero General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU Affero General Public License for more details.
14 # You should have received a copy of the GNU Affero General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 from mediagoblin.db.base import Base
20 from sqlalchemy import (
21 Column, Integer, SmallInteger, ForeignKey)
22 from sqlalchemy.orm import relationship, backref
23 from mediagoblin.db.extratypes import JSONEncoded
24 from mediagoblin.media_types import video
27 BACKREF_NAME = "video__media_data"
30 class VideoData(Base):
31 """
32 Attributes:
33 - media_data: the originating media entry (of course)
34 - width: width of the transcoded video
35 - height: height of the transcoded video
36 - orig_metadata: A loose json structure containing metadata gstreamer
37 pulled from the original video.
38 This field is NOT GUARANTEED to exist!
40 Likely metadata extracted:
41 "videoheight", "videolength", "videowidth",
42 "audiorate", "audiolength", "audiochannels", "audiowidth",
43 "mimetype", "tags"
45 TODO: document the above better.
46 """
47 __tablename__ = "video__mediadata"
49 # The primary key *and* reference to the main media_entry
50 media_entry = Column(Integer, ForeignKey('core__media_entries.id'),
51 primary_key=True)
52 get_media_entry = relationship("MediaEntry",
53 backref=backref(BACKREF_NAME, uselist=False,
54 cascade="all, delete-orphan"))
56 width = Column(SmallInteger)
57 height = Column(SmallInteger)
59 orig_metadata = Column(JSONEncoded)
61 def source_type(self):
62 """
63 Construct a useful type=... that is to say, used like:
64 <video><source type="{{ entry.media_data.source_type() }}" /></video>
66 Try to construct it out of self.orig_metadata... if we fail we
67 just dope'ily fall back on DEFAULT_WEBM_TYPE
68 """
69 orig_metadata = self.orig_metadata or {}
71 if ("webm_video" not in self.get_media_entry.media_files
72 and "mimetype" in orig_metadata['common']['tags']
73 and "codec" in orig_metadata['audio']
74 and "codec" in orig_metadata['video']):
75 if orig_metadata['mimetype'] == 'application/ogg':
76 # stupid ambiguous .ogg extension
77 mimetype = "video/ogg"
78 else:
79 mimetype = orig_metadata['common']['tags']['mimetype']
81 video_codec = orig_metadata["video"]["codec"].lower()
82 audio_codec = orig_metadata["audio"]["codec"].lower()
84 # We don't want the "video" at the end of vp8...
85 # not sure of a nicer way to be cleaning this stuff
86 if video_codec == "vp8 video":
87 video_codec = "vp8"
89 return '%s; codecs="%s, %s"' % (
90 mimetype, video_codec, audio_codec)
91 else:
92 return video.VideoMediaManager.default_webm_type
95 DATA_MODEL = VideoData
96 MODELS = [VideoData]