kapsikkum-unmanic – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3  
4 """
5 unmanic.__init__.py
6  
7 Written by: Josh.5 <jsunnex@gmail.com>
8 Date: 20 Sep 2019, (5:37 PM)
9  
10 Copyright:
11 Copyright (C) Josh Sunnex - All Rights Reserved
12  
13 Permission is hereby granted, free of charge, to any person obtaining a copy
14 of this software and associated documentation files (the "Software"), to deal
15 in the Software without restriction, including without limitation the rights
16 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17 copies of the Software, and to permit persons to whom the Software is
18 furnished to do so, subject to the following conditions:
19  
20 The above copyright notice and this permission notice shall be included in all
21 copies or substantial portions of the Software.
22  
23 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
26 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
27 DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
28 OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
29 OR OTHER DEALINGS IN THE SOFTWARE.
30  
31 """
32  
33 from __future__ import absolute_import
34  
35 import os
36 import warnings
37 from importlib import import_module
38 from pathlib import Path
39 import sys
40 import inspect
41 import pkgutil
42  
43 from ..base_codecs import Codecs
44  
45  
46 def grab_module(module_name, *args, **kwargs):
47 """
48 Fetch a module by name and return the instance of that class
49  
50 :param module_name:
51 :param args:
52 :param kwargs:
53 :return:
54 """
55 try:
56 if '.' in module_name:
57 module_name, class_name = module_name.rsplit('.', 1)
58 else:
59 class_name = module_name.capitalize()
60  
61 module = import_module('.' + module_name, package=__name__)
62 module_class = getattr(module, class_name)
63 instance = module_class(*args, **kwargs)
64  
65 return instance
66  
67 except (AttributeError, AssertionError, ModuleNotFoundError):
68 raise ImportError('{} is not part of our supported video codecs!'.format(module_name))
69  
70  
71 def get_all_video_codecs():
72 """
73 Fetch a list of supported video codecs and
74 return a dictionary of their data
75  
76 :return:
77 """
78 return_dic = {}
79  
80 for (_, module_name, _) in pkgutil.iter_modules([os.path.join(Path(__file__).parent)]):
81 instance = grab_module(module_name)
82 return_data = {
83 "name": instance.codec_name(),
84 "encoders": instance.codec_encoders(),
85 "default_encoder": instance.codec_default_encoder(),
86 "description": instance.codec_description(),
87 }
88 return_dic[module_name] = return_data
89  
90 return return_dic
91  
92  
93 """
94 Import all submodules for this package
95  
96 """
97 for (_, name, _) in pkgutil.iter_modules([os.path.join(Path(__file__).parent)]):
98  
99 imported_module = import_module('.' + name, package=__name__)
100  
101 for i in dir(imported_module):
102 attribute = getattr(imported_module, i)
103  
104 if inspect.isclass(attribute) and issubclass(attribute, Codecs):
105 setattr(sys.modules[__name__], name, attribute)
106  
107 __author__ = 'Josh.5 (jsunnex@gmail.com)'
108  
109 __all__ = (
110 'Codecs',
111 )