Skip to content

Commit

Permalink
added youtube_dl support
Browse files Browse the repository at this point in the history
  • Loading branch information
mx3L committed May 10, 2020
1 parent 89ec169 commit 979034f
Show file tree
Hide file tree
Showing 12 changed files with 293 additions and 217 deletions.
37 changes: 26 additions & 11 deletions build/plugin/src/archivczsk.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
import threading
import traceback
import datetime
import time

from Components.config import config, configfile
from Components.Console import Console
from Screens.Console import Console as ConsoleScreen
from Screens.MessageBox import MessageBox
from skin import loadSkin

Expand Down Expand Up @@ -33,6 +35,7 @@ def isLoaded():

@staticmethod
def load_repositories():
start = time.clock()
from engine.repository import Repository
repo_xml = os.path.join(settings.REPOSITORY_PATH, 'addon.xml')
try:
Expand All @@ -41,6 +44,13 @@ def load_repositories():
traceback.print_exc()
ArchivCZSK.add_repository(repository)
ArchivCZSK.__loaded = True
diff = time.clock() - start
log.info("load repositories in {0}".format(diff))

@staticmethod
def start_ydl():
from Plugins.Extensions.archivCZSK.engine.ydl import ydl
ydl.init()

@staticmethod
def load_skin():
Expand Down Expand Up @@ -70,11 +80,9 @@ def load_skin():
if skin_name == 'auto' or not os.path.isfile(skin_path):
skin_path = skin_default_path
log.info("loading skin %s" % skin_path)
log.logDebug("loading skin %s" % skin_path)
loadSkin(skin_path)
except:
log.logError("Load plugin skin failed.\n%s"%traceback.format_exc())
pass

@staticmethod
def get_repository(repository_id):
Expand Down Expand Up @@ -117,16 +125,26 @@ def __init__(self, session):
self.session = session
self.to_update_addons = []
self.updated_addons = []
self.check_libs_path = os.path.join(settings.PLUGIN_PATH, "libs_checked")

if ArchivCZSK.__need_restart:
self.ask_restart_e2()

elif config.plugins.archivCZSK.archivAutoUpdate.value and self.canCheckUpdate(True):
self.checkArchivUpdate()
elif config.plugins.archivCZSK.autoUpdate.value and self.canCheckUpdate(False):
self.download_commit()
else:
self.open_archive_screen()
if not os.path.isfile(self.check_libs_path):
self.session.openWithCallback(self.onCheckLibsEnded, ConsoleScreen, "Console", [settings.CHECK_LIBS_SCRIPT_PATH])
else:
if config.plugins.archivCZSK.archivAutoUpdate.value and self.canCheckUpdate(True):
self.checkArchivUpdate()
elif config.plugins.archivCZSK.autoUpdate.value and self.canCheckUpdate(False):
self.download_commit()
else:
self.open_archive_screen()

def onCheckLibsEnded(self):
open(self.check_libs_path, "w").close()

ArchivCZSK.__need_restart = True
self.ask_restart_e2()

def canCheckUpdate(self, archivUpdate):
limitHour = 2
Expand Down Expand Up @@ -188,7 +206,6 @@ def check_commit_download(self, data, retval, extra_args):
if retval == 0 and os.path.exists(os.path.join(os.path.dirname(__file__), 'commit')):
self.check_addon_updates()
else:
log.error("commit not downloaded")
log.logError("Download addons commit return failed.")
self.open_archive_screen()

Expand All @@ -201,11 +218,9 @@ def check_repository(repository):
with lock:
self.to_update_addons += to_update
except UpdateXMLVersionError:
log.logError('cannot retrieve update xml for repository %s'%repository)
log.error('cannot retrieve update xml for repository %s', repository)
except Exception:
traceback.print_exc()
log.logError('error when checking updates for repository %s.\n%s' %(repository, traceback.format_exc()))
log.error('error when checking updates for repository %s', repository)
for repo_key in self.__repositories.keys():
repository = self.__repositories[repo_key]
Expand Down
21 changes: 21 additions & 0 deletions build/plugin/src/engine/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,21 @@
from Plugins.Extensions.archivCZSK.engine.items import PFolder, PVideo, \
PVideoResolved, PVideoNotResolved, PPlaylist, PNotSupportedVideo, PSearch, \
PSearchItem, PContextMenuItem, Stream
from Plugins.Extensions.archivCZSK.engine.ydl import ydl
from Plugins.Extensions.archivCZSK.engine.tools.task import callFromThread, Task
from Plugins.Extensions.archivCZSK.engine.tools.util import toString, toUnicode
from Plugins.Extensions.archivCZSK.gui.captcha import Captcha
from Plugins.Extensions.archivCZSK.resources.libraries import simplejson as json
from Plugins.Extensions.archivCZSK.resources.libraries import m3u8

try:
import demjson
except ImportError:
try:
import Plugins.Extensions.archivCZSK.resources.libraries.demjson
except ImportError:
pass


GItem_lst = VideoAddonContentProvider.get_shared_itemlist()

Expand All @@ -42,6 +51,18 @@ def decode_string(string):
string = unicode(string, 'utf-8', 'ignore')
return _(string)

@callFromThread
def getVideoFormats(url):
def initCallback(initialized):
if (initialized):
return ydl.getVideoLinks(url)
return []
if ydl.isAvailable() is not None:
if ydl.isAvailable():
return ydl.getVideoLinks(url)
return []
if not ydl.isInitialized():
return ydl.init().addCallback(initCallback)

@callFromThread
def getTextInput(session, title, text=""):
Expand Down
20 changes: 19 additions & 1 deletion build/plugin/src/engine/contentprovider.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,21 +61,39 @@ def __init__(self, custom_sys):
util.CustomImporter.__init__(self, 'custom_sys', log=log.debug)
self.add_module('sys', custom_sys)

class AddonOutput:
def __init__(self):
pass

def write(self, data):
log.info(data)

def flush(self):
pass

def isatty(self):
return True


class AddonSys():
"sys for addons"
def __init__(self):
self.addons = []
self.path = SysPath(self.addons)
self.output = AddonOutput()

def __setitem__(self, key, val):
if key == 'path':
log.error('you cannot replace AddonSysPath!')
elif key == 'stdout':
pass
else:
dict.__setitem__(self, key, val)

def __getattr__(self, attr):
if attr=='path':
return self.path
elif attr=='stdout':
return self.output
return getattr(sys, attr)

def add_addon(self, addon):
Expand Down
119 changes: 118 additions & 1 deletion build/plugin/src/engine/tools/e2util.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,123 @@
from enigma import getDesktop
from enigma import getDesktop, eConsoleAppContainer, eTimer
from Plugins.Extensions.archivCZSK.compat import eConnectCallback

import json

def get_desktop_width_and_height():
desktop_size = getDesktop(0).size()
return (desktop_size.width(), desktop_size.height())


class PythonProcess(object):
def __init__(self, processPath):
self.toRead = None
self.pPayload = None
self.data = ""
self.__stopping = False
self.processPath = processPath
self.appContainer = eConsoleAppContainer()
self.stdoutAvail_conn = eConnectCallback(self.appContainer.stdoutAvail, self.dataOutCB)
self.stderrAvail_conn = eConnectCallback(self.appContainer.stderrAvail, self.dataErrCB)
self.appContainer_conn = eConnectCallback(self.appContainer.appClosed, self.finishedCB)

def recieveMessages(self, data):
def getMessage(data):
mSize = int(data[:7])
mPayload = data[7:mSize]
mPart = mSize > len(data)
return mSize, mPayload, mPart

def readMessage(payload):
try:
message = json.loads(payload)
except EOFError:
pass
except Exception:
pass
else:
self.toRead = None
self.pPayload = None
self.handleMessage(message)

def readStart(data):
mSize, mPayload, mPart = getMessage(data)
if not mPart:
data = data[mSize:]
readMessage(mPayload)
if len(data) > 0:
readStart(data)
else:
self.toRead = mSize - len(data)
self.pPayload = mPayload

def readContinue(data):
nextdata = data[:self.toRead]
self.pPayload += nextdata
data = data[len(nextdata):]
self.toRead -= len(nextdata)
if self.toRead == 0:
readMessage(self.pPayload)
if len(data) > 0:
readStart(data)

if self.pPayload is not None:
readContinue(data)
else:
readStart(data)

def handleMessage(self, data):
self.callbacks['messageCB'](data)

def start(self, callbacks):
self.callbacks = callbacks
cmd = "python %s" % self.processPath
self.appContainer.execute(cmd)

def running(self):
return self.appContainer.running()

def stop(self):
def check_stopped():
if not self.appContainer.running():
self.stopTimer.stop()
del self.stopTimer_conn
del self.stopTimer
del self.__i
return
if self.__i == 0:
self.__i += 1
self.appContainer.kill()
elif self.__i == 1:
self.stopTimer.stop()
del self.stopTimer_conn
del self.stopTimer
raise Exception("cannot kill process")

if self.__stopping:
return
self.__stopping = True
self.__i = 0

if self.appContainer.running():
self.appContainer.sendCtrlC()
self.stopTimer = eTimer()
self.stopTimer_conn = eConnectCallback(self.stopTimer.timeout, check_stopped)
self.stopTimer.start(2000, False)

def write(self, data):
dump = json.dumps(data)
dump = "%07d%s" % (len(dump), dump)
try:
self.appContainer.write(dump)
# DMM image
except TypeError:
self.appContainer.write(dump, len(dump))

def dataErrCB(self, data):
self.error = data

def dataOutCB(self, data):
self.recieveMessages(data)

def finishedCB(self, retval):
self.callbacks['finishedCB'](retval)
2 changes: 0 additions & 2 deletions build/plugin/src/engine/tools/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -616,14 +616,12 @@ def find_module(self, fullname, path):
self.log("%s found modul '%s' <filename:%s description:%s>" , self, fullname, self.filename, self.description)
except ImportError:
self.log("%s cannot found modul %s" , self, fullname)
log.logDebug("%s cannot found modul %s" % (self, fullname))
if self.__filehandle:
self.__filehandle.close()
self.__filehandle = None
return None
if self.__filehandle is None:
self.log("%s cannot import package '%s', try to append it to sys.path" , self, fullname)
log.logError("%s cannot import package '%s', try to append it to sys.path" % (self, fullname))
raise ImportError
self.log("%s trying to load module '%s'" , self, fullname)
return self
Expand Down
Loading

0 comments on commit 979034f

Please sign in to comment.