Private GIT
Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
CouchPotatoServer
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
vlbox
CouchPotatoServer
Commits
36fee698
Commit
36fee698
authored
Jan 6, 2013
by
Ruud
Browse files
Options
Downloads
Patches
Plain Diff
XBMC notifier for Frodo & Eden
parent
c5cae5ab
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
couchpotato/core/notifications/xbmc/__init__.py
+1
-1
1 addition, 1 deletion
couchpotato/core/notifications/xbmc/__init__.py
couchpotato/core/notifications/xbmc/main.py
+72
-76
72 additions, 76 deletions
couchpotato/core/notifications/xbmc/main.py
with
73 additions
and
77 deletions
couchpotato/core/notifications/xbmc/__init__.py
+
1
−
1
View file @
36fee698
...
@@ -10,7 +10,7 @@ config = [{
...
@@ -10,7 +10,7 @@ config = [{
'
tab
'
:
'
notifications
'
,
'
tab
'
:
'
notifications
'
,
'
name
'
:
'
xbmc
'
,
'
name
'
:
'
xbmc
'
,
'
label
'
:
'
XBMC
'
,
'
label
'
:
'
XBMC
'
,
'
description
'
:
'
v11 (
Dharma
) and v12 (Frodo)
'
,
'
description
'
:
'
v11 (
Eden
) and v12 (Frodo)
'
,
'
options
'
:
[
'
options
'
:
[
{
{
'
name
'
:
'
enabled
'
,
'
name
'
:
'
enabled
'
,
...
...
This diff is collapsed.
Click to expand it.
couchpotato/core/notifications/xbmc/main.py
+
72
−
76
View file @
36fee698
...
@@ -12,20 +12,22 @@ log = CPLog(__name__)
...
@@ -12,20 +12,22 @@ log = CPLog(__name__)
class
XBMC
(
Notification
):
class
XBMC
(
Notification
):
listen_to
=
[
'
renamer.after
'
]
listen_to
=
[
'
renamer.after
'
]
firstRun
=
True
use_json_notifications
=
{}
useJSONnotifications
=
True
def
notify
(
self
,
message
=
''
,
data
=
{},
listener
=
None
):
def
notify
(
self
,
message
=
''
,
data
=
{},
listener
=
None
):
if
self
.
isDisabled
():
return
if
self
.
isDisabled
():
return
hosts
=
splitString
(
self
.
conf
(
'
host
'
))
hosts
=
splitString
(
self
.
conf
(
'
host
'
))
if
self
.
firstRun
or
listener
==
"
test
"
:
return
self
.
getXBMCJSONversion
(
hosts
,
message
=
message
)
successful
=
0
successful
=
0
for
host
in
hosts
:
for
host
in
hosts
:
if
self
.
useJSONnotifications
:
if
self
.
use_json_notifications
.
get
(
host
)
is
None
:
self
.
getXBMCJSONversion
(
host
,
message
=
message
)
if
self
.
use_json_notifications
.
get
(
host
):
response
=
self
.
request
(
host
,
[
response
=
self
.
request
(
host
,
[
(
'
GUI.ShowNotification
'
,
{
"
title
"
:
self
.
default_title
,
"
message
"
:
message
}),
(
'
GUI.ShowNotification
'
,
{
'
title
'
:
self
.
default_title
,
'
message
'
:
message
}),
(
'
VideoLibrary.Scan
'
,
{}),
(
'
VideoLibrary.Scan
'
,
{}),
])
])
else
:
else
:
...
@@ -34,22 +36,20 @@ class XBMC(Notification):
...
@@ -34,22 +36,20 @@ class XBMC(Notification):
try
:
try
:
for
result
in
response
:
for
result
in
response
:
if
(
result
.
get
(
'
result
'
)
and
result
[
'
result
'
]
==
"
OK
"
):
if
(
result
.
get
(
'
result
'
)
and
result
[
'
result
'
]
==
'
OK
'
):
successful
+=
1
successful
+=
1
elif
(
result
.
get
(
'
error
'
)):
elif
(
result
.
get
(
'
error
'
)):
log
.
error
(
"
XBMC error; %s: %s (%s)
"
,
(
result
[
'
id
'
],
result
[
'
error
'
][
'
message
'
],
result
[
'
error
'
][
'
code
'
]))
log
.
error
(
'
XBMC error; %s: %s (%s)
'
,
(
result
[
'
id
'
],
result
[
'
error
'
][
'
message
'
],
result
[
'
error
'
][
'
code
'
]))
except
:
except
:
log
.
error
(
'
Failed parsing results: %s
'
,
traceback
.
format_exc
())
log
.
error
(
'
Failed parsing results: %s
'
,
traceback
.
format_exc
())
return
successful
==
len
(
hosts
)
*
2
return
successful
==
len
(
hosts
)
*
2
# TODO: implement multiple hosts support, for now the last host of the 'hosts' array
def
getXBMCJSONversion
(
self
,
host
,
message
=
''
):
# sets 'useJSONnotifications'
def
getXBMCJSONversion
(
self
,
hosts
,
message
=
''
):
success
=
False
success
=
0
for
host
in
hosts
:
# XBMC JSON-RPC version request
# XBMC JSON-RPC version request
response
=
self
.
request
(
host
,
[
response
=
self
.
request
(
host
,
[
(
'
JSONRPC.Version
'
,
{})
(
'
JSONRPC.Version
'
,
{})
...
@@ -60,54 +60,50 @@ class XBMC(Notification):
...
@@ -60,54 +60,50 @@ class XBMC(Notification):
# v6 (as of XBMC v12(Frodo)) is required to send notifications
# v6 (as of XBMC v12(Frodo)) is required to send notifications
xbmc_rpc_version
=
str
(
result
[
'
result
'
][
'
version
'
])
xbmc_rpc_version
=
str
(
result
[
'
result
'
][
'
version
'
])
log
.
debug
(
"
XBMC JSON-RPC Version: %s ; Notifications by JSON-RPC only supported for v6 [as of XBMC v12(Frodo)]
"
,
xbmc_rpc_version
)
log
.
debug
(
'
XBMC JSON-RPC Version: %s ; Notifications by JSON-RPC only supported for v6 [as of XBMC v12(Frodo)]
'
,
xbmc_rpc_version
)
# disable JSON use
# disable JSON use
self
.
use
JSON
notifications
=
False
self
.
use
_json_
notifications
[
host
]
=
False
# send the text message
# send the text message
resp
=
self
.
notifyXBMCnoJSON
(
host
,
{
'
title
'
:
self
.
default_title
,
'
message
'
:
message
})
resp
=
self
.
notifyXBMCnoJSON
(
host
,
{
'
title
'
:
self
.
default_title
,
'
message
'
:
message
})
for
result
in
resp
:
for
result
in
resp
:
if
(
result
.
get
(
'
result
'
)
and
result
[
'
result
'
]
==
"
OK
"
):
if
(
result
.
get
(
'
result
'
)
and
result
[
'
result
'
]
==
'
OK
'
):
log
.
debug
(
"
Message delivered successfully!
"
)
log
.
debug
(
'
Message delivered successfully!
'
)
success
=
True
success
=
True
break
break
elif
(
result
.
get
(
'
error
'
)):
elif
(
result
.
get
(
'
error
'
)):
log
.
error
(
"
XBMC error; %s: %s (%s)
"
,
(
result
[
'
id
'
],
result
[
'
error
'
][
'
message
'
],
result
[
'
error
'
][
'
code
'
]))
log
.
error
(
'
XBMC error; %s: %s (%s)
'
,
(
result
[
'
id
'
],
result
[
'
error
'
][
'
message
'
],
result
[
'
error
'
][
'
code
'
]))
break
break
elif
(
result
.
get
(
'
result
'
)
and
type
(
result
[
'
result
'
][
'
version
'
]).
__name__
==
'
dict
'
):
elif
(
result
.
get
(
'
result
'
)
and
type
(
result
[
'
result
'
][
'
version
'
]).
__name__
==
'
dict
'
):
# XBMC JSON-RPC v6 returns an array object containing
# XBMC JSON-RPC v6 returns an array object containing
# major, minor and patch number
# major, minor and patch number
xbmc_rpc_version
=
str
(
result
[
'
result
'
][
'
version
'
][
'
major
'
])
xbmc_rpc_version
=
str
(
result
[
'
result
'
][
'
version
'
][
'
major
'
])
xbmc_rpc_version
+=
"
.
"
+
str
(
result
[
'
result
'
][
'
version
'
][
'
minor
'
])
xbmc_rpc_version
+=
'
.
'
+
str
(
result
[
'
result
'
][
'
version
'
][
'
minor
'
])
xbmc_rpc_version
+=
"
.
"
+
str
(
result
[
'
result
'
][
'
version
'
][
'
patch
'
])
xbmc_rpc_version
+=
'
.
'
+
str
(
result
[
'
result
'
][
'
version
'
][
'
patch
'
])
log
.
debug
(
"
XBMC JSON-RPC Version: %s
"
,
xbmc_rpc_version
)
log
.
debug
(
'
XBMC JSON-RPC Version: %s
'
,
xbmc_rpc_version
)
# ok, XBMC version is supported
# ok, XBMC version is supported
self
.
use
JSON
notifications
=
True
self
.
use
_json_
notifications
[
host
]
=
True
# send the text message
# send the text message
resp
=
self
.
request
(
host
,
[(
'
GUI.ShowNotification
'
,
{
"
title
"
:
self
.
default_title
,
"
message
"
:
message
})])
resp
=
self
.
request
(
host
,
[(
'
GUI.ShowNotification
'
,
{
'
title
'
:
self
.
default_title
,
'
message
'
:
message
})])
for
result
in
resp
:
for
result
in
resp
:
if
(
result
.
get
(
'
result
'
)
and
result
[
'
result
'
]
==
"
OK
"
):
if
(
result
.
get
(
'
result
'
)
and
result
[
'
result
'
]
==
'
OK
'
):
log
.
debug
(
"
Message delivered successfully!
"
)
log
.
debug
(
'
Message delivered successfully!
'
)
success
=
True
success
=
True
break
break
elif
(
result
.
get
(
'
error
'
)):
elif
(
result
.
get
(
'
error
'
)):
log
.
error
(
"
XBMC error; %s: %s (%s)
"
,
(
result
[
'
id
'
],
result
[
'
error
'
][
'
message
'
],
result
[
'
error
'
][
'
code
'
]))
log
.
error
(
'
XBMC error; %s: %s (%s)
'
,
(
result
[
'
id
'
],
result
[
'
error
'
][
'
message
'
],
result
[
'
error
'
][
'
code
'
]))
break
break
# error getting version info (we do have contact with XBMC though)
# error getting version info (we do have contact with XBMC though)
elif
(
result
.
get
(
'
error
'
)):
elif
(
result
.
get
(
'
error
'
)):
log
.
error
(
"
XBMC error; %s: %s (%s)
"
,
(
result
[
'
id
'
],
result
[
'
error
'
][
'
message
'
],
result
[
'
error
'
][
'
code
'
]))
log
.
error
(
'
XBMC error; %s: %s (%s)
'
,
(
result
[
'
id
'
],
result
[
'
error
'
][
'
message
'
],
result
[
'
error
'
][
'
code
'
]))
# set boolean so we only run this once after boot
# in func notify() ignored for 'test' messages
self
.
firstRun
=
False
log
.
debug
(
"
u
se JSON notifications: %s
"
,
self
.
use
JSON
notifications
)
log
.
debug
(
'
U
se JSON notifications: %s
'
,
self
.
use
_json_
notifications
)
return
success
return
success
...
@@ -116,7 +112,7 @@ class XBMC(Notification):
...
@@ -116,7 +112,7 @@ class XBMC(Notification):
server
=
'
http://%s/xbmcCmds/
'
%
host
server
=
'
http://%s/xbmcCmds/
'
%
host
# title, message [, timeout , image #can be added!]
# title, message [, timeout , image #can be added!]
cmd
=
'
xbmcHttp?command=ExecBuiltIn(Notification(
"
%s
"
,
"
%s
"
))
'
%
(
urllib
.
quote
(
data
[
'
title
'
]),
urllib
.
quote
(
data
[
'
message
'
]))
cmd
=
"
xbmcHttp?command=ExecBuiltIn(Notification(
'
%s
'
,
'
%s
'
))
"
%
(
urllib
.
quote
(
data
[
'
title
'
]),
urllib
.
quote
(
data
[
'
message
'
]))
server
+=
cmd
server
+=
cmd
# I have no idea what to set to, just tried text/plain and seems to be working :)
# I have no idea what to set to, just tried text/plain and seems to be working :)
...
@@ -144,18 +140,18 @@ class XBMC(Notification):
...
@@ -144,18 +140,18 @@ class XBMC(Notification):
#
#
response
=
self
.
urlopen
(
server
,
headers
=
headers
)
response
=
self
.
urlopen
(
server
,
headers
=
headers
)
if
"
OK
"
in
response
:
if
'
OK
'
in
response
:
log
.
debug
(
'
Returned from non-JSON-type request %s: %s
'
,
(
host
,
response
))
log
.
debug
(
'
Returned from non-JSON-type request %s: %s
'
,
(
host
,
response
))
# manually fake expected response array
# manually fake expected response array
return
[{
"
result
"
:
"
OK
"
}]
return
[{
'
result
'
:
'
OK
'
}]
else
:
else
:
log
.
error
(
'
Returned from non-JSON-type request %s: %s
'
,
(
host
,
response
))
log
.
error
(
'
Returned from non-JSON-type request %s: %s
'
,
(
host
,
response
))
# manually fake expected response array
# manually fake expected response array
return
[{
"
result
"
:
"
Error
"
}]
return
[{
'
result
'
:
'
Error
'
}]
except
:
except
:
log
.
error
(
'
Failed sending non-JSON-type request to XBMC: %s
'
,
traceback
.
format_exc
())
log
.
error
(
'
Failed sending non-JSON-type request to XBMC: %s
'
,
traceback
.
format_exc
())
return
[{
"
result
"
:
"
Error
"
}]
return
[{
'
result
'
:
'
Error
'
}]
def
request
(
self
,
host
,
requests
):
def
request
(
self
,
host
,
requests
):
server
=
'
http://%s/jsonrpc
'
%
host
server
=
'
http://%s/jsonrpc
'
%
host
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment