src/ldt/ldt/ldt_utils/segmentserializer.py
author ymh <ymh.work@gmail.com>
Thu, 07 Feb 2013 13:41:49 +0100
changeset 1093 03104d3f6ca1
parent 877 50d333d90541
child 1190 129d45eec68c
permissions -rw-r--r--
Requests optimisations
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
415
4236f99104ba Annotation-types title are found in search API
verrierj
parents: 412
diff changeset
     2
from ldt.ldt_utils.models import Project
479
1cbfcfcb2a47 Objects serializer send correct stats
verrierj
parents: 468
diff changeset
     3
from ldt.ldt_utils.stat import get_string_from_buckets
482
c802e00c7131 Lot of bugfixes
verrierj
parents: 479
diff changeset
     4
from ldt.security.utils import use_forbidden_url
876
8fd46e270e23 correct segment tag parsing and remove useless import.
cavaliet
parents: 810
diff changeset
     5
from tagging.utils import parse_tag_input
1093
03104d3f6ca1 Requests optimisations
ymh <ymh.work@gmail.com>
parents: 877
diff changeset
     6
import logging
415
4236f99104ba Annotation-types title are found in search API
verrierj
parents: 412
diff changeset
     7
import lxml.etree
412
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
     8
import uuid
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
     9
1093
03104d3f6ca1 Requests optimisations
ymh <ymh.work@gmail.com>
parents: 877
diff changeset
    10
logger = logging.getLogger(__name__)
03104d3f6ca1 Requests optimisations
ymh <ymh.work@gmail.com>
parents: 877
diff changeset
    11
412
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
    12
DATE_FORMATS = ["%d/%m/%Y", "%Y-%m-%d"]
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
class SegmentSerializer(object):
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
    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
    17
    """
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
    18
    
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
    19
    def __init__(self, content, segments, viewable_contents=[], default_color=2194379):
420
38e46b1d0bd3 Small bugfixes
verrierj
parents: 415
diff changeset
    20
        """
38e46b1d0bd3 Small bugfixes
verrierj
parents: 415
diff changeset
    21
        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
    22
        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
    23
        """
412
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
    24
        self.content = content
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
    25
        self.segments = segments
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
    26
        self.viewable_contents = viewable_contents
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
    27
        self.default_color = default_color
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
    28
        self.views = None
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
    29
        self.annotation_types = None
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
    30
        self.medias = None
426
4328cd4a7533 refactor modal windows + add translations
verrierj
parents: 424
diff changeset
    31
        self.annotations = None 
4328cd4a7533 refactor modal windows + add translations
verrierj
parents: 424
diff changeset
    32
        self.tags = {}
4328cd4a7533 refactor modal windows + add translations
verrierj
parents: 424
diff changeset
    33
               
415
4236f99104ba Annotation-types title are found in search API
verrierj
parents: 412
diff changeset
    34
        self.xml_docs = {}
4236f99104ba Annotation-types title are found in search API
verrierj
parents: 412
diff changeset
    35
        
1093
03104d3f6ca1 Requests optimisations
ymh <ymh.work@gmail.com>
parents: 877
diff changeset
    36
    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
    37
        
4236f99104ba Annotation-types title are found in search API
verrierj
parents: 412
diff changeset
    38
        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
    39
            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
    40
                return None
560
1cb2a4a573e1 correct annoations api handler + ldt encoding
ymh <ymh.work@gmail.com>
parents: 532
diff changeset
    41
            doc = lxml.etree.fromstring(project.ldt_encoded)
415
4236f99104ba Annotation-types title are found in search API
verrierj
parents: 412
diff changeset
    42
            self.xml_docs[project_id] = doc
4236f99104ba Annotation-types title are found in search API
verrierj
parents: 412
diff changeset
    43
        else:
4236f99104ba Annotation-types title are found in search API
verrierj
parents: 412
diff changeset
    44
            doc = self.xml_docs[project_id]
4236f99104ba Annotation-types title are found in search API
verrierj
parents: 412
diff changeset
    45
              
426
4328cd4a7533 refactor modal windows + add translations
verrierj
parents: 424
diff changeset
    46
        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
    47
        if not cutting:
4328cd4a7533 refactor modal windows + add translations
verrierj
parents: 424
diff changeset
    48
            return None
4328cd4a7533 refactor modal windows + add translations
verrierj
parents: 424
diff changeset
    49
        
4328cd4a7533 refactor modal windows + add translations
verrierj
parents: 424
diff changeset
    50
        cutting = cutting[0]
415
4236f99104ba Annotation-types title are found in search API
verrierj
parents: 412
diff changeset
    51
        
4236f99104ba Annotation-types title are found in search API
verrierj
parents: 412
diff changeset
    52
        return cutting.text       
412
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
    def __parse_views(self):
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
    55
        
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
    56
        view = {
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
    57
                "id": "0",
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
    58
                "contents": [
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
    59
                    self.content.iri_id
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
                "annotation_types": [ ],
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
    62
        }
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
    63
        
424
a2f72b31811b Add french translations + small bugfixes
verrierj
parents: 420
diff changeset
    64
        stat = {
a2f72b31811b Add french translations + small bugfixes
verrierj
parents: 420
diff changeset
    65
                "id": "stat",
a2f72b31811b Add french translations + small bugfixes
verrierj
parents: 420
diff changeset
    66
                "contents": [
a2f72b31811b Add french translations + small bugfixes
verrierj
parents: 420
diff changeset
    67
                    self.content.iri_id
a2f72b31811b Add french translations + small bugfixes
verrierj
parents: 420
diff changeset
    68
                ],
a2f72b31811b Add french translations + small bugfixes
verrierj
parents: 420
diff changeset
    69
                "meta": {
479
1cbfcfcb2a47 Objects serializer send correct stats
verrierj
parents: 468
diff changeset
    70
                    "stat": get_string_from_buckets(self.content.annotation_volume)
424
a2f72b31811b Add french translations + small bugfixes
verrierj
parents: 420
diff changeset
    71
                }
a2f72b31811b Add french translations + small bugfixes
verrierj
parents: 420
diff changeset
    72
        }
a2f72b31811b Add french translations + small bugfixes
verrierj
parents: 420
diff changeset
    73
        
412
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
    74
        self.annotation_types = []
415
4236f99104ba Annotation-types title are found in search API
verrierj
parents: 412
diff changeset
    75
4236f99104ba Annotation-types title are found in search API
verrierj
parents: 412
diff changeset
    76
        annotation_types = []        
4236f99104ba Annotation-types title are found in search API
verrierj
parents: 412
diff changeset
    77
        for seg in self.segments:
1093
03104d3f6ca1 Requests optimisations
ymh <ymh.work@gmail.com>
parents: 877
diff changeset
    78
            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
    79
            annotation_types.append({'id': seg.cutting_id, 'title': title})
4236f99104ba Annotation-types title are found in search API
verrierj
parents: 412
diff changeset
    80
        
412
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
    81
        for a in annotation_types:
426
4328cd4a7533 refactor modal windows + add translations
verrierj
parents: 424
diff changeset
    82
                                            
415
4236f99104ba Annotation-types title are found in search API
verrierj
parents: 412
diff changeset
    83
            view['annotation_types'].append(a['id'])
412
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
    84
            self.annotation_types.append({
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
    85
                    "dc:contributor": "undefined",
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
    86
                    "dc:creator": "undefined",
415
4236f99104ba Annotation-types title are found in search API
verrierj
parents: 412
diff changeset
    87
                    "dc:title": a['title'],
4236f99104ba Annotation-types title are found in search API
verrierj
parents: 412
diff changeset
    88
                    "id": a['id'],
412
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
    89
                    "dc:created": "",
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
    90
                    "dc:description": "",
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
    91
                    "dc:modified": ""
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
    92
                })
415
4236f99104ba Annotation-types title are found in search API
verrierj
parents: 412
diff changeset
    93
            
412
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
    94
        
424
a2f72b31811b Add french translations + small bugfixes
verrierj
parents: 420
diff changeset
    95
        self.views = [view, stat]
412
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
    96
        
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
    97
    
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
    98
    def __parse_content(self):
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
    99
        
572
10c26c22b76a Replace href by url in JSON
verrierj
parents: 560
diff changeset
   100
        url = ""
412
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   101
        meta_item_value = ""
1093
03104d3f6ca1 Requests optimisations
ymh <ymh.work@gmail.com>
parents: 877
diff changeset
   102
         
03104d3f6ca1 Requests optimisations
ymh <ymh.work@gmail.com>
parents: 877
diff changeset
   103
        logger.debug("__parse_content start")   
482
c802e00c7131 Lot of bugfixes
verrierj
parents: 479
diff changeset
   104
        if use_forbidden_url(self.content):
572
10c26c22b76a Replace href by url in JSON
verrierj
parents: 560
diff changeset
   105
            url = settings.FORBIDDEN_STREAM_URL
412
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   106
        elif self.content.videopath:
572
10c26c22b76a Replace href by url in JSON
verrierj
parents: 560
diff changeset
   107
            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
   108
            meta_item_value = self.content.videopath.rstrip('/') + "/"
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   109
        else:
572
10c26c22b76a Replace href by url in JSON
verrierj
parents: 560
diff changeset
   110
            url = self.content.src
412
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   111
        
1093
03104d3f6ca1 Requests optimisations
ymh <ymh.work@gmail.com>
parents: 877
diff changeset
   112
        logger.debug("__parse_content url %s " % url)
03104d3f6ca1 Requests optimisations
ymh <ymh.work@gmail.com>
parents: 877
diff changeset
   113
        
412
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   114
        media = {
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   115
             "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
   116
             "id" : self.content.iri_id,
572
10c26c22b76a Replace href by url in JSON
verrierj
parents: 560
diff changeset
   117
             "url" : url,
412
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   118
             "unit" : "ms",
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   119
             "origin" : "0",
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   120
             "meta": {
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   121
                 "dc:creator" : "",
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   122
                 "dc:created" : self.content.creation_date.isoformat(),
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   123
                 "dc:contributor" : "",
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   124
                 "dc:modified" : self.content.update_date.isoformat(),
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   125
                 "dc:creator.contents" : "",
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   126
                 "dc:title" : self.content.title,
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   127
                 "dc:description" : self.content.description,
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   128
                 "dc:duration" : self.content.get_duration(),
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   129
                 "item": {
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   130
                     "name" : "streamer",
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   131
                     "value": meta_item_value,
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
        }
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.medias = [media]
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
    
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   139
    def __parse_segments(self):
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   140
        
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   141
        self.annotations = []
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   142
        
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   143
        for seg in self.segments:
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   144
            
426
4328cd4a7533 refactor modal windows + add translations
verrierj
parents: 424
diff changeset
   145
            segment_tags = []
876
8fd46e270e23 correct segment tag parsing and remove useless import.
cavaliet
parents: 810
diff changeset
   146
            for tag in parse_tag_input(seg.tags):
426
4328cd4a7533 refactor modal windows + add translations
verrierj
parents: 424
diff changeset
   147
                if not self.tags.has_key(tag):
4328cd4a7533 refactor modal windows + add translations
verrierj
parents: 424
diff changeset
   148
                    new_tag = {
4328cd4a7533 refactor modal windows + add translations
verrierj
parents: 424
diff changeset
   149
                        "meta": {
4328cd4a7533 refactor modal windows + add translations
verrierj
parents: 424
diff changeset
   150
                            "dc:contributor": "IRI",
4328cd4a7533 refactor modal windows + add translations
verrierj
parents: 424
diff changeset
   151
                            "dc:created": seg.date,
4328cd4a7533 refactor modal windows + add translations
verrierj
parents: 424
diff changeset
   152
                            "dc:title": tag,
4328cd4a7533 refactor modal windows + add translations
verrierj
parents: 424
diff changeset
   153
                            "dc:modified": seg.date,
4328cd4a7533 refactor modal windows + add translations
verrierj
parents: 424
diff changeset
   154
                            "dc:creator": "IRI"
4328cd4a7533 refactor modal windows + add translations
verrierj
parents: 424
diff changeset
   155
                        },
4328cd4a7533 refactor modal windows + add translations
verrierj
parents: 424
diff changeset
   156
                        "id": unicode(uuid.uuid1())
4328cd4a7533 refactor modal windows + add translations
verrierj
parents: 424
diff changeset
   157
                    }
4328cd4a7533 refactor modal windows + add translations
verrierj
parents: 424
diff changeset
   158
                    self.tags[tag] = new_tag
4328cd4a7533 refactor modal windows + add translations
verrierj
parents: 424
diff changeset
   159
                segment_tags.append({'id-ref': self.tags[tag]['id']})
4328cd4a7533 refactor modal windows + add translations
verrierj
parents: 424
diff changeset
   160
            
412
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   161
            segment = {
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   162
                'begin': seg.start_ts,
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   163
                'end': seg.start_ts + seg.duration,
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   164
                'tags': seg.tags,
427
e0158472f83a Fix pluralized translations + clean-up segmentserializer
verrierj
parents: 426
diff changeset
   165
                'id': seg.element_id,
412
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   166
                'color': "%s" % self.default_color,
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   167
                'media': self.content.iri_id,
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   168
                'content': {
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   169
                    'mimetype': 'application/x-ldt-structured',
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   170
                    'description': seg.abstract,
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   171
                    'img': {
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   172
                        'src': ''
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   173
                    },
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   174
                    'title': seg.title,
427
e0158472f83a Fix pluralized translations + clean-up segmentserializer
verrierj
parents: 426
diff changeset
   175
                    'color': self.default_color,
412
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   176
                    'polemics': [ ],
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   177
                    'audio': {
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   178
                        'mimetype': 'audio/mp3',
810
e7546394653c add audio annotation to segment api and correct reindex command.
cavaliet
parents: 572
diff changeset
   179
                        'src': seg.audio_src,
e7546394653c add audio annotation to segment api and correct reindex command.
cavaliet
parents: 572
diff changeset
   180
                        'href': seg.audio_href
412
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   181
                    }
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   182
                
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   183
                },
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   184
                'meta': {
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   185
                         "dc:creator": seg.author,
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   186
                         "dc:contributor": seg.author,
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   187
                         "dc:created": seg.date,
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   188
                         "dc:modified": seg.date,
427
e0158472f83a Fix pluralized translations + clean-up segmentserializer
verrierj
parents: 426
diff changeset
   189
                         "id-ref": seg.cutting_id,
412
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   190
                         "project": seg.project_id
426
4328cd4a7533 refactor modal windows + add translations
verrierj
parents: 424
diff changeset
   191
                },
4328cd4a7533 refactor modal windows + add translations
verrierj
parents: 424
diff changeset
   192
                'tags': segment_tags                       
412
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   193
            }
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   194
            
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   195
            self.annotations.append(segment)
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   196
    
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   197
    def serialize_to_cinelab(self):
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   198
        
1093
03104d3f6ca1 Requests optimisations
ymh <ymh.work@gmail.com>
parents: 877
diff changeset
   199
        logger.debug("serialize_to_cinelab start")
426
4328cd4a7533 refactor modal windows + add translations
verrierj
parents: 424
diff changeset
   200
        if not self.segments:
4328cd4a7533 refactor modal windows + add translations
verrierj
parents: 424
diff changeset
   201
            return None
4328cd4a7533 refactor modal windows + add translations
verrierj
parents: 424
diff changeset
   202
        
412
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   203
        self.__parse_content()
1093
03104d3f6ca1 Requests optimisations
ymh <ymh.work@gmail.com>
parents: 877
diff changeset
   204
        logger.debug("serialize_to_cinelab parse content done")
412
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   205
        self.__parse_segments()
1093
03104d3f6ca1 Requests optimisations
ymh <ymh.work@gmail.com>
parents: 877
diff changeset
   206
        logger.debug("serialize_to_cinelab parse segments done")
412
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   207
        self.__parse_views()
1093
03104d3f6ca1 Requests optimisations
ymh <ymh.work@gmail.com>
parents: 877
diff changeset
   208
        logger.debug("serialize_to_cinelab parse views done")
412
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   209
        
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   210
        res = {}
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   211
        res['views'] = self.views 
426
4328cd4a7533 refactor modal windows + add translations
verrierj
parents: 424
diff changeset
   212
        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
   213
        res['lists'] = None
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   214
        res['medias'] = self.medias
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   215
        res['annotations'] = self.annotations
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   216
        res['annotation-types'] = self.annotation_types
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   217
        
1093
03104d3f6ca1 Requests optimisations
ymh <ymh.work@gmail.com>
parents: 877
diff changeset
   218
        logger.debug("serialize_to_cinelab done")
03104d3f6ca1 Requests optimisations
ymh <ymh.work@gmail.com>
parents: 877
diff changeset
   219
        
412
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   220
        return res
8d777b1d1d92 Add API to search annotations inside a content between two timecodes
verrierj
parents:
diff changeset
   221