Skip to content

Commit

Permalink
Version 0.8.16
Browse files Browse the repository at this point in the history
  • Loading branch information
Paco8 committed Mar 5, 2024
1 parent 00713ab commit bde972d
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 12 deletions.
2 changes: 1 addition & 1 deletion addon.xml
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="plugin.video.movistarplus"
name="Movistar+"
version="0.8.14"
version="0.8.16"
provider-name="Paco8">
<requires>
<!--- <import addon="xbmc.python" version="2.25.0"/> -->
Expand Down
15 changes: 15 additions & 0 deletions resources/language/resource.language.en_gb/strings.po
Expand Up @@ -494,6 +494,21 @@ msgctxt "#30312"
msgid "Export channels and EPG now"
msgstr ""

# For Movistar only
msgctxt "#30313"
msgid "The EPG export has finished."
msgstr ""

# For Movistar only
msgctxt "#30314"
msgid "Exporting {}"
msgstr ""

# For Movistar only
msgctxt "#30315"
msgid "Number of days"
msgstr ""

msgctxt "#30320"
msgid "Rating: {}"
msgstr ""
Expand Down
15 changes: 15 additions & 0 deletions resources/language/resource.language.es_es/strings.po
Expand Up @@ -459,6 +459,21 @@ msgctxt "#30312"
msgid "Export channels and EPG now"
msgstr "Exportar los canales y la guía ahora"

# For Movistar only
msgctxt "#30313"
msgid "The EPG export has finished."
msgstr "Se ha terminado de exportar la EPG."

# For Movistar only
msgctxt "#30314"
msgid "Exporting {}"
msgstr "Exportando {}"

# For Movistar only
msgctxt "#30315"
msgid "Number of days"
msgstr "Número de días"

msgctxt "#30320"
msgid "Rating: {}"
msgstr "Calificación: {}"
Expand Down
43 changes: 33 additions & 10 deletions resources/lib/movistar.py
Expand Up @@ -11,7 +11,7 @@
import os
import time
import re
from datetime import datetime
from datetime import datetime, timedelta

from .endpoints import endpoints
from .log import LOG, print_json
Expand Down Expand Up @@ -472,14 +472,17 @@ def load_epg_data(self, date_str, duration=2, channels=''):
return data

def get_epg(self, date=None, duration=2, channels=None):
if channels:
if channels or date:
if not date:
today = datetime.today()
date = today.strftime('%Y-%m-%dT00:00:00')
ch_data = self.load_epg_data(date, duration, channels)
if not ch_data or 'error' in ch_data: return {}
data = []
data.append(ch_data)
epg_data = self.load_epg_data(date, duration, channels if channels else '')
if not epg_data or 'error' in epg_data: return {}
if channels:
data = []
data.append(epg_data)
else:
data = epg_data
else:
cache_filename = 'epg_{}.json'.format(self.quality)
content = self.cache.load(cache_filename, 6*60)
Expand Down Expand Up @@ -1288,14 +1291,15 @@ def export_channels_to_m3u8(self, filename):
with io.open(filename, 'w', encoding='utf-8', newline='') as handle:
handle.write(res)

def export_epg(self):
def export_epg(self, date=None, duration=2):
if sys.version_info[0] >= 3:
from urllib.parse import urlencode
else:
from urllib import urlencode
#now = time.time()*1000

res = {}
epg = self.get_epg()
epg = self.get_epg(date, duration)
channels = self.get_channels()
for channel in channels:
id = channel['id']
Expand Down Expand Up @@ -1334,7 +1338,7 @@ def export_epg(self):
res[id].append(t)
return res

def export_epg_to_xml(self, filename):
def export_epg_to_xml(self, filename, ndays=3, report_func=None):
if sys.version_info[0] < 3:
# Python 2
from cgi import escape as html_escape
Expand All @@ -1354,7 +1358,26 @@ def export_epg_to_xml(self, filename):
' <icon src="{}"/>\n'.format(t['logo']) +
'</channel>\n')

epg = self.export_epg()
if True:
epg = {}
today = datetime.today()
total_items = 0
for i in range(0, ndays, 1):
date = today + timedelta(days=i)
strdate = date.strftime('%Y-%m-%dT00:00:00')
LOG('epg: {}'.format(strdate))
if report_func:
report_func(strdate.split('T')[0])
e = self.export_epg(strdate, 1)
LOG('epg: channels: {}'.format(len(e)))
for ch in e:
if not ch in epg: epg[ch] = []
total_items += len(e[ch])
epg[ch].extend(e[ch])
LOG('epg: total items: {}'.format(total_items))
else:
epg = self.export_epg()

for ch in channels:
if not ch['id'] in epg: continue
for e in epg[ch['id']]:
Expand Down
6 changes: 5 additions & 1 deletion resources/lib/plugin.py
Expand Up @@ -622,6 +622,9 @@ def iptv(params):
# pass

def export_epg_now():
def report_progress(message):
show_notification(addon.getLocalizedString(30314).format(message), xbmcgui.NOTIFICATION_INFO)

if not m.logged: return
folder = addon.getSetting('epg_folder')
if sys.version_info[0] > 2:
Expand All @@ -632,7 +635,8 @@ def export_epg_now():
show_notification(addon.getLocalizedString(30310), xbmcgui.NOTIFICATION_INFO)
m.export_channels_to_m3u8(channels_filename)
show_notification(addon.getLocalizedString(30311), xbmcgui.NOTIFICATION_INFO)
m.export_epg_to_xml(epg_filename)
m.export_epg_to_xml(epg_filename, addon.getSettingInt('export_days'), report_progress)
show_notification(addon.getLocalizedString(30313), xbmcgui.NOTIFICATION_INFO)

def to_wishlist(params):
stype = params['stype']
Expand Down
1 change: 1 addition & 0 deletions resources/settings.xml
Expand Up @@ -38,6 +38,7 @@
<category label="30304">
<setting label="30306" type="folder" id="epg_folder" source="" default="" option="writeable"/>
<setting label="30305" type="bool" id="export_epg" default="false" enable="!eq(-1,)"/>
<setting label="30315" type="number" id="export_days" default="3"/>
<setting label="30308" type="action" action="Addon.OpenSettings(pvr.iptvsimple)" option="close" visible="System.HasAddon(pvr.iptvsimple)" enable="eq(-1,true)" subsetting="true"/>
<setting label="30307" type="action" action="InstallAddon(pvr.iptvsimple)" option="close" visible="!System.HasAddon(pvr.iptvsimple)" enable="eq(-2,true)" subsetting="true"/>
<setting label="30312" type="action" id="export_epg_now" action="RunPlugin(plugin://plugin.video.movistarplus/?action=export_epg_now)" option="close" enable="!eq(-4,)"/>
Expand Down

0 comments on commit bde972d

Please sign in to comment.