Release - Execute user tasks for Kodi events (callbacks ver2)

  Thread Rating:
  • 3 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Post Reply
KenV99 Offline
Fan
Posts: 505
Joined: Nov 2013
Reputation: 28
Post: #31
(2016-01-28 00:08)AvanOsch Wrote:  Thanks for a great plugin Ken.

I want to run a command that normally requires "sudo".
How would I go about doing that?

Thanks for your reply!
P.S.
The version I downloaded still had the "debug = True", causing a (pydevd) import error.
-EDIT-
Maybe you could add a check for the files "pycharm-debug.py3k" and "pycharm-debug.egg", so debug gets skipped if those don't exist...

The latest version has the debug error fixed (again).

I don't have a linux environment up and running to test on, but it seems that you need to call a helper .sh script to invoke the actual script.
Based on: http://unix.stackexchange.com/questions/...h-one-sudo
Set your script to run the helper script, passing the actual script file url as an argument
So the helper script would look like:
Code:
sudo "$BASH" -c "$(fc -ln -1)"
Which in turn would invoke your original script in sudo.

You may need to tweak this to get it right. Right now I've been using the git bash on windows for testing .sh and I can't test the whole sudo thing in that context. Perhaps an experienced linux bash person can chime in.

Edit:
The above is for the command line.
I think it would look something like:
Code:
sudo "$BASH" "$@"

Edit 2:
I tested and the above works. ("$*" didn't, "$@" does).

To supply a password:
Code:
#!/usr/bin/env bash
echo mypassword | sudo -S bash "$@"
(This post was last modified: 2016-01-29 00:18 by KenV99.)
find quote
thildemar Offline
Junior Member
Posts: 22
Joined: Sep 2010
Reputation: 0
Post: #32
Hello,

Hoping someone might be able to help me out here. My knowledge of Kodi/Python is not great. I am basically trying to get this addon to call a python script on playback that will trigger a URL if the media content is a movie or TV episode. I have task1 set to python file with the import option. Event is on playback passing "%mt" as an argument. Here is the py file I am calling:
Code:
import urllib2

def run(arg):
    if arg[0] == 'movie' or arg[0] == 'episode':
        urllib2.urlopen('Http://URLHERE').read()

When I run this as test command in the addon config it fires correctly and calls the URL as expected. When I try to actually play a file the log says it has fired, but the URL is not called.

Code:
11:36:47 T:11388  NOTICE: $$$ [kodi.callbacks] - Task starting for onPlayBackStarted
11:36:47 T:11388  NOTICE: $$$ [kodi.callbacks] - Command for Task T1, Event onPlayBackStarted completed succesfully!
11:36:47 T:11388  NOTICE: $$$ [kodi.callbacks] - Task finalized for onPlayBackStarted


I am sure I am missing something here, can anyone help?
find quote
KenV99 Offline
Fan
Posts: 505
Joined: Nov 2013
Reputation: 28
Post: #33
(2016-01-31 20:43)thildemar Wrote:  Hello,

Hoping someone might be able to help me out here. My knowledge of Kodi/Python is not great. I am basically trying to get this addon to call a python script on playback that will trigger a URL if the media content is a movie or TV episode. I have task1 set to python file with the import option. Event is on playback passing "%mt" as an argument. Here is the py file I am calling:
Code:
import urllib2

def run(arg):
    if arg[0] == 'movie' or arg[0] == 'episode':
        urllib2.urlopen('Http://URLHERE').read()

When I run this as test command in the addon config it fires correctly and calls the URL as expected. When I try to actually play a file the log says it has fired, but the URL is not called.

Code:
11:36:47 T:11388  NOTICE: $$$ [kodi.callbacks] - Task starting for onPlayBackStarted
11:36:47 T:11388  NOTICE: $$$ [kodi.callbacks] - Command for Task T1, Event onPlayBackStarted completed succesfully!
11:36:47 T:11388  NOTICE: $$$ [kodi.callbacks] - Task finalized for onPlayBackStarted


I am sure I am missing something here, can anyone help?

I recently made a lot of changes that may or may not help with your issue so please download the latest from github.
One possible problem is that despite doing many things to sort out media type for a given file, the addon cannot sometimes figure it out and pass 'unknown'.
To figure this out you can do:
Code:
import urllib2
import xbmcgui

def notify(msg):
    dialog = xbmcgui.Dialog()
    dialog.notification('Kodi Callabacks', msg, xbmcgui.NOTIFICATION_INFO, 5000)

def run(arg):
    msg = 'Received args: %s' % str(arg)
    notify(msg)
    if arg[0] == 'movie' or arg[0] == 'episode':
        msg = 'Received args: %s' % str(arg)
        notify(msg)
        urllib2.urlopen('Http://URLHERE').read()

The contents of arg will be shown as a notification at the time the event fires and you can see if the media type is movie or episode.
(This post was last modified: 2016-01-31 22:41 by KenV99.)
find quote
thildemar Offline
Junior Member
Posts: 22
Joined: Sep 2010
Reputation: 0
Post: #34
Hi Ken,

Thanks for the update. I tested the new build and this code on my PC and it seems to work fine. Unfortunately when I tried to install the new build on my FireTV I get all kinds of addon errors on startup. Here is the log:

http://pastebin.com/raw/E3g8mpds

I am running Jarvis RC2, not sure if there are any known compatibility issues with the new release...
find quote
KenV99 Offline
Fan
Posts: 505
Joined: Nov 2013
Reputation: 28
Post: #35
(2016-02-02 03:09)thildemar Wrote:  Hi Ken,

Thanks for the update. I tested the new build and this code on my PC and it seems to work fine. Unfortunately when I tried to install the new build on my FireTV I get all kinds of addon errors on startup. Here is the log:

http://pastebin.com/raw/E3g8mpds

I am running Jarvis RC2, not sure if there are any known compatibility issues with the new release...

I don't have an android platform to test if this is the error you are encountering, but the current problem is most likely caused by not renaming the directory, removing the -master from the directory name:
Add-on:Kodi_Callbacks#Details (wiki)
find quote
thildemar Offline
Junior Member
Posts: 22
Joined: Sep 2010
Reputation: 0
Post: #36
(2016-02-02 13:45)KenV99 Wrote:  
(2016-02-02 03:09)thildemar Wrote:  Hi Ken,

Thanks for the update. I tested the new build and this code on my PC and it seems to work fine. Unfortunately when I tried to install the new build on my FireTV I get all kinds of addon errors on startup. Here is the log:

http://pastebin.com/raw/E3g8mpds

I am running Jarvis RC2, not sure if there are any known compatibility issues with the new release...

I don't have an android platform to test if this is the error you are encountering, but the current problem is most likely caused by not renaming the directory, removing the -master from the directory name:
Add-on:Kodi_Callbacks#Details (wiki)

With the new build should the directory be service.kodi.callbacks or script.service.kodi.callbacks? Still getting the error with it labeled either way:

Code:
log(msg=_('Localized string not found for: [%s]') % strToId)
                                              File "/storage/emulated/0/Android/data/org.xbmc.kodi/files/.kodi/addons/service.kodi.callbacks/resources/lib/utils/poutil.py", line 75, in getLocalizedString
find quote
KenV99 Offline
Fan
Posts: 505
Joined: Nov 2013
Reputation: 28
Post: #37
(2016-02-03 04:11)thildemar Wrote:  
(2016-02-02 13:45)KenV99 Wrote:  
(2016-02-02 03:09)thildemar Wrote:  Hi Ken,

Thanks for the update. I tested the new build and this code on my PC and it seems to work fine. Unfortunately when I tried to install the new build on my FireTV I get all kinds of addon errors on startup. Here is the log:

http://pastebin.com/raw/E3g8mpds

I am running Jarvis RC2, not sure if there are any known compatibility issues with the new release...

I don't have an android platform to test if this is the error you are encountering, but the current problem is most likely caused by not renaming the directory, removing the -master from the directory name:
Add-on:Kodi_Callbacks#Details (wiki)

With the new build should the directory be service.kodi.callbacks or script.service.kodi.callbacks? Still getting the error with it labeled either way:

Code:
log(msg=_('Localized string not found for: [%s]') % strToId)
                                              File "/storage/emulated/0/Android/data/org.xbmc.kodi/files/.kodi/addons/service.kodi.callbacks/resources/lib/utils/poutil.py", line 75, in getLocalizedString

With the last two versions it should be 'script.service.kodi.callbacks'.
Please try downloading the latest and rename to the above and see if that helps.
Thx for helping me debug this.
find quote
winger88 Offline
Junior Member
Posts: 2
Joined: Feb 2016
Reputation: 0
Post: #38
Same issue - renamed and placed in directory. Can only speak for android, have not tested on windows/linux

Line 78 of poutil.py
log(msg=_('Localized string not found for: [%s]') % strToId)
find quote
KenV99 Offline
Fan
Posts: 505
Joined: Nov 2013
Reputation: 28
Post: #39
(2016-02-03 18:15)winger88 Wrote:  Same issue - renamed and placed in directory. Can only speak for android, have not tested on windows/linux

Line 78 of poutil.py
log(msg=_('Localized string not found for: [%s]') % strToId)

Please post a full log to pastebin and post the link here. Thx.
find quote
KenV99 Offline
Fan
Posts: 505
Joined: Nov 2013
Reputation: 28
Post: #40
I pushed a new update just now.
Please let me know if it has helped the Android bug.
Difficult to troubleshoot since I cannot reproduce.
Will try to run in an Android emulator when I have time.

EDIT:
I think I solved it just now: stupid backslashes in strings.po path not accepted by android.
Will check through rest of code shortly.
Fixed code available with latest master as of 6:10pm Eastern time US.
(This post was last modified: 2016-02-04 01:10 by KenV99.)
find quote
winger88 Offline
Junior Member
Posts: 2
Joined: Feb 2016
Reputation: 0
Post: #41
ImportError - No module named requests.

Line 22 in taskHttp.py
(This post was last modified: 2016-02-04 01:53 by winger88.)
find quote
KenV99 Offline
Fan
Posts: 505
Joined: Nov 2013
Reputation: 28
Post: #42
(2016-02-04 01:52)winger88 Wrote:  ImportError - No module named requests.

Line 22 in taskHttp.py

requests is a dependency: https://github.com/KenV99/script.service.../addon.xml

Kodi should have downloaded and installed it at first run.
It successfully did so when I ran on my emulator.
You can install manually from here: https://github.com/beenje/script.module.requests
find quote
thildemar Offline
Junior Member
Posts: 22
Joined: Sep 2010
Reputation: 0
Post: #43
Thanks Ken,

New build is working on FireTV after I removed old paths and re-installed from zip file (with modified directory).

Next question: Any reason media pause and resume don't support the mediatype argument?
find quote
KenV99 Offline
Fan
Posts: 505
Joined: Nov 2013
Reputation: 28
Post: #44
(2016-02-04 04:44)thildemar Wrote:  Thanks Ken,

New build is working on FireTV after I removed old paths and re-installed from zip file (with modified directory).

Next question: Any reason media pause and resume don't support the mediatype argument?

No. No one asked and I couldn't think of a reason to use the media type with those events. I'll add it in the next build. How will you be using those events with media type?

EDIT: I added it in. Please download the latest and let me know if you have any troubles.
(This post was last modified: 2016-02-04 13:35 by KenV99.)
find quote
thildemar Offline
Junior Member
Posts: 22
Joined: Sep 2010
Reputation: 0
Post: #45
(2016-02-04 04:48)KenV99 Wrote:  
(2016-02-04 04:44)thildemar Wrote:  Thanks Ken,

New build is working on FireTV after I removed old paths and re-installed from zip file (with modified directory).

Next question: Any reason media pause and resume don't support the mediatype argument?

No. No one asked and I couldn't think of a reason to use the media type with those events. I'll add it in the next build. How will you be using those events with media type?

EDIT: I added it in. Please download the latest and let me know if you have any troubles.

Thanks, I'll try and test tonight.

I am using your addon to trigger events in SmartThings for lighting control using an app I wrote on that side (https://community.smartthings.com/t/beta...ol/34068). I only want to send lighting triggers when playing back TV or Movies, not music or TVTunes or whatnot. That's why the if statement in the code above and why I want mediatype in the pause/resume event.

Thanks again!
find quote
Post Reply