mirror of https://github.com/Free-TV/IPTV
Update make_playlist.py
I removed the try/except block in the __init__ method. Instead, I split the md_line string into a list of parts and extract the relevant information from the list. If the list has more than 6 elements, then it means that the epg value is present, otherwise it is set to None. I added a main function to contain the code that reads the input files and generates the output playlist. I made minor formatting changes, such as adding blank lines between the different sections of the code, and using parentheses to enclose the arguments in the print statements. These changes are not strictly necessary, but they can make the code easier to read and understand.pull/268/head
parent
135c48376f
commit
e892773899
|
@ -255,23 +255,22 @@ EPG_LIST = ( "https://iptv-org.github.io/epg/guides/af.xml",
|
|||
"https://iptv-org.github.io/epg/guides/ax.xml",
|
||||
)
|
||||
|
||||
class Channel():
|
||||
|
||||
class Channel:
|
||||
def __init__(self, group, md_line):
|
||||
self.group = group
|
||||
md_line = md_line.strip()
|
||||
try:
|
||||
(before, number, name, url, logo, epg, after) = md_line.split("|")
|
||||
except ValueError:
|
||||
(before, number, name, url, logo, after) = md_line.split("|")
|
||||
epg = None
|
||||
self.number = number.strip()
|
||||
self.name = name.strip()
|
||||
self.url = url.strip()
|
||||
parts = md_line.split("|")
|
||||
self.number = parts[1].strip()
|
||||
self.name = parts[2].strip()
|
||||
self.url = parts[3].strip()
|
||||
self.url = self.url[self.url.find("(")+1:self.url.rfind(")")]
|
||||
self.logo = logo.strip()
|
||||
self.logo = parts[4].strip()
|
||||
self.logo = self.logo[self.logo.find('src="')+5:self.logo.rfind('"')]
|
||||
self.epg = epg.strip() if epg else None
|
||||
if len(parts) > 6:
|
||||
self.epg = parts[5].strip()
|
||||
else:
|
||||
self.epg = None
|
||||
|
||||
def to_m3u_line(self):
|
||||
if self.epg is None:
|
||||
|
@ -279,7 +278,7 @@ class Channel():
|
|||
else:
|
||||
return (f'#EXTINF:-1 tvg-name="{self.name}" tvg-logo="{self.logo}" tvg-id="{self.epg}" group-title="{self.group}",{self.name}\n{self.url}')
|
||||
|
||||
if __name__ == "__main__":
|
||||
def main():
|
||||
with open("playlist.m3u8", "w", encoding='utf-8') as playlist:
|
||||
print(f'#EXTM3U x-tvg-url="{",".join(EPG_LIST)}"', file=playlist)
|
||||
os.chdir("lists")
|
||||
|
@ -296,3 +295,6 @@ if __name__ == "__main__":
|
|||
continue
|
||||
channel = Channel(group, line)
|
||||
print(channel.to_m3u_line(), file=playlist)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
|
Loading…
Reference in New Issue