-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtvEPG.py
99 lines (79 loc) · 3.8 KB
/
tvEPG.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
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#########################################
# tvEPG.py - EPG per channel per EPG provider
# Some logos taken from: https://grelha-tv.blogspot.nl/p/logos.html
# by nsenica
# v1.0 - 2018
#########################################
import utils.XMLChannelList as XMLChannelList
import providers.pt_meo
import providers.pt_meo_go
import providers.pt_vodafone
import providers.pt_elevensports
import providers.pt_nos
import sys
import time
import argparse
import logging
from classes.xmltv.Channel import Channel
from classes.xmltv.XMLTV import XMLTV
parser = argparse.ArgumentParser()
parser.add_argument("-i", "--input", help="Specify the input channel list file", default="channelList.xml")
parser.add_argument("-o", "--output", help="Specify the output XMLTV filename", default="guide.xml")
parser.add_argument("-d", "--days", help="Specify the number of days to process", type=int, default=8)
parser.add_argument("-p", "--provider", help="Filter on provider", default=None)
parser.add_argument("-c", "--channel", help="Filter on channel (name)", default=None)
parser.add_argument("--debug", help="Turn debug on", action="store_true")
args = parser.parse_args()
##########################################
## channelFilename - Full filename (including path) for file which contains channels
## File format:
## tvg-id - EPG code ID for channel under m3u list
## name - channel name under m3u list
## icon - Channel icon URL
## provider - provider where to retrieve the information from
## code - Code for which channel is recognized in EPG Service
channelFilename=args.input
##########################################
if (args.debug):
logging.basicConfig(format='%(asctime)s %(levelname)-8s [%(filename)s:%(lineno)d] %(message)s', level="DEBUG")
else:
logging.basicConfig(format='%(asctime)s %(levelname)-8s [%(filename)s:%(lineno)d] %(message)s', level="INFO")
cDict = XMLChannelList.load(channelFilename, args.provider, args.channel)
if not cDict:
exit()
nrDays = args.days
xmltv = XMLTV()
for provCode,xmlChannels in cDict.items():
provXMLTV = None
start = time.time()
if provCode == "MEO":
logging.info("Getting info for MEO: " + str(len(xmlChannels)))
provXMLTV = providers.pt_meo.getEPG(xmlChannels, nrDays)
elif provCode == "MEOGO":
logging.info("Getting info for MEOGO: " + str(len(xmlChannels)))
provXMLTV = providers.pt_meo_go.getEPG(xmlChannels, nrDays)
elif provCode == "VODAFONE":
logging.info("Getting info for VODAFONE: " + str(len(xmlChannels)))
provXMLTV = providers.pt_vodafone.getEPG(xmlChannels, nrDays)
elif provCode == "ES":
logging.info("Getting info for ES: " + str(len(xmlChannels)))
provXMLTV = providers.pt_elevensports.getEPG(xmlChannels, nrDays)
elif provCode == "NOS":
logging.info("Getting info for NOS: " + str(len(xmlChannels)))
provXMLTV = providers.pt_nos.getEPG(xmlChannels, nrDays)
else:
logging.info("No provider found for: ")
for item in xmlChannels:
for channelInfo in item.getChannelList():
c = Channel(channelInfo.getId(), channelInfo.getDisplayName(), channelInfo.getLang(), channelInfo.getIconSrc())
xmltv.addChannel(c)
logging.info("\t" + channelInfo.getDisplayName())
logging.info("Got " + str(len(xmltv.getChannels())))
end = time.time()
if (provXMLTV is not None):
logging.info("["+provCode+"] Got " + str(len(provXMLTV.getChannels())) + " channels and " + str(len(provXMLTV.getProgrammes())) + " programmes in " + str(int(end-start)) + " seconds.")
xmltv.addFromXMLTV(provXMLTV)
logging.info("Total: " + str(len(xmltv.getChannels())) + " channels and " + str(len(xmltv.getProgrammes())) + " programmes.")
xmltv.writeXML(args.output)