Repository navigation
Expand file tree
/
Copy pathARD.py
More file actions
83 lines (60 loc) · 2.48 KB
/
Copy pathARD.py
File metadata and controls
83 lines (60 loc) · 2.48 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import subprocess
import re
import os.path
import os
from module.utils import save_join, save_path
from module.plugins.Hoster import Hoster
# Requires rtmpdump
# by Roland Beermann
class RTMP:
# TODO: Port to some RTMP-library like rtmpy or similar
# TODO?: Integrate properly into the API of pyLoad
command = "rtmpdump"
@classmethod
def download_rtmp_stream(cls, url, output_file, playpath=None):
opts = [
"-r", url,
"-o", output_file,
]
if playpath:
opts.append("--playpath")
opts.append(playpath)
cls._invoke_rtmpdump(opts)
@classmethod
def _invoke_rtmpdump(cls, opts):
args = [
cls.command
]
args.extend(opts)
return subprocess.check_call(args)
class ARD(Hoster):
__name__ = "ARD Mediathek"
__version__ = "0.12"
__pattern__ = r"http://www\.ardmediathek\.de/.*"
__config__ = []
def process(self, pyfile):
site = self.load(pyfile.url)
avail_videos = re.findall(
r'mediaCollection.addMediaStream\(0, ([0-9]*), "([^\"]*)", "([^\"]*)", "[^\"]*"\);', site)
avail_videos.sort(key=lambda videodesc: int(videodesc[0]),
reverse=True) # The higher the number, the better the quality
quality, url, playpath = avail_videos[0]
pyfile.name = re.search(r"<h1>([^<]*)</h1>", site).group(1)
if url.startswith("http"):
# Best quality is available over HTTP. Very rare.
self.download(url)
else:
pyfile.setStatus("downloading")
download_folder = self.config['general']['download_folder']
location = save_join(download_folder, pyfile.package().folder)
if not os.path.exists(location):
os.makedirs(location, int(self.config["permission"]["folder"], 8))
if self.config["permission"]["change_dl"] and os.name != "nt":
try:
uid = getpwnam(self.config["permission"]["user"])[2]
gid = getgrnam(self.config["permission"]["group"])[2]
chown(location, uid, gid)
except Exception, e:
self.logWarning(_("Setting User and Group failed: %s") % str(e))
output_file = save_join(location, save_path(pyfile.name)) + os.path.splitext(playpath)[1]
RTMP.download_rtmp_stream(url, playpath=playpath, output_file=output_file)