-
Notifications
You must be signed in to change notification settings - Fork 317
/
plugin.py
41 lines (36 loc) · 1.22 KB
/
plugin.py
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
from Plugins.Plugin import PluginDescriptor
try:
from yt_dlp import YoutubeDL
except ImportError:
YoutubeDL = None
def zap(session, service, **kwargs):
errormsg = None
if service and "http" in service.toString():
url = service.toString()
url = url.split(":")
if len(url) > 9:
url = url[10]
if YoutubeDL is not None and url.startswith("YT-DLP%3a//"):
url = url.replace("YT-DLP%3a//", "")
url = url.replace("%3a", ":")
try:
ydl = YoutubeDL({"format": "b", "no_color": True, "usenetrc": True})
result = ydl.extract_info(url, download=False)
result = ydl.sanitize_info(result)
if result and result.get("url"):
url = result["url"]
print("[ChannelSelection] zap / YoutubeDLP result url %s" % url)
return (url, errormsg)
else:
errormsg = "No Link found!"
print("[ChannelSelection] zap / YoutubeDLP no streams")
except Exception as e:
errormsg = str(e)
print("[ChannelSelection] zap / YoutubeDLP failed %s" % str(e))
pass
return (None, errormsg)
def Plugins(**kwargs):
if YoutubeDL:
return [PluginDescriptor(name="YTDLPWrapper", description="YTDLPWrapper", where=PluginDescriptor.WHERE_CHANNEL_ZAP, needsRestart=False, fnc=zap)]
else:
return []