src/ldt/ldt/ldt_utils/segmentserializer.py
author cavaliet
Thu, 10 Apr 2014 15:55:47 +0200
changeset 1296 1a24fb79eb11
parent 1257 d2cc6ecc3aa0
child 1364 fb0046d64c82
permissions -rw-r--r--
v1.53 : tagging to taggit migration
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
412
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
     1
from django.conf import settings
479
1cbfcfcb2a47 Objects serializer send correct stats
verrierj
parents: 468
diff changeset
     2
from ldt.ldt_utils.stat import get_string_from_buckets
482
c802e00c7131 Lot of bugfixes
verrierj
parents: 479
diff changeset
     3
from ldt.security.utils import use_forbidden_url
1093
03104d3f6ca1 Requests optimisations
ymh <ymh.work@gmail.com>
parents: 877
diff changeset
     4
import logging
415
4236f99104ba Annotation-types title are found in search API
verrierj
parents: 412
diff changeset
     5
import lxml.etree
412
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
     6
import uuid
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
     7
1093
03104d3f6ca1 Requests optimisations
ymh <ymh.work@gmail.com>
parents: 877
diff changeset
     8
logger = logging.getLogger(__name__)
03104d3f6ca1 Requests optimisations
ymh <ymh.work@gmail.com>
parents: 877
diff changeset
     9
412
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
    10
DATE_FORMATS = ["%d/%m/%Y", "%Y-%m-%d"]
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
    11
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
    12
class SegmentSerializer(object):
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
    13
    """
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
    14
    Serialize a set of annotations to a cinelab compatible array
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
    15
    """
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
    16
    
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
    17
    def __init__(self, content, segments, viewable_contents=[], default_color=2194379):
420
38e46b1d0bd3 Small bugfixes
verrierj
parents: 415
diff changeset
    18
        """
38e46b1d0bd3 Small bugfixes
verrierj
parents: 415
diff changeset
    19
        viewable_contents should contain all contents from project that a user is allowed to see. The settings.FORBIDDDEN_STREAM_URL
38e46b1d0bd3 Small bugfixes
verrierj
parents: 415
diff changeset
    20
        will be displayed if a content is not found in viewable_contents, and the real stream will be displayed if it is. 
38e46b1d0bd3 Small bugfixes
verrierj
parents: 415
diff changeset
    21
        """
412
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
    22
        self.content = content
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
    23
        self.segments = segments
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
    24
        self.viewable_contents = viewable_contents
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
    25
        self.default_color = default_color
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
    26
        self.views = None
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
    27
        self.annotation_types = None
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
    28
        self.medias = None
426
4328cd4a7533 refactor modal windows + add translations
verrierj
parents: 424
diff changeset
    29
        self.annotations = None 
4328cd4a7533 refactor modal windows + add translations
verrierj
parents: 424
diff changeset
    30
        self.tags = {}
4328cd4a7533 refactor modal windows + add translations
verrierj
parents: 424
diff changeset
    31
               
415
4236f99104ba Annotation-types title are found in search API
verrierj
parents: 412
diff changeset
    32
        self.xml_docs = {}
4236f99104ba Annotation-types title are found in search API
verrierj
parents: 412
diff changeset
    33
        
1093
03104d3f6ca1 Requests optimisations
ymh <ymh.work@gmail.com>
parents: 877
diff changeset
    34
    def __get_cutting_title(self, project_id, content_id, ensemble_id, cutting_id, project):
415
4236f99104ba Annotation-types title are found in search API
verrierj
parents: 412
diff changeset
    35
        
4236f99104ba Annotation-types title are found in search API
verrierj
parents: 412
diff changeset
    36
        if not self.xml_docs.has_key(project_id):
532
155456f99f3d Projectserializer can add an extra annotation-type and its annotations to the serialization of a view
verrierj
parents: 482
diff changeset
    37
            if not project:
155456f99f3d Projectserializer can add an extra annotation-type and its annotations to the serialization of a view
verrierj
parents: 482
diff changeset
    38
                return None
560
1cb2a4a573e1 correct annoations api handler + ldt encoding
ymh <ymh.work@gmail.com>
parents: 532
diff changeset
    39
            doc = lxml.etree.fromstring(project.ldt_encoded)
415
4236f99104ba Annotation-types title are found in search API
verrierj
parents: 412
diff changeset
    40
            self.xml_docs[project_id] = doc
4236f99104ba Annotation-types title are found in search API
verrierj
parents: 412
diff changeset
    41
        else:
4236f99104ba Annotation-types title are found in search API
verrierj
parents: 412
diff changeset
    42
            doc = self.xml_docs[project_id]
4236f99104ba Annotation-types title are found in search API
verrierj
parents: 412
diff changeset
    43
              
426
4328cd4a7533 refactor modal windows + add translations
verrierj
parents: 424
diff changeset
    44
        cutting = doc.xpath('/iri/annotations/content[@id=\'%s\']/ensemble[@id=\'%s\']/decoupage[@id=\'%s\']/title' % (content_id, ensemble_id, cutting_id))
4328cd4a7533 refactor modal windows + add translations
verrierj
parents: 424
diff changeset
    45
        if not cutting:
4328cd4a7533 refactor modal windows + add translations
verrierj
parents: 424
diff changeset
    46
            return None
4328cd4a7533 refactor modal windows + add translations
verrierj
parents: 424
diff changeset
    47
        
4328cd4a7533 refactor modal windows + add translations
verrierj
parents: 424
diff changeset
    48
        cutting = cutting[0]
415
4236f99104ba Annotation-types title are found in search API
verrierj
parents: 412
diff changeset
    49
        
4236f99104ba Annotation-types title are found in search API
verrierj
parents: 412
diff changeset
    50
        return cutting.text       
412
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
    51
    
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
    52
    def __parse_views(self):
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
    53
        
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
    54
        view = {
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
    55
                "id": "0",
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
    56
                "contents": [
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
    57
                    self.content.iri_id
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
    58
                ],
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
    59
                "annotation_types": [ ],
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
    60
        }
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
    61
        
424
a2f72b31811b Add french translations + small bugfixes
verrierj
parents: 420
diff changeset
    62
        stat = {
a2f72b31811b Add french translations + small bugfixes
verrierj
parents: 420
diff changeset
    63
                "id": "stat",
a2f72b31811b Add french translations + small bugfixes
verrierj
parents: 420
diff changeset
    64
                "contents": [
a2f72b31811b Add french translations + small bugfixes
verrierj
parents: 420
diff changeset
    65
                    self.content.iri_id
a2f72b31811b Add french translations + small bugfixes
verrierj
parents: 420
diff changeset
    66
                ],
a2f72b31811b Add french translations + small bugfixes
verrierj
parents: 420
diff changeset
    67
                "meta": {
479
1cbfcfcb2a47 Objects serializer send correct stats
verrierj
parents: 468
diff changeset
    68
                    "stat": get_string_from_buckets(self.content.annotation_volume)
424
a2f72b31811b Add french translations + small bugfixes
verrierj
parents: 420
diff changeset
    69
                }
a2f72b31811b Add french translations + small bugfixes
verrierj
parents: 420
diff changeset
    70
        }
a2f72b31811b Add french translations + small bugfixes
verrierj
parents: 420
diff changeset
    71
        
412
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
    72
        self.annotation_types = []
415
4236f99104ba Annotation-types title are found in search API
verrierj
parents: 412
diff changeset
    73
4236f99104ba Annotation-types title are found in search API
verrierj
parents: 412
diff changeset
    74
        annotation_types = []        
4236f99104ba Annotation-types title are found in search API
verrierj
parents: 412
diff changeset
    75
        for seg in self.segments:
1093
03104d3f6ca1 Requests optimisations
ymh <ymh.work@gmail.com>
parents: 877
diff changeset
    76
            title = self.__get_cutting_title(seg.project_id, seg.iri_id, seg.ensemble_id, seg.cutting_id, seg.project_obj)
415
4236f99104ba Annotation-types title are found in search API
verrierj
parents: 412
diff changeset
    77
            annotation_types.append({'id': seg.cutting_id, 'title': title})
4236f99104ba Annotation-types title are found in search API
verrierj
parents: 412
diff changeset
    78
        
412
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
    79
        for a in annotation_types:
426
4328cd4a7533 refactor modal windows + add translations
verrierj
parents: 424
diff changeset
    80
                                            
415
4236f99104ba Annotation-types title are found in search API
verrierj
parents: 412
diff changeset
    81
            view['annotation_types'].append(a['id'])
412
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
    82
            self.annotation_types.append({
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
    83
                    "dc:contributor": "undefined",
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
    84
                    "dc:creator": "undefined",
415
4236f99104ba Annotation-types title are found in search API
verrierj
parents: 412
diff changeset
    85
                    "dc:title": a['title'],
4236f99104ba Annotation-types title are found in search API
verrierj
parents: 412
diff changeset
    86
                    "id": a['id'],
412
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
    87
                    "dc:created": "",
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
    88
                    "dc:description": "",
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
    89
                    "dc:modified": ""
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
    90
                })
415
4236f99104ba Annotation-types title are found in search API
verrierj
parents: 412
diff changeset
    91
            
412
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
    92
        
424
a2f72b31811b Add french translations + small bugfixes
verrierj
parents: 420
diff changeset
    93
        self.views = [view, stat]
412
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
    94
        
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
    95
    
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
    96
    def __parse_content(self):
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
    97
        
572
10c26c22b76a Replace href by url in JSON
verrierj
parents: 560
diff changeset
    98
        url = ""
412
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
    99
        meta_item_value = ""
1257
d2cc6ecc3aa0 merge all content's projects in one (for decoupage).
cavaliet
parents: 1190
diff changeset
   100
        
482
c802e00c7131 Lot of bugfixes
verrierj
parents: 479
diff changeset
   101
        if use_forbidden_url(self.content):
572
10c26c22b76a Replace href by url in JSON
verrierj
parents: 560
diff changeset
   102
            url = settings.FORBIDDEN_STREAM_URL
412
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   103
        elif self.content.videopath:
572
10c26c22b76a Replace href by url in JSON
verrierj
parents: 560
diff changeset
   104
            url = self.content.videopath.rstrip('/') + "/" + self.content.src
412
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   105
            meta_item_value = self.content.videopath.rstrip('/') + "/"
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   106
        else:
572
10c26c22b76a Replace href by url in JSON
verrierj
parents: 560
diff changeset
   107
            url = self.content.src
412
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   108
        
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   109
        media = {
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   110
             "http://advene.liris.cnrs.fr/ns/frame_of_reference/ms" : "o=0",
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   111
             "id" : self.content.iri_id,
572
10c26c22b76a Replace href by url in JSON
verrierj
parents: 560
diff changeset
   112
             "url" : url,
412
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   113
             "unit" : "ms",
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   114
             "origin" : "0",
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   115
             "meta": {
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   116
                 "dc:creator" : "",
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   117
                 "dc:created" : self.content.creation_date.isoformat(),
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   118
                 "dc:contributor" : "",
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   119
                 "dc:modified" : self.content.update_date.isoformat(),
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   120
                 "dc:creator.contents" : "",
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   121
                 "dc:title" : self.content.title,
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   122
                 "dc:description" : self.content.description,
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   123
                 "dc:duration" : self.content.get_duration(),
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   124
                 "item": {
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   125
                     "name" : "streamer",
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   126
                     "value": meta_item_value,
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   127
                 },
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   128
             }
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   129
        }
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   130
        
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   131
        self.medias = [media]
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   132
        
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   133
    
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   134
    def __parse_segments(self):
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   135
        
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   136
        self.annotations = []
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   137
        
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   138
        for seg in self.segments:
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   139
            
426
4328cd4a7533 refactor modal windows + add translations
verrierj
parents: 424
diff changeset
   140
            segment_tags = []
1296
1a24fb79eb11 v1.53 : tagging to taggit migration
cavaliet
parents: 1257
diff changeset
   141
            for tag in [t.name for t in seg.tags.all()]:
426
4328cd4a7533 refactor modal windows + add translations
verrierj
parents: 424
diff changeset
   142
                if not self.tags.has_key(tag):
4328cd4a7533 refactor modal windows + add translations
verrierj
parents: 424
diff changeset
   143
                    new_tag = {
4328cd4a7533 refactor modal windows + add translations
verrierj
parents: 424
diff changeset
   144
                        "meta": {
4328cd4a7533 refactor modal windows + add translations
verrierj
parents: 424
diff changeset
   145
                            "dc:contributor": "IRI",
4328cd4a7533 refactor modal windows + add translations
verrierj
parents: 424
diff changeset
   146
                            "dc:created": seg.date,
4328cd4a7533 refactor modal windows + add translations
verrierj
parents: 424
diff changeset
   147
                            "dc:title": tag,
4328cd4a7533 refactor modal windows + add translations
verrierj
parents: 424
diff changeset
   148
                            "dc:modified": seg.date,
4328cd4a7533 refactor modal windows + add translations
verrierj
parents: 424
diff changeset
   149
                            "dc:creator": "IRI"
4328cd4a7533 refactor modal windows + add translations
verrierj
parents: 424
diff changeset
   150
                        },
4328cd4a7533 refactor modal windows + add translations
verrierj
parents: 424
diff changeset
   151
                        "id": unicode(uuid.uuid1())
4328cd4a7533 refactor modal windows + add translations
verrierj
parents: 424
diff changeset
   152
                    }
4328cd4a7533 refactor modal windows + add translations
verrierj
parents: 424
diff changeset
   153
                    self.tags[tag] = new_tag
4328cd4a7533 refactor modal windows + add translations
verrierj
parents: 424
diff changeset
   154
                segment_tags.append({'id-ref': self.tags[tag]['id']})
4328cd4a7533 refactor modal windows + add translations
verrierj
parents: 424
diff changeset
   155
            
412
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   156
            segment = {
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   157
                'begin': seg.start_ts,
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   158
                'end': seg.start_ts + seg.duration,
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   159
                'tags': seg.tags,
427
e0158472f83a Fix pluralized translations + clean-up segmentserializer
verrierj
parents: 426
diff changeset
   160
                'id': seg.element_id,
412
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   161
                'color': "%s" % self.default_color,
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   162
                'media': self.content.iri_id,
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   163
                'content': {
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   164
                    'mimetype': 'application/x-ldt-structured',
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   165
                    'description': seg.abstract,
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   166
                    'img': {
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   167
                        'src': ''
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   168
                    },
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   169
                    'title': seg.title,
427
e0158472f83a Fix pluralized translations + clean-up segmentserializer
verrierj
parents: 426
diff changeset
   170
                    'color': self.default_color,
412
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   171
                    'polemics': [ ],
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   172
                    'audio': {
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   173
                        'mimetype': 'audio/mp3',
810
e7546394653c add audio annotation to segment api and correct reindex command.
cavaliet
parents: 572
diff changeset
   174
                        'src': seg.audio_src,
e7546394653c add audio annotation to segment api and correct reindex command.
cavaliet
parents: 572
diff changeset
   175
                        'href': seg.audio_href
412
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   176
                    }
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   177
                
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   178
                },
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   179
                'meta': {
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   180
                         "dc:creator": seg.author,
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   181
                         "dc:contributor": seg.author,
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   182
                         "dc:created": seg.date,
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   183
                         "dc:modified": seg.date,
427
e0158472f83a Fix pluralized translations + clean-up segmentserializer
verrierj
parents: 426
diff changeset
   184
                         "id-ref": seg.cutting_id,
412
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   185
                         "project": seg.project_id
426
4328cd4a7533 refactor modal windows + add translations
verrierj
parents: 424
diff changeset
   186
                },
4328cd4a7533 refactor modal windows + add translations
verrierj
parents: 424
diff changeset
   187
                'tags': segment_tags                       
412
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   188
            }
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   189
            
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   190
            self.annotations.append(segment)
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   191
    
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   192
    def serialize_to_cinelab(self):
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   193
        
426
4328cd4a7533 refactor modal windows + add translations
verrierj
parents: 424
diff changeset
   194
        if not self.segments:
4328cd4a7533 refactor modal windows + add translations
verrierj
parents: 424
diff changeset
   195
            return None
4328cd4a7533 refactor modal windows + add translations
verrierj
parents: 424
diff changeset
   196
        
412
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   197
        self.__parse_content()
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   198
        self.__parse_segments()
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   199
        self.__parse_views()
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   200
        
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   201
        res = {}
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   202
        res['views'] = self.views 
426
4328cd4a7533 refactor modal windows + add translations
verrierj
parents: 424
diff changeset
   203
        res['tags'] = self.tags.values() if len(self.tags) > 0 else None
412
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   204
        res['lists'] = None
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   205
        res['medias'] = self.medias
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   206
        res['annotations'] = self.annotations
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   207
        res['annotation-types'] = self.annotation_types
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   208
        
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   209
        return res
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   210