Skip to content

Commit

Permalink
Marks now working
Browse files Browse the repository at this point in the history
  • Loading branch information
pablouser1 committed Feb 10, 2022
1 parent ce92de9 commit c206769
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 49 deletions.
2 changes: 1 addition & 1 deletion addon.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="plugin.video.filmin" name="Filmin" version="1.4.0" provider-name="pablouser1">
<addon id="plugin.video.filmin" name="Filmin" version="1.4.1" provider-name="pablouser1">
<requires>
<import addon="xbmc.python" version="3.0.0" />
<import addon="script.module.requests" version="2.22.0+matrix.1" />
Expand Down
16 changes: 7 additions & 9 deletions resources/lib/api.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import requests
import xbmc
from .helpers.Methods import Methods
from xbmc import getLanguage, ISO_639_1
from .exceptions.ApiException import ApiException

class Api:
Expand All @@ -13,20 +12,19 @@ class Api:

def __init__(self):
self.s.headers["X-CLIENT-ID"] = self.CLIENT_ID
self.s.headers["clientlanguage"] = xbmc.getLanguage(xbmc.ISO_639_1, True)
self.s.headers["clientlanguage"] = getLanguage(ISO_639_1, True)
self.s.headers["clientversion"] = '4.2.316' # Latest Filmin version Android
self.s.headers["devicemodel"] = 'Kodi'

def makeRequest(self, endpoint: str, method: str = Methods.GET, body: dict = None, query: dict = None):
def makeRequest(self, endpoint: str, method = 'GET', body: dict = {}, query: dict = {}):
res = self.s.request(method, self.BASE_URL + endpoint, json=body, params=query)
res_json = res.json()
if res.ok:
return res_json
else:
raise ApiException(res_json['errors'])
raise ApiException(res_json['errors'])

def login(self, username: str, password: str)-> dict:
res = self.makeRequest('/oauth/access_token', Methods.POST, {
res = self.makeRequest('/oauth/access_token', 'POST', {
"client_id": self.CLIENT_ID,
"client_secret": self.CLIENT_SECRET,
"grant_type": "password",
Expand All @@ -36,7 +34,7 @@ def login(self, username: str, password: str)-> dict:
return res

def logout(self):
self.makeRequest('/oauth/logout', Methods.POST)
self.makeRequest('/oauth/logout', 'POST')

def setToken(self, token: str):
self.s.headers["Authorization"] = f'Bearer {token}'
Expand Down Expand Up @@ -136,7 +134,7 @@ def episodes(self, item_id: int, season_id: int):
return items

def useTicket(self, item_id: int):
self.makeRequest(endpoint='/user/tickets/activate', method=Methods.POST, body={
self.makeRequest(endpoint='/user/tickets/activate', method='POST', body={
'id': item_id
})

Expand Down
5 changes: 1 addition & 4 deletions resources/lib/dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@
class Dispatcher:
functions = {}
args = {}
kwargs = {}
def register(self, route: str, args = [], kwargs = []):
def register(self, route: str, args = []):
def add(f):
if route in self.functions:
raise Exception(f'{route} route already exists!')

self.functions[route] = f
self.args[route] = args
self.kwargs[route] = kwargs
return f

return add
Expand All @@ -21,7 +19,6 @@ def run(self, route: str):
raise Exception('Route not valid')

args = []
kwargs = []
# Add args
if self.args[route]:
for arg in self.args[route]:
Expand Down
5 changes: 0 additions & 5 deletions resources/lib/helpers/Methods.py

This file was deleted.

11 changes: 6 additions & 5 deletions resources/lib/player/Handler.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from xbmc import sleep
from xbmc import Monitor
from xbmcgui import Dialog, ListItem
from xbmcplugin import setResolvedUrl
from ..common import api, config, _HANDLE
from ..helpers.listitem import setInfoVideo
# from .Player import Player
from .Player import Player
from ..exceptions.DRMException import DRMException
from ..exceptions.StreamException import StreamException

Expand Down Expand Up @@ -76,15 +76,16 @@ def start(self):
else:
raise DRMException()
# Start playing
setResolvedUrl(_HANDLE, True, play_item)
"""
monitor = Monitor()
player = Player(config.canSync(),
config.getUserId(),
self.item['id'],
version['id'],
stream['media_viewing_id'],
config.getToken()['access'])
player.play(listitem=play_item)
"""
setResolvedUrl(_HANDLE, True, play_item)
while not monitor.abortRequested():
monitor.waitForAbort(5)
else:
Dialog().ok('Eror', 'This item is not available')
9 changes: 4 additions & 5 deletions resources/lib/player/Mediamark.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ def __init__(self, user_id: int, media_id: int, version_id: int, media_viewing_i
self.MEDIA_VIEWING_ID = media_viewing_id
self.SESSION_ID = session_id
self.s.headers["X-CLIENT-ID"] = self.CLIENT_ID
self.s.headers["Authorization"] = f'Token {self.AUTH_TOKEN}'

def setToken(self):
def init(self):
res = self.s.post(self.BASE_URL + '/token', data={
'media_id': self.MEDIA_ID,
'user_id': self.USER_ID,
Expand All @@ -29,14 +30,15 @@ def setToken(self):

res_json = res.json()
self.TOKEN = res_json['data']['token']
return res_json['data']['interval']

def getInitialPos(self)-> int:
res = self.s.get(self.BASE_URL, params={
'token': self.TOKEN
})

res_json = res.json()
return int(res_json['data']['position'])
return int(float(res_json['data']['position']))

def sync(self, time: int):
self.s.post(self.BASE_URL, data={
Expand All @@ -50,6 +52,3 @@ def sync(self, time: int):
'session_connections': 2,
'subtitle_id': 0
})

def sendPos(self):
pass
34 changes: 15 additions & 19 deletions resources/lib/player/Player.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import xbmc
import xbmcgui
from threading import Timer
from .Mediamark import Mediamark

class Player(xbmc.Player):
Expand All @@ -11,8 +12,8 @@ class Player(xbmc.Player):
FILMIN TIMES ARE IN MILISECONDS
"""
can_sync = False
ended = False
mediamark: Mediamark
timer: Timer

def __init__(self, can_sync: bool, user_id: int, media_id: int, version_id: int, media_viewing_id: int, session_id: str):
xbmc.Player.__init__(self)
Expand All @@ -22,9 +23,18 @@ def __init__(self, can_sync: bool, user_id: int, media_id: int, version_id: int,
xbmc.log('Enabling sync to FILMIN', xbmc.LOGINFO)
self.mediamark = Mediamark(user_id, media_id, version_id, media_viewing_id, session_id)

def sync(self):
if self.can_sync:
time = self.getTime()
time_ms = time * 1000
xbmc.log(f'Syncing to Filmin at {time} seconds', xbmc.LOGINFO)
self.mediamark.sync(time_ms)

def onAVStarted(self):
if self.can_sync:
self.mediamark.setToken()
interval = self.mediamark.init()
self.timer = Timer(interval / 1000, self.sync)
self.timer.start()
filmin_position = self.mediamark.getInitialPos() / 1000 # Last position set by Filmin converted to seconds
kodi_position = self.getTime() # Kodi last position, already in seconds
# Move video to Filmin position
Expand All @@ -33,24 +43,10 @@ def onAVStarted(self):
self.seekTime(seek_to) # seekTime is relative to the current Kodi position

def onPlayBackSeek(self, time: int, seekOffset: int):
if self.can_sync:
xbmc.log(f'Syncing to Filmin at {time} seconds', xbmc.LOGINFO)
time_ms = time * 1000
self.mediamark.sync(time_ms)
self.sync()

def onPlayBackPaused(self):
if self.can_sync:
time = self.getTime()
time_ms = time * 1000
xbmc.log(f'Syncing to Filmin at {time} seconds', xbmc.LOGINFO)
self.mediamark.sync(time_ms)
self.sync()

def onPlayBackStopped(self):
if self.can_sync:
time = self.getTime()
time_ms = time * 1000
xbmc.log(f'Syncing to Filmin at {time} seconds', xbmc.LOGINFO)
self.mediamark.sync(time_ms)

def onPlayBackEnded(self):
self.ended = True
self.timer.cancel()
2 changes: 1 addition & 1 deletion resources/lib/views/Base.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Base:
static = False

"""
True if the directory contains both videos and folders. IF THIS IS TRUE, DON'T SET HAS_DIRS AND/OR STATIC TO TRUE
True if the directory contains videos
"""
has_videos = False

Expand Down

0 comments on commit c206769

Please sign in to comment.