-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtv
executable file
·84 lines (73 loc) · 2.74 KB
/
tv
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
84
#!/usr/bin/python3
#
# Python TV streamer
#
# Copyright (C) 2019-11-23 Jochen Sprickerhof
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""Python TV streamer."""
from atexit import register
from datetime import datetime
from subprocess import run
from zoneinfo import ZoneInfo
from tuner import Station, Stations, main
class TV(Stations):
def __init__(self):
self.header = [
" _______ __",
"|_ _\\ \\ / /",
" | | \\ \\ / /",
" | | \\ V /",
" |_| \\_/",
]
def zapp(self):
to_zone = ZoneInfo("localtime")
shows = self.getjson(
f"https://api.zapp.mediathekview.de/v1/shows/{self.sname}"
)
if shows and "shows" in shows and "startTime" in shows["shows"][0]:
self.startTime = datetime.strptime(
shows["shows"][0]["startTime"], "%Y-%m-%dT%H:%M:%S.%f%z"
).astimezone(to_zone)
self.endTime = datetime.strptime(
shows["shows"][0]["endTime"], "%Y-%m-%dT%H:%M:%S.%f%z"
).astimezone(to_zone)
return shows["shows"][0]["title"]
return ""
channels = Station.getjson(
"https://api.zapp.mediathekview.de/v1/channelInfoList"
)
if not channels:
print("Error getting channels")
for i, channel in enumerate(channels):
offset = ord("1") if i < 9 else ord("a") - 9
self[f"{chr(offset + i)}"] = Station(
channels[channel]["name"], channels[channel]["streamUrl"], zapp, channel
)
def get_text(self, i, now):
if self[i].endTime != self[i].startTime:
percent = (
(now - self[i].startTime) / (self[i].endTime - self[i].startTime) * 100
)
if percent > 0:
return f"{percent:3.0f}% - {self[i].endTime:%H:%M} - {self[i].akt}"
return ""
def exit_handler():
run(["xset", "+dpms"])
run(["xset", "s", "on"])
if __name__ == "__main__":
run(["xset", "-dpms"])
run(["xset", "s", "off"])
register(exit_handler)
main(TV())