Skip to content

Commit

Permalink
Notification bubble at scrobbling
Browse files Browse the repository at this point in the history
  • Loading branch information
daviddavo committed Dec 24, 2016
1 parent 8e8aa0a commit db4bd50
Show file tree
Hide file tree
Showing 13 changed files with 48 additions and 18 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Kodi

## Installing
1. Download the .zip [here](https://github.com/SIMKL/script.service.simkl/blob/master/script.service.simkl.zip)
1. Download the .zip [here](https://github.com/SIMKL/script.service.simkl/blob/master/script.simkl.zip)
2. Open Kodi and go to Settings > Add-ons > Install from zip file, select the zip file
3. In Settings > Add-ons > My add-ons and search for Simkl TV Tracker. Click on it.
4. Click on Configure to configure the add-on (Login and scrobbler options)
Expand Down
4 changes: 2 additions & 2 deletions addon.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="script.service.simkl"
<addon id="script.simkl"
name="Simkl TV Tracker Dev"
version="0.0.1"
version="0.1.1"
provider-name="David Davó / Simkl">
<requires>
<import addon="xbmc.python" version="2.6"/>
Expand Down
3 changes: 3 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
v0.1.1 (2016-12-23)
- Initial version
- Added notification bubble at scrobble
Binary file added icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 5 additions & 1 deletion resources/language/English/strings.po
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ msgid "Enter to the following URL: {}"
msgstr ""

msgctxt "#32023"
msgcid "Remaining time: {}/{}"
msgid "Remaining time: {}/{}"
msgstr ""

# Blahblahblah
Expand All @@ -70,6 +70,10 @@ msgctxt "#32027"
msgid "You don't have internet"
msgstr ""

msgctxt "#32028"
msgid "Scrobbling {}"
msgstr ""

#msgctxt "#"
#msgid ""
#msgstr ""
6 changes: 5 additions & 1 deletion resources/language/Spanish/strings.po
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ msgid "Enter to the following URL: {}"
msgstr "Entra a la siguiente URL: {}"

msgctxt "#32023"
msgcid "Remaining time: {}/{}"
msgid "Remaining time: {}/{}"
msgstr "Tiempo restante: {}/{}"

# Blahblahblah
Expand All @@ -70,6 +70,10 @@ msgctxt "#32027"
msgid "You don't have internet"
msgstr "No tienes conexión a internet"

msgctxt "#32028"
msgid "Scrobbling {}"
msgstr "Scrobbling {}"

#msgctxt "#"
#msgid ""
#msgstr ""
23 changes: 18 additions & 5 deletions resources/lib/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import xbmc, xbmcaddon
import interface
import json
__addon__ = interface.__addon__
def getstr(id): return interface.getstr(id)

class Engine:
def __init__(self, api, player):
Expand All @@ -15,7 +17,9 @@ def __init__(self, api, player):

def synclibrary(self):
### UPLOAD ###

#DISABLED UNTIL WORKING FINE
pass
'''
kodilibrary = xbmc.executeJSONRPC(json.dumps({
"jsonrpc": "2.0",
"method": "VideoLibrary.GetMovies",
Expand All @@ -41,6 +45,7 @@ def synclibrary(self):
}))
xbmc.log("Simkl: Ret: {}".format(kodilibrary))
kodilibrary = json.loads(kodilibrary)
if kodilibrary["result"]["limits"]["total"] > 0:
for movie in kodilibrary["result"]["movies"]:
#Dont do that, upload all at once
Expand All @@ -49,6 +54,7 @@ def synclibrary(self):
imdb = movie["imdbnumber"]
date = movie["lastplayed"]
self.api.watched(imdb, "movie", date)
'''

class Player(xbmc.Player):
def __init__(self):
Expand Down Expand Up @@ -82,10 +88,10 @@ def onPlayBackStopped(self):
movie = self.getVideoInfoTag()
imdb = movie.getIMDBNumber().strip(" ")
fname = self.getPlayingFile()
media = xbmc.executeJSONRPC(json.dumps({"jsonrpc": "2.0", "method": "Player.GetItem",
thing = xbmc.executeJSONRPC(json.dumps({"jsonrpc": "2.0", "method": "Player.GetItem",
"params": { "properties": [ "showtitle", "streamdetails","title"]
, "playerid": 1 }, "id": "VideoGetItem"}))
media = json.loads(media)["result"]["item"]["type"]
media = json.loads(thing)["result"]["item"]["type"]
xbmc.log("Simkl: IMDb: {}".format(imdb))
xbmc.log("Simkl: Genre: " + movie.getGenre())
xbmc.log("Simkl: MediaType: " + str(media))
Expand All @@ -95,13 +101,20 @@ def onPlayBackStopped(self):
pctconfig = int(self.addon.getSetting("scr-pct"))

if percentage > pctconfig:
bubble = __addon__.getSetting("bubble")

xbmc.log("Simkl: Ready to scrobble {}".format(movie.getTitle()))
if imdb == "":
xbmc.log("Simkl: No imdb - Fname: {}".format(fname))
self.api.watched(fname, media)
r = self.api.watched(fname, media) #r from response
else:
xbmc.log("Simkl: IMDB: " + str(imdb))
self.api.watched(imdb, media)
r = self.api.watched(imdb, media)

if bubble and r:
xbmc.log("Simkl: Full: {}".format(thing))
interface.notify(getstr(32028).format(
json.loads(thing)["result"]["item"]["label"]))

except RuntimeError:
pass
2 changes: 1 addition & 1 deletion resources/lib/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import time
tmp = time.time()

__addon__ = xbmcaddon.Addon("script.service.simkl")
__addon__ = xbmcaddon.Addon("script.simkl")
__icon__ = __addon__.getAddonInfo("icon")
def getstr(id): return __addon__.getLocalizedString(id)

Expand Down
8 changes: 7 additions & 1 deletion resources/lib/simklapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import interface
import httplib

__addon__ = interface.__addon__
def getstr(id): return interface.getstr(id)

REDIRECT_URI = "http://simkl.com"
Expand Down Expand Up @@ -123,11 +124,16 @@ def watched(self, filename, mediatype, date=time.strftime('%Y-%m-%d %H:%M:%S')):

xbmc.log("Simkl: values {}".format(tosend))
con.request("GET", "/sync/history/", body=tosend, headers=headers)
xbmc.log("Simkl: {}".format(con.getresponse().read().decode("utf-8")))
r = con.getresponse().read().decode("utf-8")
xbmc.log("Simkl: {}".format(r))

return max(json.loads(r)["added"].values())

except httplib.BadStatusLine:
xbmc.log("Simkl: {}".format("ERROR: httplib.BadStatusLine"))
else:
xbmc.log("Simkl: Can't scrobble. User not logged in")
return 0

api = API()
if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion resources/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
<setting label="32006" type="slider" id="scr-pct" default="70" range="0,100" option="percent" enable="gt(-1,-2)" />
<setting label="32007" type="slider" id="sct-w-pct" default="10" range="0,100" option="
percent"/>
<setting label="32008" type="bool" id="bubble" default="false" enable="false"/>
<setting label="32008" type="bool" id="bubble" default="false" enable="true"/>
</category>
</settings>
Binary file removed script.service.simkl.zip
Binary file not shown.
Binary file added script.simkl.zip
Binary file not shown.
10 changes: 5 additions & 5 deletions tozip.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/bin/bash
#Creates a zip file compatible with Kodi

mkdir script.service.simkl
rsync -rv --progress ./ ./script.service.simkl --exclude-from .gitignore --exclude tozip.sh
mkdir script.simkl
rsync -rv --progress ./ ./script.simkl --exclude-from .gitignore --exclude tozip.sh

rm script.service.simkl.zip
zip -rx@.gitignore script.service.simkl.zip script.service.simkl/*
rm -Rf script.service.simkl
rm script.simkl.zip
zip -rx@.gitignore script.simkl.zip script.simkl/*
rm -Rf script.simkl

0 comments on commit db4bd50

Please sign in to comment.