bovine.activitystreams.media
bovine.activitystreams.media
This optional package contains methods to create objects used for media attachments. To use these methods please run
As work on a media attachment is in progress, the methods in this package might still change.
VideoInformation
dataclass
VideoInformation(digest: str, file_size: int, duration: str, width: int, height: int)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
digest
|
str
|
|
required |
file_size
|
int
|
|
required |
duration
|
str
|
|
required |
width
|
int
|
|
required |
height
|
int
|
|
required |
Source code in bovine/bovine/activitystreams/media.py
create_audio
Creates an audio object
>>> create_audio("./resources/test/cow_moo.mp3",
... "http://local.test/audio.mp3",
... alt_text="A cow mooing").build()
{'@context': ['https://www.w3.org/ns/activitystreams',
'https://www.w3.org/ns/credentials/v2',
{'size': 'https://joinpeertube.org/ns#size'}],
'type': 'Audio',
'name': 'A cow mooing',
'url': 'http://local.test/audio.mp3',
'mediaType': 'audio/mpeg',
'digestMultibase': 'zQmSXTyLCPqoiGoUUwKRMKgFdddaAUkvQNr29nhB6tahb9Z',
'size': 67709,
'duration': 'PT2.1S'}
Source code in bovine/bovine/activitystreams/media.py
create_image
Creates an Image object for the file
>>> create_image(
... "./resources/test/cow.jpg",
... "http://local.test/image.jpg",
... alt_text="A beautiful cow").build()
{'@context': ['https://www.w3.org/ns/activitystreams',
'https://www.w3.org/ns/credentials/v2',
{'size': 'https://joinpeertube.org/ns#size'}],
'type': 'Image',
'name': 'A beautiful cow',
'url': 'http://local.test/image.jpg',
'width': 200,
'height': 164,
'mediaType': 'image/jpeg',
'digestMultibase': 'zQmVm2NjMCsrzFWFRbhQJwHNzZH8gesampoGpZcsSii12VL',
'size': 15356}
Source code in bovine/bovine/activitystreams/media.py
create_video
Creates a video object
>>> create_video(
... "./resources/test/cow_eating.mp4",
... "http://local.test/video.mp4",
... alt_text="A beautiful cow eating").build()
{'@context':
['https://www.w3.org/ns/activitystreams',
'https://www.w3.org/ns/credentials/v2',
{'size': 'https://joinpeertube.org/ns#size'}],
'type': 'Video',
'name': 'A beautiful cow eating',
'url': 'http://local.test/video.mp4',
'width': 256,
'height': 144,
'mediaType': 'video/mp4',
'digestMultibase': 'zQmSzK5qEe5tpjwGMhmjx9RvVoPkWhEmCwxP2s7wPMpKMoK',
'size': 54373,
'duration': 'PT3S'}
This method also supports two video sources:
>>> create_video(
... ["./resources/test/cow_eating.mp4", "./resources/test/cow_eating_hd.mp4"],
... ["http://local.test/video.mp4", "http://local.test/video_hd.mp4"],
... alt_text="A beautiful cow eating").build()
{'@context': ['https://www.w3.org/ns/activitystreams',
'https://www.w3.org/ns/credentials/v2',
{'size': 'https://joinpeertube.org/ns#size'}],
'type': 'Video',
'name': 'A beautiful cow eating',
'url': [{'type': 'Link',
'size': 54373,
'digest': 'zQmSzK5qEe5tpjwGMhmjx9RvVoPkWhEmCwxP2s7wPMpKMoK',
'width': 256,
'height': 144,
'href': 'http://local.test/video.mp4',
'mediaType': 'video/mp4'},
{'type': 'Link',
'size': 2271723,
'digest': 'zQme2X4rgWuRdmAtGGMSEbdoeRQ2NAL2VptcdRGTYDZbSKG',
'width': 1920,
'height': 1080,
'href': 'http://local.test/video_hd.mp4',
'mediaType': 'video/mp4'}],
'duration': 'PT3S'}
Source code in bovine/bovine/activitystreams/media.py
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
|
file_props
file_props(filename: str)
Properties of a file
>>> file_props("./resources/test/cow.jpg")
('zQmVm2NjMCsrzFWFRbhQJwHNzZH8gesampoGpZcsSii12VL', 15356)
Source code in bovine/bovine/activitystreams/media.py
iso8601_duration
Converts seconds to iso 8601 duration