Timeshifting in XMLTV (1 Viewer)

PN23

Portal Member
November 25, 2019
48
5
47
Home Country
United Kingdom United Kingdom
Any assistance here would be greatly appreciated - I am pulling my hair out with this one!

I am using a couple of IPTV services that provide me with local channels in my own country, and some of these channels are so called "+1 channels" which run an hour behind the live channels so are timezone -1

I also have a few channels from the US and these can be between -5 and -8 hours behind.

Applying time compensation in the XMLTV plugin would be a blanket change across all channels so I have not tried that, however I have tried setting tvg-shift tags in my m3u to compensate as I have done with other IPTV platforms.

MP2 (and I assume MP1 as I have never used it) does not appear to be able to work with an m3u file that is anything other than a plain simple file, so any modern tagging as would be found in m3uplus or m3u8 files results in the TV server not being able to scan any channels described in the file.

When I remove everything other than the name and path to the channel, the TV server can scan them all, but this leaves me with the XMLTV EPG issue with timings all over the place.

I have scoured the forums and found others with similar issues to me but not found an answer. Can anybody point me in the right direction with this? Is it possible to offset the time for some channels?
 

PN23

Portal Member
November 25, 2019
48
5
47
Home Country
United Kingdom United Kingdom
OK, I have figured out timeshifting in the XML file now and have written some scripts to create +1 channels etc apply the correct timeshift and add this to my exiting tvguide.xml file. If I validate this file with my normal tools (even I just create one separate XML as a test for 2 channels - one normal and one +1 variant of the same channel) this comes out fine. Even online validators show the two channels with the programming an hour different.

As soon as I import this XML into MP2, the guide shows the same data for the two channels at exactly the same time without any timeshift at all.

I am really scratching my head now.
 

PN23

Portal Member
November 25, 2019
48
5
47
Home Country
United Kingdom United Kingdom
I have this worked out now and working well for channels from -8 to +8 hours of time difference. If anyone needs to know I'm doing this post a reply and I'll put some documentation together.
 

Ravstar

New Member
October 19, 2020
9
0
Home Country
Great Britain (UK) Great Britain (UK)
Hi PN23, I have zgemma (enigma 2) box and my epg source file is out of sync by +0530 so can you help me to make a python script that should run everyday which can download the file to path /media/hdd/epg and replace +0530 with +0000? This would be .xml.gz

your help would be much appreciate.

many thanks

Rav
 

PN23

Portal Member
November 25, 2019
48
5
47
Home Country
United Kingdom United Kingdom
Hey @Ravstar,

I'll try to help, but I have never used an enigma box personally so am unsure of exactly what the directory structure would be, but you should be able to get everything done that you need at the command line in a quick shell script which can then be scheduled to run automatically using cron.

This is how I would do it:-
  • In the terminal, create a staging directory to work in. This only needs to be done once. mkdir /media/hdd/epg/staging
  • Start your preferred text editor (vi, vim, nano etc) then add each of the following lines
  • cp /media/hdd/epg/filename.xml.gz /media/hdd/epg/staging/filename.xml.gz - This will copy the gzipped xml to the staging directory
  • gunzip /media/hdd/epg/staging/filename.xml.gz - This will unzip the xml file. If gunzip is not available you could use gzip -d /media/hdd/epg/staging/filename.xml.gz instead
  • sed -i 's/+0530/+0000/g' /media/hdd/epg/staging/filename.xml - This will use the SED stream editor to find every reference to +0530 and replace it with +0000 which will result in the start and end times for all programmes being timeshifted from +0530 to +0000
  • gzip -c /media/hdd/epg/staging/filename.xml > /media/hdd/epg/staging/filename.xml.gz - This will gzip the edited XML file to filename.xml.gz
  • rm /media/hdd/epg/staging/filename.xml - This will delete the temporary XML to cleanup
  • rm /media/hdd/epg/filename.xml.gz - This will delete the original XMLTV file
  • mv /media/hdd/epg/staging/filename.xml.gz /media/hdd/epg - This will move the edited and gzipped XMLTV file back to the epg directory
  • Save this as xmltv.sh and quit the text editor
  • Back at the terminal, make this shell script executable to be able to run it - chmod +x /media/hdd/epg/staging.xmltv.sh
Once done, the shell script will be executable and can be scheduled to run as a cron job, or run at any time manually.

Before doing this though, manually run each line yourself to make sure it is working as you expect and tweak if necessary, then make those changes to the shell script and schedule it.
 

Ravstar

New Member
October 19, 2020
9
0
Home Country
Great Britain (UK) Great Britain (UK)
Hi PN23,

Thank you for your prompt reply. I am literally a layman here and have no knowledge at all for any language so what I want is a script.py that can download a xml.gz file from a url and replace +0530 with +0000 and save this in /media/hdd/epg path

The manual process I am doing everyday is, downloading the xml.gz file from a url, extracting it and replacing +0530 with +0000 with notepad++ and ftp it from my laptop to enigma 2 box at /media/hdd/epg

Like you mentioned I will place this script in a directory on my enigma 2 box and setup a unix script file in cron to run daily like

python /etc/enigma2/epg/script.py

exit 0

Any help will be much appreciated. I am based in the UK and perhaps we can connect and show you exactly how it looks.
 

PN23

Portal Member
November 25, 2019
48
5
47
Home Country
United Kingdom United Kingdom
Hi @Ravstar,

If it has to be python, then I'm probably not the right guy to be able to help you out as my python skills are not strong.

The above method would still be able to work autonomously on any Linux host though really. A line can be added at the top of the script to download the file you need to the staging location first, then it can be uncompressed, have the times edited, re-compressed, and placed where you need it to be for the data to appear in the epg.

As long as your engima2 box has a connection to the internet, it should be able to do all of this on it's own on a schedule and you wouldn't need to do anything on your laptop or copy any files across.

I have similar things working with other Linux systems but have not used an enigma2 device before.

It is easier that it probably sounds from the above - it should all be doable with 7 or 8 lines in a script.
 

Ravstar

New Member
October 19, 2020
9
0
Home Country
Great Britain (UK) Great Britain (UK)
Hi @PN23

Any shell script should work so it doesn't need to be python and following steps would be required

1. URL hit http://example.com/xml.gz
2. File download at /media/hdd/epg
3. decompress/Uncompress
4. XML tag replace
5. save at /media/hdd/epg1

It doesn't need to be compressed again.

Please can you share the script file with me if that's possible for you to make one?

Thank you for your help.
 

PN23

Portal Member
November 25, 2019
48
5
47
Home Country
United Kingdom United Kingdom
Hi @Ravstar,

All the steps you require are as above except for downloading the XML from the online source.

Drop the below into a text editor and save it as filename.sh then run chmod +x filename.sh to make it executable otherwise it will not run.

wget -O /media/hdd/epg/filename.xml.gz http://example.com/filename.xml.gz
gzip -d /media/hdd/epg/filename.xml.gz
sed -i 's/+0530/+0000/g' /media/hdd/epg/filename.xml
mv /media/hdd/epg/filename.xml /media/hdd/epg1
rm /media/hdd/epg/filename.xml.gz
 

Ravstar

New Member
October 19, 2020
9
0
Home Country
Great Britain (UK) Great Britain (UK)
Script is working fine but when I try to execute is using chmod +x /media/hdd/epg/xmltv.sh it doesn't execute despite I have placed the xmltv.sh in above directory.

Any suggestions? Thank you for your help for all above.
 
Last edited:

Users who are viewing this thread

Top Bottom