Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Bower components Debian packages RPM packages NuGet packages

dream-alpha / enigma2-plugin-extensions-testcockpit   deb

Repository URL to install this package:

Version: 4.0.6 

/ usr / lib / enigma2 / python / Plugins / Extensions / TestCockpit / Test12.py

#!/usr/bin/python
# coding=utf-8
#
# Copyright (C) 2018-2025 by dream-alpha
#
# In case of reuse of this source code please do not remove this copyright.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# For more information on the GNU General Public License see:
# <http://www.gnu.org/licenses/>.


# pylint: disable=no-member


import os
import time
from datetime import datetime
from Components.config import config
from Screens.InfoBar import InfoBar
from Plugins.SystemPlugins.CacheCockpit.FileManager import FileManager
from .Debug import logger
from .DelayTimer import DelayTimer
from .RecordingUtils import isRecording, stopRecording
from .FileUtils import deleteFiles, copyFile
from .PluginUtils import getPlugin, WHERE_COVER_DOWNLOAD


class Test():

	def __init__(self, _session):
		self.success = False
		self.tried = 0
		self.found = 0

	def start(self, index, callback):
		self.index = index
		self.callback = callback
		deleteFiles("/data/test/*.jpg")
		self.cover_sources = ["auto", "tvfa_id", "tvh_id", "tvs_id", "tvm_id"]
		for cover_source in self.cover_sources:
			for hours in range(8):
				cover_path = "/data/test/" + cover_source + "-" + str(hours) + ".jpg"
				copyFile("/usr/lib/enigma2/python/Plugins/Extensions/TestCockpit/construction.jpg", cover_path)
		InfoBar.instance.recordQuestionCallback(["", "event"])
		timer = isRecording()
		self.path = timer.Filename
		self.service_ref = timer.service_ref
		self.hours = -1
		DelayTimer(2000, self.getCover, timer.Filename, timer.service_ref)

	def downloadCover(self, path, service_ref, hours, cover_source):
		logger.info("path: %s, hours: %s, cover_source: %s", path, hours, cover_source)
		afile = FileManager.getInstance("MVC").getFile("table1", path)
		if afile is not None:
			# logger.debug("afile: %s", afile)
			logger.debug("event_start_time: %s", int(time.time()))
			event_start_time = int(time.time()) / 60 / 60 / 24
			event_start_time *= 24 * 60 * 60
			event_start_time += 6 * 60 * 60
			path2 = "/data/test/" + cover_source + "-" + str(hours) + ".ts"

			self.tried += 1
			logger.debug("event_start_time: %s", datetime.fromtimestamp(event_start_time + hours * 60 * 60))
			plugin = getPlugin(WHERE_COVER_DOWNLOAD)
			if plugin:
				logger.debug("plugin.name: %s", plugin.name)
				plugin(
					config.plugins.moviecockpit,
					path2,
					service_ref,
					event_start_time + hours * 60 * 60,
					30 * 60,
					cover_source,
					self.downloadCoverCallback,
				)
		else:
			self.downloadCoverCallback(path)

	def downloadCoverCallback(self, path):
		logger.info("...")
		cover_path = os.path.splitext(path)[0] + ".jpg"
		if os.path.exists(cover_path):
			self.success |= True
			self.found += 1
		logger.debug("tried: %s, found: %s", self.tried, self.found)
		DelayTimer(50, self.getCover, self.path, self.service_ref)

	def getCover(self, path, service_ref):
		if self.cover_sources:
			cover_source = self.cover_sources[0]
			self.hours += 1
			if self.hours > 7:
				self.hours = 0
				del self.cover_sources[0]
			logger.debug("cover_source: %s, hours: %s", cover_source, self.hours)
			logger.debug("cover_sources: %s", self.cover_sources)
			DelayTimer(50, self.downloadCover, path, service_ref, self.hours, cover_source)
		else:
			stopRecording(path)
			self.callback(self.index, self.success)