pymkv2 2.0.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
pymkv/BCP47.py ADDED
@@ -0,0 +1,24 @@
1
+ # sheldon woodward
2
+ # 10/21/20
3
+
4
+ """BCP47 language region code"""
5
+
6
+ import bcp47
7
+
8
+
9
+ def is_bcp47(language_ietf):
10
+ """The `is_bcp47` function checks if a given language tag is a valid BCP47 language tag.
11
+
12
+ Args:
13
+ language_ietf: The language tag to be checked.
14
+
15
+ Returns:
16
+ bool: True if the language tag is a valid BCP47 language tag, False otherwise.
17
+
18
+ Raises:
19
+ None
20
+ """
21
+ if language_ietf == "und":
22
+ return True
23
+ else:
24
+ return language_ietf in bcp47.languages.values()
pymkv/ISO639_2.py ADDED
@@ -0,0 +1,27 @@
1
+ # sheldon woodward
2
+ # 3/18/18
3
+
4
+ """ISO639-2 Three Character Language Codes"""
5
+
6
+ from typing import Optional
7
+
8
+ from iso639 import languages
9
+
10
+
11
+ def is_iso639_2(language) -> Optional[bool]:
12
+ """The `is_iso639_2` function checks if a given language code is a valid ISO 639-2 language code.
13
+
14
+ Args:
15
+ language: The language code to be checked.
16
+
17
+ Returns:
18
+ bool: True if the language code is a valid ISO 639-2 language code, False otherwise.
19
+
20
+ Raises:
21
+ None
22
+ """
23
+ try:
24
+ languages.get(part2b=language)
25
+ return True
26
+ except KeyError:
27
+ return False
pymkv/MKVAttachment.py ADDED
@@ -0,0 +1,96 @@
1
+ """:class:`~pymkv.MKVAttachment` classes are used to represent attachment files within an MKV or to be used in an
2
+ MKV.
3
+
4
+ Examples
5
+ --------
6
+ Below are some basic examples of how the :class:`~pymkv.MKVAttachment` objects can be used.
7
+
8
+ Create a new :class:`~pymkv.MKVAttachment` and add it to an :class:`~pymkv.MKVFile`.
9
+
10
+ >>> from pymkv import MKVAttachment
11
+ >>> attachment = MKVAttachment('path/to/attachment.jpg', name='NAME')
12
+ >>> attachment.description = 'DESCRIPTION'
13
+
14
+ Attachments can also be added directly to an :class:`~pymkv.MKVFile`.
15
+
16
+ >>> from pymkv import MKVFile
17
+ >>> mkv = MKVFile('path/to/file.mkv')
18
+ >>> mkv.add_attachment('path/to/other/attachment.png')
19
+
20
+ Now, the MKV can be muxed with both attachments.
21
+
22
+ >>> mkv.add_attachment(attachment)
23
+ >>> mkv.mux('path/to/output.mkv')
24
+ """
25
+
26
+ from __future__ import annotations
27
+
28
+ from mimetypes import guess_type
29
+ from pathlib import Path
30
+
31
+
32
+ class MKVAttachment:
33
+ """A class that represents an MKV attachment for an :class:`~pymkv.MKVFile` object.
34
+
35
+ Parameters
36
+ ----------
37
+ file_path : str
38
+ The path to the attachment file.
39
+ name : str, optional
40
+ The name that will be given to the attachment when muxed into a file.
41
+ description : str, optional
42
+ The description that will be given to the attachment when muxed into a file.
43
+ attach_once : bool, optional
44
+ Determines if the attachment should be added to all split files or only the first. Default is False,
45
+ which will attach to all files.
46
+
47
+ Attributes
48
+ ----------
49
+ mime_type : str
50
+ The attachment's MIME type. The type will be guessed when :attr:`~pymkv.MKVAttachment.file_path` is set.
51
+ name : str
52
+ The name that will be given to the attachment when muxed into a file.
53
+ description : str
54
+ The description that will be given to the attachment when muxed into a file.
55
+ attach_once : bool
56
+ Determines if the attachment should be added to all split files or only the first. Default is False,
57
+ which will attach to all files.
58
+ """
59
+
60
+ def __init__(
61
+ self,
62
+ file_path: str,
63
+ name: str | None = None,
64
+ description: str | None = None,
65
+ attach_once: bool | None = False,
66
+ ) -> None:
67
+ self.mime_type = None
68
+ self._file_path = None
69
+ self.file_path = file_path
70
+ self.name = name
71
+ self.description = description
72
+ self.attach_once = attach_once
73
+
74
+ def __repr__(self) -> str:
75
+ return repr(self.__dict__)
76
+
77
+ @property
78
+ def file_path(self) -> str:
79
+ """str: The path to the attachment file.
80
+
81
+ Raises
82
+ ------
83
+ FileNotFoundError
84
+ Raised if `file_path` does not exist.
85
+ """
86
+ return self._file_path
87
+
88
+ @file_path.setter
89
+ def file_path(self, file_path: str) -> None:
90
+ file_path = Path.expanduser(Path(file_path))
91
+ if not Path.is_file(file_path):
92
+ msg = f'"{file_path}" does not exist'
93
+ raise FileNotFoundError(msg)
94
+ self.mime_type = guess_type(file_path)[0]
95
+ self.name = None
96
+ self._file_path = file_path