Skip to content

Commit 4bcbdfb

Browse files
committed
refactor: move Movie class and related functionality from movie.py to picture.py
1 parent 68be86f commit 4bcbdfb

File tree

3 files changed

+81
-86
lines changed

3 files changed

+81
-86
lines changed

src/tppt/pptx/shape/movie.py

Lines changed: 0 additions & 84 deletions
This file was deleted.

src/tppt/pptx/shape/picture.py

Lines changed: 80 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
from typing import IO, Literal, Self
1+
from typing import IO, Literal, NotRequired, Self, assert_never
22

3+
from pptx.opc.constants import CONTENT_TYPE
4+
from pptx.shapes.picture import Movie as PptxMovie
35
from pptx.shapes.picture import Picture as PptxPicture
46

57
from tppt.types import FilePath
@@ -38,3 +40,80 @@ def to_pptx(self) -> PptxPicture:
3840
def from_pptx(cls, pptx_obj: PptxPicture) -> Self:
3941
"""Create from pptx shape."""
4042
return cls(pptx_obj)
43+
44+
45+
MOVIE_MIME_TYPE = Literal[
46+
"video/x-ms-asf",
47+
"video/avi",
48+
"video/quicktime",
49+
"video/mp4",
50+
"video/mpeg",
51+
"video/msvideo",
52+
"video/x-ms-wmv",
53+
"video/x-msvideo",
54+
]
55+
56+
57+
def to_pptx_movie_mime_type(mime_type: MOVIE_MIME_TYPE) -> str:
58+
"""Convert movie mime type to pptx movie mime type."""
59+
match mime_type:
60+
case "video/x-ms-asf":
61+
return CONTENT_TYPE.ASF
62+
case "video/avi":
63+
return CONTENT_TYPE.AVI
64+
case "video/quicktime":
65+
return CONTENT_TYPE.MOV
66+
case "video/mp4":
67+
return CONTENT_TYPE.MP4
68+
case "video/mpeg":
69+
return CONTENT_TYPE.MPG
70+
case "video/msvideo":
71+
return CONTENT_TYPE.MS_VIDEO
72+
case "video/x-ms-wmv":
73+
return CONTENT_TYPE.WMV
74+
case "video/x-msvideo":
75+
return CONTENT_TYPE.X_MS_VIDEO
76+
case _:
77+
assert_never(mime_type)
78+
79+
80+
class MovieProps(RangeProps):
81+
"""Movie properties."""
82+
83+
poster_frame_image: NotRequired[FilePath | IO[bytes]]
84+
85+
mime_type: MOVIE_MIME_TYPE
86+
"""
87+
Mime type of the movie.
88+
89+
NOTE: The Movie shape is an experimental feature of python-pptx, and specifying the mime_type is recommended.
90+
"""
91+
92+
93+
class MovieData(MovieProps):
94+
"""Movie data."""
95+
96+
type: Literal["movie"]
97+
98+
movie_file: FilePath | IO[bytes]
99+
100+
101+
class Movie(BaseShape[PptxMovie]):
102+
"""Movie data class."""
103+
104+
def __init__(
105+
self,
106+
pptx_obj: PptxMovie,
107+
data: MovieData | None = None,
108+
/,
109+
) -> None:
110+
self._pptx = pptx_obj
111+
112+
def to_pptx(self) -> PptxMovie:
113+
"""Convert to pptx shape."""
114+
return self._pptx
115+
116+
@classmethod
117+
def from_pptx(cls, pptx_obj: PptxMovie) -> Self:
118+
"""Create from pptx shape."""
119+
return cls(pptx_obj)

src/tppt/pptx/slide.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
from pptx.slide import Slide as PptxSlide
1616

17-
from tppt.pptx.shape.movie import (
17+
from tppt.pptx.shape.picture import (
1818
Movie,
1919
MovieData,
2020
MovieProps,

0 commit comments

Comments
 (0)