forked from helenfernanda/gratis
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathepgfinal.py
More file actions
103 lines (85 loc) · 3.94 KB
/
Copy pathepgfinal.py
File metadata and controls
103 lines (85 loc) · 3.94 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import requests
import gzip
from lxml import etree
import os
# Configurações
EPG_SOURCES = [
"https://x1co.com.br/epg/epg.xml",
"https://raw.githubusercontent.com/JulioCesarXY/gratis/refs/heads/main/epg/epg_kpoptvbr.xml",
"https://raw.githubusercontent.com/BuddyChewChew/localnow-playlist-generator/refs/heads/main/epg.xml",
"https://epgshare01.online/epgshare01/epg_ripper_DUMMY_CHANNELS.xml.gz",
"https://raw.githubusercontent.com/JulioCesarXY/gratis/refs/heads/main/epg/epg_distrotv.xml",
"https://raw.githubusercontent.com/BuddyChewChew/xumo-playlist-generator/main/playlists/xumo_epg.xml.gz",
"https://epgshare01.online/epgshare01/epg_ripper_DISTROTV1.xml.gz",
"https://github.com/matthuisman/i.mjh.nz/raw/master/Roku/all.xml.gz",
"https://raw.githubusercontent.com/BuddyChewChew/lg-playlist-generator/main/lg_channels_us.xml",
"https://github.com/matthuisman/i.mjh.nz/raw/master/SamsungTVPlus/all.xml.gz",
"https://raw.githubusercontent.com/JulioCesarXY/EPG-Plex-Brazil/refs/heads/main/plex_epg_brasil.xml",
"https://raw.githubusercontent.com/JulioCesarXY/gerador-de-epg/refs/heads/main/yeeaahtv_epg.xml",
"https://pastebin.com/raw/PkLp1BhD",
"https://raw.githubusercontent.com/JulioCesarXY/gerador-de-epg/refs/heads/main/epg_canal_vazio.xml",
"https://raw.githubusercontent.com/JulioCesarXY/EPG-TVLatinaSat/refs/heads/main/latinasat_epg.xml"
]
OUTPUT_DIR = "epg"
OUTPUT_FILE = os.path.join(OUTPUT_DIR, "epg_final.xml")
OUTPUT_FILE_GZ = os.path.join(OUTPUT_DIR, "epg_final.xml.gz")
def fetch_content(url):
print(f"Baixando: {url}")
try:
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)'}
response = requests.get(url, headers=headers, timeout=60)
response.raise_for_status()
if url.endswith(".gz") or response.content.startswith(b'\x1f\x8b'):
return gzip.decompress(response.content)
return response.content
except Exception as e:
print(f"Erro ao baixar {url}: {e}")
return None
def merge_epgs():
if not os.path.exists(OUTPUT_DIR):
os.makedirs(OUTPUT_DIR)
combined_root = etree.Element("tv")
combined_root.set("generator-info-name", "EPG-Merger-Pro")
added_channels = set()
for url in EPG_SOURCES:
content = fetch_content(url)
if content:
try:
parser = etree.XMLParser(recover=True, remove_blank_text=True)
tree = etree.fromstring(content, parser=parser)
for channel in tree.xpath("//channel"):
channel_id = channel.get("id")
if channel_id not in added_channels:
combined_root.append(channel)
added_channels.add(channel_id)
for programme in tree.xpath("//programme"):
combined_root.append(programme)
print(f"Dados integrados com sucesso: {url}")
except Exception as e:
print(f"Erro ao processar XML de {url}: {e}")
# --- SALVAMENTO DOS ARQUIVOS ---
# 1. Converte a árvore para string XML em memória (formato bytes)
print("\nGerando dados finais...")
xml_data = etree.tostring(
combined_root,
encoding="utf-8",
xml_declaration=True,
pretty_print=True
)
# 2. Salva o XML normal
try:
with open(OUTPUT_FILE, "wb") as f:
f.write(xml_data)
print(f"Arquivo XML salvo em: {OUTPUT_FILE}")
except Exception as e:
print(f"Erro ao salvar XML: {e}")
# 3. Salva o XML Comprimido (.gz)
try:
with gzip.open(OUTPUT_FILE_GZ, "wb") as f_gz:
f_gz.write(xml_data)
print(f"Arquivo GZ salvo em: {OUTPUT_FILE_GZ}")
except Exception as e:
print(f"Erro ao criar arquivo GZ: {e}")
print(f"\nConcluído! Total de canais únicos: {len(added_channels)}")
if __name__ == "__main__":
merge_epgs()