|
1 | 1 | #!/usr/bin/python |
2 | 2 | # -*- coding: UTF-8 -*- |
3 | 3 |
|
4 | | -import xbmc, xbmcaddon |
| 4 | +import xbmc |
5 | 5 | import interface |
6 | 6 | import json |
7 | 7 | __addon__ = interface.__addon__ |
8 | | -def getstr(id): return interface.getstr(id) |
| 8 | +def getstr(strid): return interface.getstr(strid) |
9 | 9 |
|
10 | 10 | class Engine: |
11 | | - def __init__(self, api, player): |
12 | | - self.api = api |
13 | | - self.player = player |
14 | | - player.engine = self |
15 | | - player.api = api |
16 | | - self.synclibrary() |
| 11 | + def __init__(self, api, player): |
| 12 | + self.api = api |
| 13 | + self.player = player |
| 14 | + player.engine = self |
| 15 | + player.api = api |
| 16 | + self.synclibrary() |
17 | 17 |
|
18 | | - def synclibrary(self): |
19 | | - ### UPLOAD ### |
20 | | - #DISABLED UNTIL WORKING FINE |
21 | | - pass |
22 | | - ''' |
23 | | - kodilibrary = xbmc.executeJSONRPC(json.dumps({ |
24 | | - "jsonrpc": "2.0", |
25 | | - "method": "VideoLibrary.GetMovies", |
26 | | - "params": { |
27 | | - |
28 | | - "limits": { |
29 | | - "start": 0, |
30 | | - "end": 1000 |
31 | | - }, |
32 | | - "properties": [ |
33 | | - "playcount", |
34 | | - "imdbnumber", |
35 | | - "file", |
36 | | - "lastplayed" |
37 | | - ], |
38 | | - "sort": { |
39 | | - "order": "ascending", |
40 | | - "method": "label", |
41 | | - "ignorearticle": True |
42 | | - } |
43 | | - }, |
44 | | - "id": "libMovies" |
45 | | - })) |
46 | | - xbmc.log("Simkl: Ret: {}".format(kodilibrary)) |
47 | | - kodilibrary = json.loads(kodilibrary) |
48 | | - |
49 | | - if kodilibrary["result"]["limits"]["total"] > 0: |
50 | | - for movie in kodilibrary["result"]["movies"]: |
51 | | - #Dont do that, upload all at once |
| 18 | + def synclibrary(self): |
| 19 | + ### UPLOAD ### |
| 20 | + #DISABLED UNTIL WORKING FINE |
| 21 | + pass |
| 22 | + ''' |
| 23 | + kodilibrary = xbmc.executeJSONRPC(json.dumps({ |
| 24 | + "jsonrpc": "2.0", |
| 25 | + "method": "VideoLibrary.GetMovies", |
| 26 | + "params": { |
| 27 | + "limits": { |
| 28 | + "start": 0, |
| 29 | + "end": 1000 |
| 30 | + }, |
| 31 | + "properties": [ |
| 32 | + "playcount", |
| 33 | + "imdbnumber", |
| 34 | + "file", |
| 35 | + "lastplayed" |
| 36 | + ], |
| 37 | + "sort": { |
| 38 | + "order": "ascending", |
| 39 | + "method": "label", |
| 40 | + "ignorearticle": True |
| 41 | + } |
| 42 | + }, |
| 43 | + "id": "libMovies" |
| 44 | + })) |
| 45 | + xbmc.log("Simkl: Ret: {}".format(kodilibrary)) |
| 46 | + kodilibrary = json.loads(kodilibrary) |
| 47 | + |
| 48 | + if kodilibrary["result"]["limits"]["total"] > 0: |
| 49 | + for movie in kodilibrary["result"]["movies"]: |
| 50 | + #Dont do that, upload all at once |
52 | 51 |
|
53 | | - if movie["playcount"] > 0: |
54 | | - imdb = movie["imdbnumber"] |
55 | | - date = movie["lastplayed"] |
56 | | - self.api.watched(imdb, "movie", date) |
57 | | - ''' |
| 52 | + if movie["playcount"] > 0: |
| 53 | + imdb = movie["imdbnumber"] |
| 54 | + date = movie["lastplayed"] |
| 55 | + self.api.watched(imdb, "movie", date) |
| 56 | + ''' |
58 | 57 |
|
59 | 58 | class Player(xbmc.Player): |
60 | | - def __init__(self): |
61 | | - xbmc.Player.__init__(self) |
| 59 | + def __init__(self): |
| 60 | + xbmc.Player.__init__(self) |
62 | 61 |
|
63 | | - def getMediaType(self): |
64 | | - if xbmc.getCondVisibility('Container.Content(tvshows)'): |
65 | | - return "show" |
66 | | - elif xbmc.getCondVisibility('Container.Content(seasons)'): |
67 | | - return "season" |
68 | | - elif xbmc.getCondVisibility('Container.Content(episodes)'): |
69 | | - return "episode" |
70 | | - elif xbmc.getCondVisibility('Container.Content(movies)'): |
71 | | - return "movie" |
72 | | - else: |
73 | | - return None |
| 62 | + @classmethod |
| 63 | + def getMediaType(self): |
| 64 | + if xbmc.getCondVisibility('Container.Content(tvshows)'): |
| 65 | + return "show" |
| 66 | + elif xbmc.getCondVisibility('Container.Content(seasons)'): |
| 67 | + return "season" |
| 68 | + elif xbmc.getCondVisibility('Container.Content(episodes)'): |
| 69 | + return "episode" |
| 70 | + elif xbmc.getCondVisibility('Container.Content(movies)'): |
| 71 | + return "movie" |
| 72 | + else: |
| 73 | + return None |
74 | 74 |
|
75 | | - def onPlayBackStarted(self): |
76 | | - self.onPlayBackStopped() |
77 | | - def onPlayBackSeek(self, *args): |
78 | | - #self.onPlayBackStopped() |
79 | | - pass |
80 | | - def onPlayBackResumed(self): |
81 | | - #self.onPlayBackStopped() |
82 | | - pass |
83 | | - def onPlayBackEnded(self): |
84 | | - xbmc.log("Simkl: ONPLAYBACKENDED") |
85 | | - self.onPlayBackStopped() |
86 | | - def onPlayBackStopped(self): |
87 | | - try: |
88 | | - movie = self.getVideoInfoTag() |
89 | | - imdb = movie.getIMDBNumber().strip(" ") |
90 | | - fname = self.getPlayingFile() |
91 | | - thing = xbmc.executeJSONRPC(json.dumps({"jsonrpc": "2.0", "method": "Player.GetItem", |
92 | | - "params": { "properties": [ "showtitle", "title" ] |
93 | | - , "playerid": 1 }, "id": "VideoGetItem"})) |
94 | | - xbmc.log("Simkl: Full: {}".format(thing)) |
95 | | - media = json.loads(thing)["result"]["item"]["type"] |
96 | | - xbmc.log("Simkl: IMDb: {}".format(imdb)) |
97 | | - xbmc.log("Simkl: Genre: " + movie.getGenre()) |
98 | | - xbmc.log("Simkl: MediaType: " + str(media)) |
99 | | - #Scrobble from filename only for testing purposes or error of other methods |
| 75 | + def onPlayBackStarted(self): |
| 76 | + self.onPlayBackStopped() |
| 77 | + def onPlayBackSeek(self, *args): |
| 78 | + #self.onPlayBackStopped() |
| 79 | + pass |
| 80 | + def onPlayBackResumed(self): |
| 81 | + #self.onPlayBackStopped() |
| 82 | + pass |
| 83 | + def onPlayBackEnded(self): |
| 84 | + xbmc.log("Simkl: ONPLAYBACKENDED") |
| 85 | + self.onPlayBackStopped() |
| 86 | + def onPlayBackStopped(self): |
| 87 | + try: |
| 88 | + movie = self.getVideoInfoTag() |
| 89 | + imdb = movie.getIMDBNumber().strip(" ") |
| 90 | + fname = self.getPlayingFile() |
| 91 | + thing = xbmc.executeJSONRPC(json.dumps({"jsonrpc": "2.0", "method": "Player.GetItem", |
| 92 | + "params": { "properties": [ "showtitle", "title" ] |
| 93 | + , "playerid": 1 }, "id": "VideoGetItem"})) |
| 94 | + xbmc.log("Simkl: Full: {}".format(thing)) |
| 95 | + media = json.loads(thing)["result"]["item"]["type"] |
| 96 | + xbmc.log("Simkl: IMDb: {}".format(imdb)) |
| 97 | + xbmc.log("Simkl: Genre: " + movie.getGenre()) |
| 98 | + xbmc.log("Simkl: MediaType: " + str(media)) |
| 99 | + #Scrobble from filename only for testing purposes or error of other methods |
100 | 100 |
|
101 | | - percentage = 100 * self.getTime() / self.getTotalTime() |
102 | | - pctconfig = int(self.addon.getSetting("scr-pct")) |
103 | | - |
104 | | - if percentage > pctconfig: |
105 | | - bubble = __addon__.getSetting("bubble") |
| 101 | + percentage = 100 * self.getTime() / self.getTotalTime() |
| 102 | + pctconfig = int(self.addon.getSetting("scr-pct")) |
| 103 | + |
| 104 | + if percentage > pctconfig: |
| 105 | + bubble = __addon__.getSetting("bubble") |
106 | 106 |
|
107 | | - xbmc.log("Simkl: Ready to scrobble {}".format(movie.getTitle())) |
108 | | - if imdb == "": |
109 | | - xbmc.log("Simkl: No imdb - Fname: {}".format(fname)) |
110 | | - r = self.api.watched(fname, media, self.getTotalTime()) |
111 | | - else: |
112 | | - xbmc.log("Simkl: IMDB: " + str(imdb)) |
113 | | - r = self.api.watched(imdb, media, self.getTotalTime()) |
| 107 | + xbmc.log("Simkl: Ready to scrobble {}".format(movie.getTitle())) |
| 108 | + if imdb == "": |
| 109 | + xbmc.log("Simkl: No imdb - Fname: {}".format(fname)) |
| 110 | + r = self.api.watched(fname, media, self.getTotalTime()) |
| 111 | + else: |
| 112 | + xbmc.log("Simkl: IMDB: " + str(imdb)) |
| 113 | + r = self.api.watched(imdb, media, self.getTotalTime()) |
114 | 114 |
|
115 | | - if bubble and r: |
116 | | - interface.notify(getstr(32028).format( |
117 | | - json.loads(thing)["result"]["item"]["label"])) |
118 | | - r = 0 |
| 115 | + if bubble and r: |
| 116 | + interface.notify(getstr(32028).format( |
| 117 | + json.loads(thing)["result"]["item"]["label"])) |
| 118 | + r = 0 |
119 | 119 |
|
120 | | - except RuntimeError: |
121 | | - pass |
| 120 | + except RuntimeError: |
| 121 | + pass |
0 commit comments