-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathmuxmanager.py
74 lines (48 loc) · 2.21 KB
/
muxmanager.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
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
import globals
import sony
import os
import stat
import urllib
class MuxManager():
sonyObj = None
def __init__(self, s):
self.sonyObj = s
pass
def generate_playlist(self):
save_dir = os.path.dirname(os.path.realpath(__file__))
self.sonyObj.check_login()
channel_list = self.sonyObj.get_channel_list()
m3u_file = open(os.path.join(save_dir, "playlist.m3u"), "w")
m3u_file.write("#EXTM3U")
m3u_file.write("\n")
for channel_id, title, logo in channel_list:
url = "pipe://" + os.path.join(save_dir, "pipe.sh ")
url += "\"http://127.0.0.1:"+str(globals.PORT) + "/psvue?params=" + urllib.quote(globals.CHANNEL_URL + channel_id) + "\""
m3u_file.write("\n")
channel_info = '#EXTINF:-1 tvg-id="' + channel_id + '" tvg-name="' + title + '"'
if logo is not None: channel_info += ' tvg-logo="' + logo + '"'
channel_info += ' group_title="PS Vue",' + title
m3u_file.write(channel_info.encode("utf-8") + "\n")
m3u_file.write(url + "\n")
m3u_file.close()
pass
def get_playlist(self):
save_dir = os.path.dirname(os.path.realpath(__file__))
m3u_file = open(os.path.join(save_dir, "playlist.m3u"), "r")
playlist = m3u_file.read()
m3u_file.close()
return playlist
def generate_pipe_shell_file(self):
save_dir = os.path.dirname(os.path.realpath(__file__))
file_path = os.path.join(save_dir, "pipe.sh")
pipe_shell_file = open(file_path, "w")
file_contents = "#!/bin/sh"
file_contents += "\n\n"
file_contents += ". \"" + os.path.join(save_dir, "reqPayload.dat") + "\""
file_contents += "\n\n"
file_contents += "/usr/bin/ffmpeg -loglevel fatal -headers 'Cookie: reqPayload=\"'$COOKIE'\"' -user_agent \"Adobe Primetime/1.4 Dalvik/2.1.0 (Linux; U; Android 6.0.1 Build/MOB31H)\" -i $1 -acodec copy -vcodec copy -f mpegts pipe:1"
pipe_shell_file.write(file_contents)
pipe_shell_file.close()
st = os.stat(file_path)
os.chmod(file_path, st.st_mode | stat.S_IEXEC | stat.S_IXGRP | stat.S_IXUSR | stat.S_IXOTH)
pass