-
Notifications
You must be signed in to change notification settings - Fork 14
/
main.py
47 lines (32 loc) · 1020 Bytes
/
main.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
#!/usr/bin/env python3
# system imports
import os
import sys
from typing import List
# 3rd parties imports
import requests
# local imports
import rakuten
def generate_list(channels: List[rakuten.Channel]) -> str:
list_builder = []
list_builder.append("#EXTM3U")
# get streams
ch_streams = rakuten.map_channels_streams(channels)
head_line_format = "#EXTINF:-1 tvg-chno={} tvg-id=\"{}\" tvg-name=\"{}\" group-title=\"{}\",{}"
for ch in sorted(channels, key=lambda x: x.channel_number):
head_line = head_line_format.format(
ch.channel_number,
ch.id,
ch.title,
ch.category.lower().replace(" ", "_"),
ch.title,
)
list_builder.append(head_line)
list_builder.append(ch_streams.get(ch.id, "# no_stream"))
return "\n".join(list_builder)
def main():
channels = rakuten.get_channels()
m3u_list = generate_list(channels)
print(m3u_list)
if __name__ == "__main__":
sys.exit(main())