Python: how to zap to channel

Moderátor: Moderátoři

Příspěvky: 398
Registrován: 31 led 2015 08:30

Python: how to zap to channel

Příspěvekod ni_hao » 05 zář 2017 08:02

I have 4 WiFi IP cams, which are in my servicelist.
The 1st CAM entry in that list is: 4097:0:0:9991:0:0:0:0:0:0:rtsp://192.168.2.24/live/ch00_1 CAM 1
When I want to switch to that channel in CLI I have to enter:

Kód: Vybrat vše
/usr/bin/wget -q -O - http://127.0.0.1/web/zap?sRef=4097:0:0:9991:0:0:0:0:0:0:rtsp%253a%2F%2F192.168.2.24%2Flive%2Fch00_1%3ACAM%201"

Now, I am trying to write a plugin which will allow me to zap between all my ip cams every x seconds. I want to know first how I can zap in python to 1 cam.
I tried first with having python execute the wget commands, but it did not work.

I read in current .py files (WebInterface/WebChilds/PlayService.py) that there is: self.nav.PlayService(eServiceReference(sref)), but how to use it in a .py file.
What I have now is very simple:
Kód: Vybrat vše
from Plugins.Plugin import PluginDescriptor
from enigma import eServiceReference
       
def main(self):
   sref = "4097:0:0:0:0:0:0:0:0:0:rtsp://192.168.2.24/live/ch00_1"
   self.nav.PlayService(eServiceReference(sref))

def Plugins(**kwargs):
   return [PluginDescriptor(name="Zap2Cams", description=_("Zap2Cams"), where = [PluginDescriptor.WHERE_EXTENSIONSMENU ], fnc=main)]


but does not work; who can help me?

Příspěvky: 398
Registrován: 31 led 2015 08:30

Re: Python: how to zap to channel

Příspěvekod ni_hao » 05 zář 2017 13:00

Sorry: "def main(self):" should be "def main(session, **kwargs):"

shamann
Administrátor
Příspěvky: 2410
Registrován: 21 lis 2014 20:53

Re: Python: how to zap to channel

Příspěvekod shamann » 05 zář 2017 14:19

Hi

I write whole plugin in 30min but not tested - full version with auto switch - so there can be some error ....

Best regards

Příspěvky: 398
Registrován: 31 led 2015 08:30

Re: Python: how to zap to channel

Příspěvekod ni_hao » 08 zář 2017 10:47

thanks so much, unfortunately an error
Kód: Vybrat vše
Screen <class 'Plugins.Extensions.CamZap.plugin.StartShow'>((), {}): <type 'exceptions.AttributeError'>
Traceback (most recent call last):
  File "/usr/lib/enigma2/python/mytest.py", line 350, in create
    return screen(self, *arguments, **kwargs)
  File "/usr/lib/enigma2/python/Plugins/Extensions/CamZap/plugin.py", line 58, in __init__
    self.SwitchTimer.timeout.get().append(self.changeSource)
AttributeError: 'eSignal0X' object has no attribute 'get'

line 57 and 58 are:

except AttributeError:
self.SwitchTimer.timeout.get().append(self.changeSource)

shamann
Administrátor
Příspěvky: 2410
Registrován: 21 lis 2014 20:53

Re: Python: how to zap to channel

Příspěvekod shamann » 08 zář 2017 11:34

sorry, fixed ...

Příspěvky: 398
Registrován: 31 led 2015 08:30

Re: Python: how to zap to channel

Příspěvekod ni_hao » 09 zář 2017 08:46

It did not work, but after I imported ActionMap from Components.ActionMap, it was running without errors! Super
However there are some things:

1. I think the timer was not good. After I changed "self.SwitchTimer.startLongTimer(60*TIME_SWITCH)" to: "self.SwitchTimer.startLongTimer(TIME_SWITCH)" it was good.

2. Further I wanted to have the picons showed in OLED so I have changed the source by using different SIDs in the URLs (and each cam has its own IP):

'rtsp://192.168.2.24/live/ch00_1' --> '4097:0:1:9991:0:0:0:0:0:0:rtsp://192.168.2.24/live/ch00_1'
'rtsp://192.168.2.24/live/ch00_2' --> '4097:0:1:9992:0:0:0:0:0:0:rtsp://192.168.2.22/live/ch00_1'
'rtsp://192.168.2.24/live/ch00_3' --> '4097:0:1:9993:0:0:0:0:0:0:rtsp://192.168.2.23/live/ch00_1'
'rtsp://192.168.2.24/live/ch00_4' --> '4097:0:1:9994:0:0:0:0:0:0:rtsp://192.168.2.21/live/ch00_1'

and:
sref = eServiceReference('4097:0:1:0:0:0:0:0:0:0:' + allUrls[self.index].replace(':', '%3a')) --> sref = eServiceReference(allUrls[self.index].replace('rtsp:', 'rtsp%3a'))

Now the skin shows numbers, which are the index numbers of the array (list). So it starts with "0", I wanted this to be the number of the cam, so I changed:
self['index_url'].setText(str(self.index)) --> self['index_url'].setText(str(self.index + 1)), which working

2 Questions:
1. Is is possible not to use self.index for getting the number in the skin, but show in skin element the number of position 12 of each URL
(which is the last digit of 999x)? something like: self['index_url'].setText(URls[12])

2. Is it possible not defining an array with URLs (allUrls), but read the bouquet file (where all the cam (URLs) are in)?
Something like:

Kód: Vybrat vše
import os

BOUQUET = "/etc/enigma2/userbouquet.cams.tv"

if os.path.isfile(BOUQUET):
    URLs = []
    with open(BOUQUET) as fobj:
        for line in fobj:
            if "#SERVICE" in line:
                row = line.split()
                URLs.append(row[1:2])
else:
    self.exit


Of course you have to change the "sref =" line in something like:

sref = eServiceReference(URLs[self.index])
{ no replacement needed in "sref =", because in bouquet file is already "'rtsp%3a" }

shamann
Administrátor
Příspěvky: 2410
Registrován: 21 lis 2014 20:53

Re: Python: how to zap to channel

Příspěvekod shamann » 09 zář 2017 11:03

changed/fixed ... and of course you can change to loading of array by any fnc/way you want

Příspěvky: 398
Registrován: 31 led 2015 08:30

Re: Python: how to zap to channel

Příspěvekod ni_hao » 09 zář 2017 15:18

Thx again. If I use the following, what is wrong with CAMNO?

Kód: Vybrat vše
if '4097:0:' in sref:
    sref = allUrls[self.index].replace('://', '%3a//')
    CAMNO = sref[12]
    self['index_url'].setText(str(CAMNO))

shamann
Administrátor
Příspěvky: 2410
Registrován: 21 lis 2014 20:53

Re: Python: how to zap to channel

Příspěvekod shamann » 09 zář 2017 15:32

nothing, it is ok but I do not recommended to use char number from url to use index is better way

Příspěvky: 398
Registrován: 31 led 2015 08:30

Re: Python: how to zap to channel

Příspěvekod ni_hao » 09 zář 2017 18:00

I get error msg, so must be something wrong with syntax in line with "CAMNO ="
Using index is possible when you never change the URLs, so always use 4 URLs. But what if I only use as allUrls: cam 2 and cam 4...

error was: unexpected ident. Normally it will be space in front of a command in a loop or so, but could not find it.
I deleted the line with "CAMNO = " and changed it to:

Kód: Vybrat vše
sref = allUrls[self.index].replace('://', '%3a//')
          self['index_url'].setText(sref[12])

Now working fine ;)

Next is making menu to display how many cams should be shown (1, 2, 3 or 4) ;)

shamann
Administrátor
Příspěvky: 2410
Registrován: 21 lis 2014 20:53

Re: Python: how to zap to channel

Příspěvekod shamann » 09 zář 2017 18:37

ok, use for your enjoy :)


Zpět na Plugins

Kdo je online

Uživatelé procházející toto fórum: Žádní registrovaní uživatelé a 1 návštěvník