Skip to content

Commit

Permalink
New routing system
Browse files Browse the repository at this point in the history
  • Loading branch information
pablouser1 committed Jan 29, 2022
1 parent 0ff8a53 commit ce92de9
Show file tree
Hide file tree
Showing 34 changed files with 351 additions and 133 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.3.5" provider-name="pablouser1">
<addon id="plugin.video.filmin" name="Filmin" version="1.4.0" 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
4 changes: 4 additions & 0 deletions resources/language/resource.language.en_gb/strings.po
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,7 @@ msgstr ""
msgctxt "#40011"
msgid "Enable Up Next integration"
msgstr ""

msgctxt "#40012"
msgid "User ID"
msgstr ""
4 changes: 4 additions & 0 deletions resources/language/resource.language.es_es/strings.po
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,7 @@ msgstr "Permitir alquilar contenido usando tickets"
msgctxt "#40011"
msgid "Enable Up Next integration"
msgstr "Habilitar integración con Up Next"

msgctxt "#40012"
msgid "User ID"
msgstr "ID del Usuario"
1 change: 1 addition & 0 deletions resources/lib/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ def getStreams(self, item_id: int):
versions.append({
"type": "FLVURL",
"src": res["FLVURL"],
"media_viewing_id": res["media_viewing_id"],
"drm": False
})

Expand Down
6 changes: 2 additions & 4 deletions resources/lib/app.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
from .router import Router
from .routes import dispatch
from .session import askLogin
from .common import config, api

def run():
# Start router
router = Router()
# Check if user already has a session
if config.hasLoginData():
token_info = config.getToken()
Expand All @@ -13,4 +11,4 @@ def run():
else:
askLogin()

router.push()
dispatch()
8 changes: 4 additions & 4 deletions resources/lib/common.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import sys
from sys import argv
from urllib.parse import parse_qsl
from .config import Config
from .api import Api

_URL = sys.argv[0]
_HANDLE = int(sys.argv[1])
params = dict(parse_qsl(sys.argv[2][1:]))
_URL = argv[0]
_HANDLE = int(argv[1])
params = dict(parse_qsl(argv[2][1:]))
config = Config()
api = Api()
9 changes: 8 additions & 1 deletion resources/lib/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,17 @@ def getToken(self)-> dict:
'access': access
}

def getUserId(self)-> int:
return self.addon.getSettingInt('user_id')

def canBuy(self)-> bool:
return self.addon.getSettingBool('tickets')

def setAuth(self, access_token: str, refresh_token: str, username: str):
def canSync(self)-> bool:
return self.addon.getSettingBool('sync')

def setAuth(self, access_token: str, refresh_token: str, username: str, user_id: int):
self.addon.setSettingString('access_token', access_token)
self.addon.setSettingString('refresh_token', refresh_token)
self.addon.setSettingString('username', username)
self.addon.setSettingInt('user_id', user_id)
18 changes: 18 additions & 0 deletions resources/lib/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
def __enum(**enums):
return type('Enum', (), enums)

ROUTES = __enum(
HOME='home',
CATALOG='catalog',
SEARCH='search',
PURCHASED='purchased',
WATCHING='watching',
HIGHLIGHTEDS='highlighteds',
PLAYLISTS='playlists',
PLAYLIST='playlist',
COLLECTIONS='collections',
COLLECTION='collection',
SEASONS='seasons',
EPISODES='episodes',
PLAYER='player'
)
33 changes: 33 additions & 0 deletions resources/lib/dispatcher.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from .common import params

class Dispatcher:
functions = {}
args = {}
kwargs = {}
def register(self, route: str, args = [], kwargs = []):
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

def run(self, route: str):
if route not in self.functions:
raise Exception('Route not valid')

args = []
kwargs = []
# Add args
if self.args[route]:
for arg in self.args[route]:
if arg not in params:
raise Exception('Param not found in URL!')

args.append(params[arg])

self.functions[route](*args)
6 changes: 0 additions & 6 deletions resources/lib/exceptions/SearchException.py

This file was deleted.

2 changes: 1 addition & 1 deletion resources/lib/helpers/Render.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def videos(items: list)-> list:
"""
listing = []
for item in items:
url = '{0}?action=play&id={1}'.format(_URL, item["id"])
url = '{0}?menu=player&id={1}'.format(_URL, item["id"])
list_item = setInfoVideo(url, item)
list_item.setProperty('IsPlayable', 'true')
listing.append((url, list_item, False))
Expand Down
8 changes: 4 additions & 4 deletions resources/lib/helpers/Types.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
videos_type = [
videos_type = (
"short", "film", "episode"
]
)

folders_type = [
folders_type = (
"serie", "season"
]
)
2 changes: 2 additions & 0 deletions resources/lib/helpers/listitem.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ def setInfoVideo(url: str, item: dict)-> ListItem:
art = getArt(item["imageResources"]["data"])
list_item.setArt(art)
list_item.setInfo('video', info)
list_item.setProperty('isPlayable', 'true')
list_item.setIsFolder(False)
return list_item

def setInfoFolder(url: str, item: dict)-> ListItem:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from xbmc import sleep
from xbmcgui import Dialog, ListItem
from xbmcplugin import setResolvedUrl
from ..common import api, config, _HANDLE
from ..helpers.listitem import setInfoVideo
from ..user import User
# from .Player import Player
from ..exceptions.DRMException import DRMException
from ..exceptions.StreamException import StreamException

Expand All @@ -18,8 +19,9 @@ def __init__(self, el_id: int):
self.canWatch = len(self.item['user_data']['can_watch']['data']) > 0

def buyMedia(self):
user = User()
self.bought = Dialog().yesno('Tickets', f'This content is not avaiable. Do you want to rent it using a ticket? You have {user.tickets} tickets left')
user = api.user()
tickets = len(res['tickets']['data'])
self.bought = Dialog().yesno('Tickets', f'This content is not avaiable. Do you want to rent it using a ticket? You have {tickets} tickets left')
if self.bought:
api.useTicket(self.item['id'])

Expand Down Expand Up @@ -75,5 +77,14 @@ def start(self):
raise DRMException()
# Start playing
setResolvedUrl(_HANDLE, True, play_item)
"""
player = Player(config.canSync(),
config.getUserId(),
self.item['id'],
version['id'],
stream['media_viewing_id'],
config.getToken()['access'])
player.play(listitem=play_item)
"""
else:
Dialog().ok('Eror', 'This item is not available')
55 changes: 55 additions & 0 deletions resources/lib/player/Mediamark.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import requests

class Mediamark:
BASE_URL = "https://bm.filmin.es/mediamarks"
AUTH_TOKEN = "Njk1MzM5MjAtNDVmNi0xMWUzLThmOTYtMDgwMDIwMGM5YTY2" # I -- THINK -- this is hardcoded, I hope so.
CLIENT_ID = "zXZXrpum7ayGcWlo"
s = requests.Session()
TOKEN = ''
USER_ID = 0
MEDIA_ID = 0
VERSION_ID = 0
MEDIA_VIEWING_ID = 0
SESSION_ID = 0

def __init__(self, user_id: int, media_id: int, version_id: int, media_viewing_id: int, session_id: str):
self.USER_ID = user_id
self.MEDIA_ID = media_id
self.VERSION_ID = version_id
self.MEDIA_VIEWING_ID = media_viewing_id
self.SESSION_ID = session_id
self.s.headers["X-CLIENT-ID"] = self.CLIENT_ID

def setToken(self):
res = self.s.post(self.BASE_URL + '/token', data={
'media_id': self.MEDIA_ID,
'user_id': self.USER_ID,
'platform': 'android'
})

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

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'])

def sync(self, time: int):
self.s.post(self.BASE_URL, data={
'token': self.TOKEN,
'position': time,
'version_id': self.VERSION_ID,
'duration': 0,
'media_id': self.MEDIA_ID,
'media_viewing_id': self.MEDIA_VIEWING_ID,
'session_id': self.SESSION_ID,
'session_connections': 2,
'subtitle_id': 0
})

def sendPos(self):
pass
56 changes: 56 additions & 0 deletions resources/lib/player/Player.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import xbmc
import xbmcgui
from .Mediamark import Mediamark

class Player(xbmc.Player):
"""
TODO, MAKE CUSTOM PLAYER WORK
Custom player for Filmin
KODI TIMES ARE IN SECONDS
FILMIN TIMES ARE IN MILISECONDS
"""
can_sync = False
ended = False
mediamark: Mediamark

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)
xbmc.log('STARTING CUSTOM PLAYER', xbmc.LOGINFO)
self.can_sync = can_sync
if self.can_sync:
xbmc.log('Enabling sync to FILMIN', xbmc.LOGINFO)
self.mediamark = Mediamark(user_id, media_id, version_id, media_viewing_id, session_id)

def onAVStarted(self):
if self.can_sync:
self.mediamark.setToken()
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
seek_to = filmin_position - kodi_position
xbmc.log(f'Moving video to {seek_to} seconds relative', xbmc.LOGINFO)
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)

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)

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
33 changes: 0 additions & 33 deletions resources/lib/router.py

This file was deleted.

Loading

0 comments on commit ce92de9

Please sign in to comment.