コード例 #1
0
    def _format_contentset(self, article, item):
        """Constructs the contentSet element in a picture, video and audio newsItem.

        :param article:
        :param item:
        :return: contentSet Element added to the item
        """
        content_set = SubElement(item, 'contentSet')
        for rendition, value in article.get('renditions', {}).items():
            attrib = {
                'href': value.get('href'),
                'contenttype': value.get('mimetype', ''),
                'rendition': 'rendition:' + rendition
            }
            if article.get(ITEM_TYPE) == CONTENT_TYPE.PICTURE:
                if 'height' in value:
                    attrib['height'] = str(value.get('height'))
                if 'width' in value:
                    attrib['width'] = str(value.get('width'))
            elif article.get(ITEM_TYPE) in {
                    CONTENT_TYPE.VIDEO, CONTENT_TYPE.AUDIO
            }:
                if get_filemeta(article, 'width'):
                    attrib['width'] = str(get_filemeta(article, 'width'))
                if get_filemeta(article, 'height'):
                    attrib['height'] = str(get_filemeta(article, 'height'))
                if get_filemeta(article, 'duration'):
                    attrib['duration'] = get_filemeta(article, 'duration')
                    attrib['durationunit'] = 'timeunit:normalPlayTime'

            if rendition == 'original' and get_filemeta(article, 'length'):
                attrib['size'] = str(get_filemeta(article, 'length'))
            SubElement(content_set, 'remoteContent', attrib=attrib)
コード例 #2
0
    def _format_contentset(self, article, item):
        """
        Constructs the contentSet element in a picture, video and audio newsItem.
        :param article:
        :param item:
        :return: contentSet Element added to the item
        """
        content_set = SubElement(item, 'contentSet')
        for rendition, value in article.get('renditions', {}).items():
            attrib = {'href': value.get('href'),
                      'contenttype': value.get('mimetype', ''),
                      'rendition': 'rendition:' + rendition
                      }
            if article.get(ITEM_TYPE) == CONTENT_TYPE.PICTURE:
                if 'height' in value:
                    attrib['height'] = str(value.get('height'))
                if 'width' in value:
                    attrib['width'] = str(value.get('width'))
            elif article.get(ITEM_TYPE) in {CONTENT_TYPE.VIDEO, CONTENT_TYPE.AUDIO}:
                if get_filemeta(article, 'width'):
                    attrib['width'] = str(get_filemeta(article, 'width'))
                if get_filemeta(article, 'height'):
                    attrib['height'] = str(get_filemeta(article, 'height'))
                if get_filemeta(article, 'duration'):
                    attrib['duration'] = get_filemeta(article, 'duration')
                    attrib['durationunit'] = 'timeunit:normalPlayTime'

            if rendition == 'original' and get_filemeta(article, 'length'):
                attrib['size'] = str(get_filemeta(article, 'length'))
            SubElement(content_set, 'remoteContent', attrib=attrib)
コード例 #3
0
ファイル: items.py プロジェクト: sfcaru/liveblog
 def on_create(self, docs):
     super().on_create(docs)
     for doc in docs:
         update_dates_for(doc)
         doc['original_creator'] = str(get_user().get('_id'))
         if doc.get('item_type'):
             if doc['item_type'] == 'embed':
                 metadata = doc['meta']
                 set_filemeta(doc, metadata)
                 if get_filemeta(doc, 'version'):
                     metadata['version'] = str(metadata.get('version'))
                 if get_filemeta(doc, 'width'):
                     metadata['width'] = str(metadata.get('width'))
                 if get_filemeta(doc, 'height'):
                     metadata['height'] = str(metadata.get('height'))
コード例 #4
0
    def _format_media(self, article, main_news_component, media_type):
        """
        Create an NewsComponent element related to media

        :param dict article:
        :param Element main_news_component:
        """
        media_news_component = SubElement(main_news_component, "NewsComponent")
        SubElement(media_news_component, 'Role', {'FormalName': media_type})
        for rendition, value in article.get('renditions').items():
            news_component = SubElement(media_news_component, "NewsComponent")
            SubElement(news_component, 'Role', {'FormalName': rendition})
            content_item = SubElement(news_component, "ContentItem",
                                      attrib={'Href': value.get('href', '')})
            SubElement(content_item, 'MediaType', {'FormalName': media_type})
            SubElement(content_item, 'Format', {'FormalName': value.get('mimetype', '')})
            characteristics = SubElement(content_item, 'Characteristics')
            if rendition == 'original' and get_filemeta(article, 'length'):
                SubElement(characteristics, 'SizeInBytes').text = str(get_filemeta(article, 'length'))
            if article.get(ITEM_TYPE) == CONTENT_TYPE.PICTURE:
                if value.get('width'):
                    SubElement(characteristics, 'Property',
                               attrib={'FormalName': 'Width', 'Value': str(value.get('width'))})
                if value.get('height'):
                    SubElement(characteristics, 'Property',
                               attrib={'FormalName': 'Height', 'Value': str(value.get('height'))})
            elif article.get(ITEM_TYPE) in {CONTENT_TYPE.VIDEO, CONTENT_TYPE.AUDIO}:
                if get_filemeta(article, 'width'):
                    SubElement(characteristics, 'Property',
                               attrib={'FormalName': 'Width',
                                       'Value': str(get_filemeta(article, 'width'))})
                if get_filemeta(article, 'height'):
                    SubElement(characteristics, 'Property',
                               attrib={'FormalName': 'Height',
                                       'Value': str(get_filemeta(article, 'height'))})

                duration = self._get_total_duration(get_filemeta(article, 'duration'))
                if duration:
                    SubElement(characteristics, 'Property',
                               attrib={'FormalName': 'TotalDuration', 'Value': str(duration)})
コード例 #5
0
    def _format_media(self, article, main_news_component, media_type):
        """
        Create an NewsComponent element related to media

        :param dict article:
        :param Element main_news_component:
        """
        media_news_component = SubElement(main_news_component, "NewsComponent")
        SubElement(media_news_component, "Role", {"FormalName": media_type})
        for rendition, value in article.get("renditions").items():
            news_component = SubElement(media_news_component, "NewsComponent")
            SubElement(news_component, "Role", {"FormalName": rendition})
            content_item = SubElement(news_component,
                                      "ContentItem",
                                      attrib={"Href": value.get("href", "")})
            SubElement(content_item, "MediaType", {"FormalName": media_type})
            SubElement(content_item, "Format",
                       {"FormalName": value.get("mimetype", "")})
            characteristics = SubElement(content_item, "Characteristics")
            if rendition == "original" and get_filemeta(article, "length"):
                SubElement(characteristics, "SizeInBytes").text = str(
                    get_filemeta(article, "length"))
            if article.get(ITEM_TYPE) == CONTENT_TYPE.PICTURE:
                if value.get("width"):
                    SubElement(characteristics,
                               "Property",
                               attrib={
                                   "FormalName": "Width",
                                   "Value": str(value.get("width"))
                               })
                if value.get("height"):
                    SubElement(characteristics,
                               "Property",
                               attrib={
                                   "FormalName": "Height",
                                   "Value": str(value.get("height"))
                               })
            elif article.get(ITEM_TYPE) in {
                    CONTENT_TYPE.VIDEO, CONTENT_TYPE.AUDIO
            }:
                if get_filemeta(article, "width"):
                    SubElement(
                        characteristics,
                        "Property",
                        attrib={
                            "FormalName": "Width",
                            "Value": str(get_filemeta(article, "width"))
                        },
                    )
                if get_filemeta(article, "height"):
                    SubElement(
                        characteristics,
                        "Property",
                        attrib={
                            "FormalName": "Height",
                            "Value": str(get_filemeta(article, "height"))
                        },
                    )

                duration = self._get_total_duration(
                    get_filemeta(article, "duration"))
                if duration:
                    SubElement(characteristics,
                               "Property",
                               attrib={
                                   "FormalName": "TotalDuration",
                                   "Value": str(duration)
                               })
コード例 #6
0
 def test_get_set_filemeta(self):
     item = {}
     set_filemeta(item, {'foo': 'bar'})
     self.assertEqual('bar', get_filemeta(item, 'foo'))
     self.assertEqual({'foo': 'bar'}, get_filemeta(item))
コード例 #7
0
 def test_get_filemeta_obsolete(self):
     item = {'filemeta': {'x': 1}}
     self.assertEqual(1, get_filemeta(item, 'x'))
コード例 #8
0
 def test_get_set_filemeta(self):
     item = {}
     set_filemeta(item, {'foo': 'bar'})
     self.assertEqual('bar', get_filemeta(item, 'foo'))
     self.assertEqual({'foo': 'bar'}, get_filemeta(item))
コード例 #9
0
 def test_get_filemeta_obsolete(self):
     item = {'filemeta': {'x': 1}}
     self.assertEqual(1, get_filemeta(item, 'x'))