-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Thiago Crepaldi
committed
Dec 19, 2023
1 parent
6bf0d1f
commit 958074f
Showing
5 changed files
with
22,131 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?xml version="1.0"?> | ||
<settings> | ||
<!-- for detailed info about the settings see http://webgrabplus.com/documentation/configuration/webgrabconfigxml | ||
and http://webgrabplus.com/sites/default/files/downloads/Misc/Documented_Configuration_Files_0.zip --> | ||
<filename>guide.xml</filename> | ||
<mode> | ||
</mode> | ||
<postprocess grab="y" run="y">/usr/bin/python3 /home/thiago/dev/github/homelab-utility-belt/xmltv/update_episode_num.py --guide /home/thiago/.wg++/guide.xml --save-to /home/thiago/.wg++/guide_with_episode_num.xml</postprocess> | ||
<postprocess grab="y" run="y">/usr/bin/python3 /home/thiago/dev/github/homelab-utility-belt/xmltv/logos/add_logo.py --xmltv_in=/home/thiago/.wg++/guide_with_episode_num.xml --logos=/home/thiago/dev/github/homelab-utility-belt/xmltv/logos/my_logos.ini --xmltv_out guide_with_episode_num_icon.xml</postprocess> | ||
<user-agent>Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36 Edg/79.0.309.71</user-agent> | ||
<!-- for siteini's that need a decrypt_userkey--> | ||
<!--<decryptkey site="clarotv.com.br.EK">4K4ZbJ</decryptkey>--> | ||
<decryptkey site="mi.tv">da6158c8</decryptkey> | ||
<!-- add the correct license id values in the next line --> | ||
<license wg-username="cybervader" registered-email="cybervader@protonmail.com" password="da6158c8">To force a license update; replace this text with the letter f</license> | ||
<logging>on</logging> | ||
<retry time-out="5">4</retry> | ||
<timespan>14</timespan> | ||
<update>f</update> | ||
<!-- | ||
Replace the next dummy channel entry with the channels you want. | ||
You can look into the installed siteini.pack folder on your computer | ||
For the latest version, | ||
see http://webgrabplus.com/epg-channels for the available sites/channels | ||
or https://github.com/SilentButeo2/webgrabplus-siteinipack/tree/master/siteini.pack | ||
--> | ||
<channel update="i" site="clarotv.com.br" site_id="11_#_592" xmltv_id="02.1 Record News">02.1 Record News </channel> | ||
<channel update="i" site="clarotv.com.br" site_id="11_#_408" xmltv_id="04.1 Band Mais">04.1 Band Mais</channel> | ||
<channel update="i" site="vivo.com.br" site_id="LCH1316" xmltv_id="06.1 TV Thathi">06.1 TV Thathi</channel> | ||
<!-- 08.1 Missing RF TV at https://www.rftvoficial.com.br/programacao/ --> | ||
<channel update="i" site="clarotv.com.br" site_id="11_#_2066" xmltv_id="10.1 TV Cultura Paulista">10.1 TV Cultura Paulista</channel> | ||
<channel update="i" site="mi.tv" site_id="br##br_bfb2e086-4b15-4a62-9539-20eccab4c707" xmltv_id="10.2 Univesp TV">10.2 Univesp TV</channel> | ||
<!-- 10.3 Educacao - maybe TV Cultura Educacao or TV Educacao --> | ||
<channel update="i" site="hagah.com.br" site_id="tv-camara" xmltv_id="11.1 TV Camara">11.1 TV Camara</channel> | ||
<channel update="i" site="mi.tv" site_id="br##br_53bed41f-18f9-418e-9c2e-747b8a033cdd" xmltv_id="11.2 TV ALESP">11.2 TV ALESP</channel> | ||
<channel update="i" site="clarotv.com.br" site_id="11_#_1975" xmltv_id="11.3 TV Camara Campinas">11.3 TV Camara Campinas</channel> | ||
<channel update="i" site="vivo.com.br" site_id="LCH102" xmltv_id="11.4 TV Senado">11.4 TV Senado</channel> | ||
<!-- 11.5 Missing Radio Camara --> | ||
<channel update="i" site="clarotv.com.br" site_id="11_#_1868" xmltv_id="12.1 EPTV">12.1 EPTV</channel> | ||
<!-- 12.2 Missing EducaTV --> | ||
<channel update="i" site="hagah.com.br" site_id="rbi" xmltv_id="13.1 RBI">13.1 RBI</channel> | ||
<channel update="i" site="clarotv.com.br" site_id="11_#_521" xmltv_id="23.1 TV Seculo 21">23.1 TV Seculo 21</channel> | ||
<channel update="i" site="vivo.com.br" site_id="LCH921" xmltv_id="30.1 VTV SBT">30.1 VTV SBT</channel> | ||
<channel update="i" site="clarotv.com.br" site_id="11_#_484" xmltv_id="32.1 Rede Vida">32.1 Rede Vida</channel> | ||
<!-- 32.2 Rede Vida Educacao --> | ||
<!-- 32.3 Rede Vida Eduicacao 2 --> | ||
<channel update="i" site="hagah.com.br" site_id="cnt" xmltv_id="52.1 CNT">52.1 CNT</channel> | ||
<channel update="i" site="vivo.com.br" site_id="LCH3652" xmltv_id="56.1 Cancao Nova">56.1 Cancao Nova</channel> | ||
</settings> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
import argparse | ||
import csv | ||
import os | ||
import re | ||
import sys | ||
import xml.etree.ElementTree as ET | ||
from xml.dom.minidom import parse | ||
|
||
|
||
def main(): | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument("--xmltv_in", help="Path to XMLTV Guide file", required=True) | ||
parser.add_argument("--logos", help="Path to Logos file", required=True) | ||
parser.add_argument( | ||
"--xmltv_out", | ||
help="Path to updated XMLTV Guide file that will be created", | ||
required=False, | ||
) | ||
parser.add_argument( | ||
"--version", help="Set script version", required=False, default="0.1" | ||
) | ||
parser.add_argument( | ||
"--usage", help="Example usage", required=False, action="store_true" | ||
) | ||
args = parser.parse_args() | ||
|
||
# Check if the user has provided valid arguments | ||
check_usage(args) | ||
|
||
print("Add or change channel logos in xmltv files") | ||
print(f"Version {args.version} Thiago Crepaldi, December 2023\n") | ||
|
||
# Internal variables | ||
path = os.path.dirname(os.path.abspath(__file__)) | ||
args.xmltv_in_path = os.path.dirname(os.path.abspath(args.xmltv_in)) | ||
args.xmltv_out_path = os.path.dirname(os.path.abspath(args.xmltv_out)) | ||
args.logos_path = os.path.dirname(os.path.abspath(args.logos)) | ||
|
||
# Read the XMLTV file | ||
print(f"Reading XMLTV file {args.xmltv_in}...") | ||
xmltv_channels = {} | ||
document = parse(args.xmltv_in) | ||
for channel in document.getElementsByTagName("channel"): | ||
xmltv_id = channel.getAttribute("id").strip() | ||
icon = "" | ||
icon_element = channel.getElementsByTagName("icon") | ||
if len(icon_element) > 0: | ||
icon = icon_element.getAttribute("src").strip() | ||
xmltv_channels[xmltv_id] = icon | ||
|
||
# Read the logos file | ||
print(f"Reading logos file {args.logos}...") | ||
with open(args.logos, encoding="utf-8") as logos_file: | ||
content_reader = csv.reader(logos_file, delimiter=",") | ||
logos_changed = 0 | ||
|
||
for xmltv_id_ini, new_icon in content_reader: | ||
xmltv_id_ini, new_icon = xmltv_id_ini.strip(), new_icon.strip() | ||
if xmltv_id_ini in xmltv_channels: | ||
if new_icon.lower() != xmltv_channels[xmltv_id_ini].lower(): | ||
logos_changed += 1 | ||
was_empty = xmltv_channels[xmltv_id_ini] == "" | ||
xmltv_channels[xmltv_id_ini] = new_icon | ||
|
||
if not was_empty: | ||
print( | ||
f"Logo replaced by '{new_icon}' for channel '{xmltv_id_ini}'" | ||
) | ||
else: | ||
print( | ||
f"Missing logo added '{new_icon}' for channel '{xmltv_id_ini}'" | ||
) | ||
|
||
if logos_changed == 0: | ||
print("No logos added or changed .. ") | ||
|
||
# Update the XMLTV file with the new logos | ||
for channel in document.getElementsByTagName("channel"): | ||
xmltv_id = channel.getAttribute("id").strip() | ||
icon = "" | ||
new_icon = xmltv_channels[xmltv_id] | ||
icon_element = channel.getElementsByTagName("icon") | ||
if len(icon_element) > 0: | ||
icon = icon_element.getAttribute("src").strip() | ||
|
||
if (len(icon) == 0 and len(new_icon) > 0) or icon != new_icon: | ||
if not icon_element: | ||
icon_element = document.createElement("icon") | ||
channel.appendChild(icon_element) | ||
|
||
icon_element.setAttribute("src", new_icon) | ||
|
||
# Write the XMLTV file | ||
with open(args.xmltv_out, "w") as f: | ||
document.writexml(f, encoding="utf-8") | ||
|
||
|
||
def check_usage(args): | ||
if args.usage: | ||
message = """Example usage: | ||
** Example of a valid command line: | ||
python add_logo --xmltv_in guide.xml --xmltv_out epg_logos.xml --logos logos.ini | ||
- as webgrab+plus postprocess plugin: | ||
<postprocess run="y" grab="n">python add_logo --xmltv_in guide+2.xml --logos logos.txt</postprocess> | ||
** Content of the logos file: | ||
- syntax ... channel name, logo link | ||
- channel name must be the same as the channel_id value in the channel section of the input file | ||
- lines starting with * are considered a comment text | ||
** Example logos file content: | ||
* list of channel logo links | ||
* | ||
TV Camara , https://www.net.com.br/imagens/logo/tv_camara-1680_95x39.png | ||
TV Brasil , https://www.net.com.br/imagens/logo/tv_brasil-1683_95x39.png | ||
PREMIERE HD 3 , https://www.net.com.br/imagens/logo/premiere_hd_3_-1175_95x39.png | ||
---------------------------------------------------------------------------------------------- | ||
""" | ||
fail = False | ||
if not args.xmltv_in or not os.path.exists(args.xmltv_in): | ||
message = "invalid --xmltv_in argument, try -h for help" | ||
fail = True | ||
if not args.logos or not os.path.exists(args.logos): | ||
message = "invalid --logos arguments, try -h for help" | ||
fail = True | ||
|
||
if not args.xmltv_out: | ||
args.xmltv_out = args.xmltv_in.replace(".xml", "_logos.xml") | ||
|
||
if fail: | ||
raise RuntimeError(message) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
Oops, something went wrong.