aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/livestreamer/plugins/__init__.py
blob: 3999574b1f20ea897c2dab048f05715085e4d574 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/bin/env python3

import pkgutil
import imp

plugins_loaded = {}

class Plugin(object):
    def can_handle_url(self, url):
        raise NotImplementedError

    def get_streams(self, channel):
        raise NotImplementedError

    def stream_cmdline(self, stream, filename):
        raise NotImplementedError


def load_plugins(plugins):
    for loader, name, ispkg in pkgutil.iter_modules(plugins.__path__):
        file, pathname, desc = imp.find_module(name, plugins.__path__)
        imp.load_module(name, file, pathname, desc)
    return plugins_loaded


def get_plugins():
    return plugins_loaded

def register_plugin(name, klass):
    obj = klass()
    plugins_loaded[name] = obj