Skip to content

Commit

Permalink
iSpot v.2.0.5
Browse files Browse the repository at this point in the history
  • Loading branch information
Lunatixz committed Apr 28, 2024
1 parent 67ac27a commit b690063
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 22 deletions.
2 changes: 1 addition & 1 deletion addons.xml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
</extension>
</addon>

<addon id="plugin.video.ispot.tv" version="2.0.4" name="iSpot.tv Adverts" provider-name="Lunatixz">
<addon id="plugin.video.ispot.tv" version="2.0.5" name="iSpot.tv Adverts" provider-name="Lunatixz">
<requires>
<import addon="xbmc.python" version="3.0.0"/>
<import addon="script.module.six" version="1.0.0"/>
Expand Down
2 changes: 1 addition & 1 deletion addons.xml.md5
Original file line number Diff line number Diff line change
@@ -1 +1 @@
48d8143d7a7254e068d2243c0914e22a
c56d3ffcad18c0138b5f62492a1d44e8
2 changes: 1 addition & 1 deletion plugin.video.ispot.tv/addon.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<addon id="plugin.video.ispot.tv" version="2.0.4" name="iSpot.tv Adverts" provider-name="Lunatixz">
<addon id="plugin.video.ispot.tv" version="2.0.5" name="iSpot.tv Adverts" provider-name="Lunatixz">
<requires>
<import addon="xbmc.python" version="3.0.0"/>
<import addon="script.module.six" version="1.0.0"/>
Expand Down
48 changes: 32 additions & 16 deletions plugin.video.ispot.tv/resources/lib/ispot.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
DISC_CACHE = False
DEBUG_ENABLED = REAL_SETTINGS.getSetting('Enable_Debugging').lower() == 'true'
ENABLE_DOWNLOAD = REAL_SETTINGS.getSetting('Enable_Download').lower() == 'true'
DOWNLOAD_PATH = os.path.join(REAL_SETTINGS.getSetting('Download_Folder'),'resources').replace('/resources/resources','/resources')
DOWNLOAD_PATH = os.path.join(REAL_SETTINGS.getSetting('Download_Folder'),'resources','').replace('/resources/resources','/resources')
DEFAULT_ENCODING = "utf-8"
ENABLE_SAP = False
HEADER = {'User-Agent': "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.246"}
Expand Down Expand Up @@ -225,7 +225,7 @@ def playVideo(self, name, uri):


def getFile(self, uri, que=False):
file = xbmcvfs.translatePath(os.path.join(DOWNLOAD_PATH,'%s.mp4'%(slugify(uri))))
file = xbmcvfs.translatePath(os.path.join(DOWNLOAD_PATH,'%s.mp4'%(slugify(uri)))).replace('\\','/')
exists = xbmcvfs.exists(file)
if que and not exists and ENABLE_DOWNLOAD: self.queDownload([uri])
log('getFile, uri = %s, file = %s'%(uri,file))
Expand All @@ -242,27 +242,28 @@ def queDownload(self, uris):

def getDownloads(self):
if ENABLE_DOWNLOAD:
if not xbmcvfs.exists(DOWNLOAD_PATH):
xbmcvfs.mkdir(DOWNLOAD_PATH)

queuePool = (self.cache.get('queuePool', json_data=True) or {})
uris = queuePool.get('uri',[])
dia = self.progressBGDialog(message='Preparing to download %s'%(ADDON_NAME))
dluris = (list(chunkLst(uris,5)) or [[]])[0]

for idx, uri in enumerate(dluris):
try:
diact = int(idx*100//len(dluris))
dia = self.progressBGDialog(diact, dia, message='Downloading Adverts (%s%%)'%(diact))
video = self.getVideo('%s%s'%(BASE_URL,uri))
if not video: continue
url = video['url']
if not xbmcvfs.exists(DOWNLOAD_PATH): xbmcvfs.mkdir(DOWNLOAD_PATH)
dest, exists = self.getFile(uri)
diact = int(idx*100//len(dluris))
dia = self.progressBGDialog(diact, dia, message='Downloading Adverts (%s%%)'%(diact))
dest, exists = self.getFile(uri)
try:
if not exists:
urllib.request.urlretrieve(url, dest)
log('getDownloads, url = %s, dest = %s'%(url,dest))
uris.pop(uris.index(uri))
if self.myMonitor.waitForAbort(10): break
video = self.getVideo('%s%s'%(BASE_URL,uri))
if video:
urllib.request.urlretrieve(video['url'], dest)
log('getDownloads, url = %s, dest = %s'%(video['url'],dest))
if self.myMonitor.waitForAbort(10): break
except Exception as e:
log('getDownloads Failed! %s'%(e))
self.progressBGDialog(100, dia, message='Downloading (Canceled!)')
if xbmcvfs.exists(dest): uris.pop(uris.index(uri))
self.progressBGDialog(100, dia, message='Downloading (Finished!)')
queuePool['uri'] = uris
log('getDownloads, remaining urls = %s'%(len(uris)))
Expand All @@ -282,7 +283,22 @@ def progressBGDialog(self, percent=0, control=None, message='', header=ADDON_NAM
if wait: self.myMonitor.waitForAbort(wait/1000)
return control



def walkPlugin(self):
path = 'plugin://%s'%(ADDON_ID)
chks = list()
dirs = [path]
for idx, dir in enumerate(dirs):
if self.myMonitor.waitForAbort(0.001): break
else:
log('walkFileDirectory, walking %s/%s directory'%(idx,len(dirs)))
if len(dirs) > 0: dir = dirs.pop(dirs.index(dir))
if dir in chks: continue
else: chks.append(dir)
for item in json.loads(xbmc.executeJSONRPC(json.dumps({"jsonrpc":"2.0","id":ADDON_ID,"method":"Files.GetDirectory","params":{"directory":dir,"media":"files"}}))).get('result', {}).get('files',[]):
if item.get('filetype') == 'directory': dirs.append(item.get('file'))


def run(self):
ROUTER.run()
xbmcplugin.setContent(ROUTER.handle ,CONTENT_TYPE)
Expand Down
18 changes: 15 additions & 3 deletions plugin.video.ispot.tv/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

# -*- coding: utf-8 -*-

import sys
import sys, time

from resources.lib import ispot
from kodi_six import xbmc, xbmcaddon, xbmcplugin, xbmcgui, xbmcvfs, py2_encode, py2_decode
Expand All @@ -33,13 +33,25 @@ def __init__(self):
self.running = False
self._start()


def _check(self, key, runEvery=900):
epoch = int(time.time())
next = int(xbmcgui.Window(10000).getProperty(key) or '0')
if (epoch >= next):
xbmcgui.Window(10000).setProperty(key,str(epoch+runEvery))
return True
return False


def _start(self):
while not self.myMonitor.abortRequested():
if self.myMonitor.waitForAbort(900): break
if self.myMonitor.waitForAbort(5): break
elif not self.running:
self.running = True
ispot.iSpotTV(sys.argv).getDownloads()
iservice = ispot.iSpotTV(sys.argv)
if self._check('queue',86400): iservice.walkPlugin()
elif self._check('download',900): iservice.getDownloads()
del iservice
self.running = False

if __name__ == '__main__': Service()
Binary file not shown.

0 comments on commit b690063

Please sign in to comment.