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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
from livestreamer.options import Options
class Plugin(object):
"""
A plugin can retrieve stream information from the *url* specified.
"""
options = Options()
def __init__(self, url):
self.url = url
self.logger = self.session.logger.new_module("plugin." + self.module)
@classmethod
def can_handle_url(cls, url):
raise NotImplementedError
@classmethod
def set_option(cls, key, value):
cls.options.set(key, value)
@classmethod
def get_option(cls, key):
return cls.options.get(key)
def get_streams(self):
"""
Retrieves and returns a :class:`dict` containing the streams.
The key is the name of the stream, most commonly the quality.
The value is a :class:`Stream` object.
The stream with key *best* is a reference to the stream most likely
to be of highest quality.
"""
ranking = ["iphonelow", "iphonehigh", "240p", "320k", "360p", "SQTest", "SQ", "850k",
"480p", "HQTest", "HQ", "1400k", "720p", "2400k", "hd", "1080p", "live"]
streams = self._get_streams()
for rank in reversed(ranking):
if rank in streams:
streams["best"] = streams[rank]
break
return streams
def _get_streams(self):
raise NotImplementedError
class PluginError(Exception):
pass
class NoStreamsError(PluginError):
def __init__(self, url):
PluginError.__init__(self, ("No streams found on this URL: {0}").format(url))
class NoPluginError(PluginError):
pass
__all__ = ["Plugin", "PluginError", "NoStreamsError", "NoPluginError"]
|