Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion linebot/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@
ImageComponent,
SeparatorComponent,
TextComponent,
SpanComponent
SpanComponent,
VideoComponent
)
from .imagemap import ( # noqa
ImagemapSendMessage,
Expand Down
58 changes: 56 additions & 2 deletions linebot/models/flex_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ def __init__(self, size=None, direction=None, header=None, hero=None,
:param hero: Hero block
:type hero: :py:class:`linebot.models.flex_message.ImageComponent`
| :py:class:`linebot.models.flex_message.BoxComponent`
| :py:class:`linebot.models.flex_message.VideoComponent`
:param body: Body block
:type body: :py:class:`linebot.models.flex_message.BoxComponent`
:param footer: Footer block
Expand All @@ -112,7 +113,8 @@ def __init__(self, size=None, direction=None, header=None, hero=None,
self.hero = self.get_or_new_from_json_dict_with_types(
hero, {
'image': ImageComponent,
'box': BoxComponent
'box': BoxComponent,
'video': VideoComponent
}
)
self.body = self.get_or_new_from_json_dict(body, BoxComponent)
Expand Down Expand Up @@ -238,7 +240,9 @@ def __init__(self,
align_items=None,
background=None,
width=None,
max_width=None,
height=None,
max_height=None,
flex=None,
spacing=None,
margin=None,
Expand Down Expand Up @@ -270,7 +274,9 @@ def __init__(self,
:param background: Background object
:type background: T <= :py:class:`linebot.models.background.Background`
:param str width: Width of the box
:param str max_width: Maximum width of the box
:param str height: Height of the box
:param str max_height: Maximum height of the box
:param float flex: The ratio of the width or height of this box within the parent box
and the previous component in the parent box
:param str spacing: Minimum space between components in this box
Expand Down Expand Up @@ -303,7 +309,9 @@ def __init__(self,
self.justify_content = justify_content
self.align_items = align_items
self.width = width
self.max_width = max_width
self.height = height
self.max_height = max_height
self.flex = flex
self.spacing = spacing
self.margin = margin
Expand Down Expand Up @@ -334,7 +342,8 @@ def __init__(self,
'image': ImageComponent,
'span': SpanComponent,
'separator': SeparatorComponent,
'text': TextComponent
'text': TextComponent,
'video': VideoComponent
}
))
self.contents = new_contents
Expand Down Expand Up @@ -615,6 +624,7 @@ def __init__(self,
align=None,
gravity=None,
wrap=None,
line_spacing=None,
max_lines=None,
weight=None,
color=None,
Expand All @@ -640,6 +650,7 @@ def __init__(self,
:param str gravity: Vertical alignment style
:param bool wrap: rue to wrap text. The default value is False.
If set to True, you can use a new line character (\n) to begin on a new line.
:param str line_spacing: Line spacing in a wrapping text
:param int max_lines: Max number of lines
:param str weight: Font weight
:param str color: Font color
Expand All @@ -663,6 +674,7 @@ def __init__(self,
self.align = align
self.gravity = gravity
self.wrap = wrap
self.line_spacing = line_spacing
self.max_lines = max_lines
self.weight = weight
self.color = color
Expand All @@ -674,3 +686,45 @@ def __init__(self,
self.contents = [self.get_or_new_from_json_dict(it, SpanComponent) for it in contents]
else:
self.contents = None


class VideoComponent(FlexComponent):
"""VideoComponent.

https://developers.line.biz/en/reference/messaging-api/#f-video

This component renders a video.
"""

def __init__(self,
url=None,
preview_url=None,
alt_content=None,
aspect_ratio=None,
action=None,
**kwargs):
r"""__init__ method.

:param str url: URL of video file
:param str preview_url: URL of preview image
:param alt_content: Alternative content
:type alt_content: :py:class:`linebot.models.flex_message.ImageComponent`
| :py:class:`linebot.models.flex_message.BoxComponent`
:param float aspect_ratio: Aspect ratio of the video
:param action: Action performed when this video is tapped
:type action: list[T <= :py:class:`linebot.models.actions.Action`]
:param kwargs:
"""
super(VideoComponent, self).__init__(**kwargs)

self.type = 'video'
self.url = url
self.preview_url = preview_url
self.alt_content = self.get_or_new_from_json_dict_with_types(
alt_content, {
'image': ImageComponent,
'box': BoxComponent
}
)
self.aspect_ratio = aspect_ratio
self.action = get_action(action)
20 changes: 20 additions & 0 deletions tests/models/test_flex_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
FillerComponent,
IconComponent,
SpanComponent,
VideoComponent,
URIAction,
LinearGradientBackground,
)
Expand Down Expand Up @@ -249,6 +250,25 @@ def test_span_component(self):
SpanComponent(**arg).as_json_dict()
)

def test_video_component(self):
arg = {
'type': 'video',
'url': 'https://example.com/video.mp4',
"preview_url": "https://example.com/video_preview.jpg",
"alt_content": {
"type": "image",
"size": "full",
"aspect_ratio": "20:13",
"aspect_mode": "cover",
"url": "https://example.com/image.jpg"
},
"aspect_ratio": "20:13"
}
self.assertEqual(
self.serialize_as_dict(arg, type=self.VIDEO),
VideoComponent(**arg).as_json_dict()
)

def test_text_component(self):
arg = {
'text': 'Hello, World!',
Expand Down