Esempio n. 1
0
 def __init__(self, *args, **kwargs):
     self.ftp_root = kodi.vfs.translate_path(
         kodi.get_setting('root_directory'))
     self.ftp_log = kodi.vfs.join(kodi.get_profile(), "pyftpd.log")
     self.cert_file = vfs.join(kodi.get_profile(), "pyftpd.pem")
     if not vfs.exists(self.cert_file):
         vfs.cp(vfs.join(kodi.get_path(), "pyftpd.pem"), self.cert_file)
Esempio n. 2
0
def download(url, addon_id, destination, unzip=False, quiet=False):
	version = None
	filename = addon_id + '.zip'
	r = requests.get(url, stream=True)
	kodi.log("Download: %s" % url)
	
	
	
	if r.status_code == requests.codes.ok:
		temp_file = kodi.vfs.join(kodi.get_profile(), "downloads")
		if not kodi.vfs.exists(temp_file): kodi.vfs.mkdir(temp_file, recursive=True)
		temp_file = kodi.vfs.join(temp_file, filename)
		try:
			total_bytes = int(r.headers["Content-Length"])
		except:
			total_bytes = 0
		block_size = 1000
		cached_bytes = 0
		if not quiet:
			pb = xbmcgui.DialogProgress()
			pb.create("Downloading",filename,' ', ' ')
		kodi.sleep(150)
		start = time.time()
		with open(temp_file, 'wb') as f:
			for block in r.iter_content(chunk_size=block_size):
				if not block: break
				if not quiet and pb.iscanceled():
					raise downloaderException('Download Aborted')
					return False
				cached_bytes += len(block)
				f.write(block)
				if total_bytes > 0:
					delta = int(time.time() - start)
					if delta:
						bs = int(cached_bytes / (delta))
					else: bs = 0
					if not quiet:
						percent = int(cached_bytes * 100 / total_bytes)
						pb.update(percent, "Downloading",filename, format_status(cached_bytes, total_bytes, bs))
		
		if not quiet: pb.close()
		if unzip:
			zip_ref = zipfile.ZipFile(temp_file, 'r')
			zip_ref.extractall(destination)
			zip_ref.close()
			kodi.vfs.rm(temp_file, quiet=True)
			try:
				xml = kodi.vfs.read_file(kodi.vfs.join(destination, kodi.vfs.join(addon_id, 'addon.xml')), soup=True)
				version = get_version_by_xml(xml)
				if not version:
					version = get_version_by_name(filename)
			except:
				kodi.log("Unable to fine version from addon.xml for addon: %s" % addon_id)
		else:
			kodi.vfs.mv(temp_file, kodi.vfs.join(destination, filename))
	else:
		kodi.close_busy_dialog()
		raise downloaderException(r.status_code)
	return version
Esempio n. 3
0
 def clear_art(self):
     kodi.log("Clearing Bad Art...")
     DB_FILE = kodi.vfs.join("special://database", 'Textures13.db')
     BAD_FILE = kodi.vfs.join(kodi.get_profile(), 'badart.log')
     bad_files = list(set(kodi.vfs.read_file(BAD_FILE).split("\n")))
     with database.connect(DB_FILE, check_same_thread=False) as dbh:
         dbc = dbh.cursor()
         for bad_file in bad_files:
             if not bad_file: continue
             f = kodi.vfs.join(bad_file[0], bad_file) + '.jpg'
             dbc.execute("DELETE FROM texture WHERE cachedurl=?", [f])
             f = kodi.vfs.join("special://thumbnails", f)
             kodi.vfs.rm(f, quiet=True)
     dbh.commit()
     kodi.vfs.write_file(BAD_FILE, '')
	(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.

	You should have received a copy of the GNU General Public License
	along with this program.  If not, see <http://www.gnu.org/licenses/>.
*'''

from commoncore import kodi
from commoncore.database import SQLiteDatabase

DB_TYPE = 'sqlite'
DB_FILE = kodi.vfs.join(kodi.get_profile(), 'core.db')
kodi.log(DB_FILE)


class DBI(SQLiteDatabase):
    def _initialize(self):
        self.connect()
        schema_file = kodi.vfs.join(
            kodi.get_path(), 'resources/database/schema.%s.sql' % self.db_type)
        if self.run_script(schema_file, commit=False):
            self.execute('DELETE FROM version', quiet=True)
            self.execute('INSERT INTO version(db_version) VALUES(?)',
                         [self.db_version],
                         quiet=True)
            self.commit()
        self.disconnect()
Esempio n. 5
0
	(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.

	You should have received a copy of the GNU General Public License
	along with this program.  If not, see <http://www.gnu.org/licenses/>.
*"""

from commoncore import kodi
from commoncore.database import SQLiteDatabase

DB_TYPE = "sqlite"
DB_FILE = kodi.vfs.join(kodi.get_profile(), "cache.db")


class DBI(SQLiteDatabase):
    def _initialize(self):
        self.connect()
        schema_file = kodi.vfs.join(
            kodi.get_path(), "resources/database/schema.%s.sql" % self.db_type
        )
        if self.run_script(schema_file, commit=False):
            self.execute("DELETE FROM version", quiet=True)
            self.execute(
                "INSERT INTO version(db_version) VALUES(?)",
                [self.db_version],
                quiet=True,
            )
Esempio n. 6
0
	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.

	You should have received a copy of the GNU General Public License
	along with this program.  If not, see <http://www.gnu.org/licenses/>.
*'''

from commoncore import kodi
from commoncore.database import SQLiteDatabase

DB_TYPE = 'sqlite'
DB_FILE = kodi.vfs.join(kodi.get_profile(), 'cache.db')
	
class DBI(SQLiteDatabase):
	def _initialize(self):
		self.connect()
		schema_file = kodi.vfs.join(kodi.get_path(), 'resources/database/schema.%s.sql' % self.db_type)
		if self.run_script(schema_file, commit=False):
			self.execute('DELETE FROM version', quiet=True)
			self.execute('INSERT INTO version(db_version) VALUES(?)', [self.db_version], quiet=True)
			self.commit()
		self.disconnect()

DB = DBI(DB_FILE, quiet=True, connect=True, version=2)
import json
import random
import urllib
import hashlib
import zlib
import requests
import traceback
from sqlite3 import dbapi2 as database
from commoncore import kodi
from commoncore.enum import enum
from commoncore.filelock import FileLock
from commoncore.BeautifulSoup import BeautifulSoup

	
vfs = kodi.vfs
CACHE = vfs.join(kodi.get_profile(), 'API_CACHE')
if not vfs.exists(CACHE): vfs.mkdir(CACHE, True)

TYPES = enum(TEXT=unicode, STR=type(''), UTF8=type(u''), DICT=type({}), RESPONSE=requests.models.Response)
EXPIRE_TIMES = enum(FLUSH=-2, NEVER=-1, FIFTEENMIN=.25, THIRTYMIN=.5, HOUR=1, FOURHOURS=4, EIGHTHOURS=8, TWELVEHOURS=12, DAY=24, THREEDAYS=72, WEEK=168)

class baseException(Exception):
	pass

class connectionException(BaseException):
	pass

class responseException(BaseException):
	pass

class BASE_API():
Esempio n. 8
0
import json
import random
import urllib
import hashlib
import zlib
import requests
import traceback
from sqlite3 import dbapi2 as database
from commoncore import kodi
from commoncore.enum import enum
from commoncore.filelock import FileLock
from commoncore.BeautifulSoup import BeautifulSoup

	
vfs = kodi.vfs
CACHE = vfs.join(kodi.get_profile(), 'API_CACHE')
if not vfs.exists(CACHE): vfs.mkdir(CACHE, True)

TYPES = enum(TEXT=unicode, STR=type(''), UTF8=type(u''), DICT=type({}), RESPONSE=requests.models.Response)
EXPIRE_TIMES = enum(FLUSH=-2, NEVER=-1, FIFTEENMIN=.25, THIRTYMIN=.5, HOUR=1, FOURHOURS=4, EIGHTHOURS=8, TWELVEHOURS=12, DAY=24, THREEDAYS=72, WEEK=168)

class baseException(Exception):
	pass

class connectionException(BaseException):
	pass

class responseException(BaseException):
	pass

class BASE_API():
Esempio n. 9
0
def download(url, addon_id, destination, unzip=False, quiet=False):
    version = None
    filename = addon_id + '.zip'
    r = requests.get(url, stream=True)
    kodi.log("Download: %s" % url)

    if r.status_code == requests.codes.ok:
        temp_file = kodi.vfs.join(kodi.get_profile(), "downloads")
        if not kodi.vfs.exists(temp_file):
            kodi.vfs.mkdir(temp_file, recursive=True)
        temp_file = kodi.vfs.join(temp_file, filename)
        try:
            total_bytes = int(r.headers["Content-Length"])
        except:
            total_bytes = 0
        block_size = 1000
        cached_bytes = 0
        if not quiet:
            pb = xbmcgui.DialogProgress()
            pb.create("Downloading", filename, ' ', ' ')
        kodi.sleep(150)
        start = time.time()
        with open(temp_file, 'wb') as f:
            for block in r.iter_content(chunk_size=block_size):
                if not block: break
                if not quiet and pb.iscanceled():
                    raise downloaderException('Download Aborted')
                    return False
                cached_bytes += len(block)
                f.write(block)
                if total_bytes > 0:
                    delta = int(time.time() - start)
                    if delta:
                        bs = int(cached_bytes / (delta))
                    else:
                        bs = 0
                    if not quiet:
                        percent = int(cached_bytes * 100 / total_bytes)
                        pb.update(percent, "Downloading", filename,
                                  format_status(cached_bytes, total_bytes, bs))

        if not quiet: pb.close()
        if unzip:
            zip_ref = zipfile.ZipFile(temp_file, 'r')
            zip_ref.extractall(destination)
            zip_ref.close()
            kodi.vfs.rm(temp_file, quiet=True)
            try:
                xml = kodi.vfs.read_file(kodi.vfs.join(
                    destination, kodi.vfs.join(addon_id, 'addon.xml')),
                                         soup=True)
                version = get_version_by_xml(xml)
                if not version:
                    version = get_version_by_name(filename)
            except:
                kodi.log(
                    "Unable to fine version from addon.xml for addon: %s" %
                    addon_id)
        else:
            kodi.vfs.mv(temp_file, kodi.vfs.join(destination, filename))
    else:
        kodi.close_busy_dialog()
        raise downloaderException(r.status_code)
    return version
Esempio n. 10
0
	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.

	You should have received a copy of the GNU General Public License
	along with this program.  If not, see <http://www.gnu.org/licenses/>.
*'''

from commoncore.enum import enum
from commoncore import kodi
def utf8(string):
	try: 
		string = u'' + string
	except UnicodeEncodeError:
		string = u'' + string.encode('utf-8')
	except UnicodeDecodeError:
		string = u'' + string.decode('utf-8')
	return string

#ARTWORK = kodi.vfs.join(kodi.get_profile(), 'resources/artwork')
CACHE_PATH = kodi.vfs.join(kodi.get_profile(),'cache')
#VIEWS = enum(DEFAULT=500, LIST=50, BIGLIST=51, THUMBNAIL=500, SMALLTHUMBNAIL=522, FANART=508, POSTERWRAP=501, MEDIAINFO=504, MEDIAINFO2=503, MEDIAINFO3=515, WIDE=505, LIST_DEFAULT=50, TV_DEFAULT=50, MOVIE_DEFAULT=50, SEASON_DEFAULT=50, EPISODE_DEFAULT=50)
#UNAIRED_COLOR = 'maroon'

if not kodi.vfs.exists(CACHE_PATH): kodi.vfs.mkdir(CACHE_PATH, recursive=True)
def download(url,
             full_name,
             addon_id,
             destination,
             unzip=False,
             quiet=False,
             verify_hash=True):
    version = None
    filename = addon_id + ".zip"
    r = requests.get(url, stream=True)
    kodi.log("Download: %s" % url)

    if r.status_code == requests.codes.ok:
        temp_file = kodi.vfs.join(kodi.get_profile(), "downloads")
        if not kodi.vfs.exists(temp_file):
            kodi.vfs.mkdir(temp_file, recursive=True)
        temp_file = kodi.vfs.join(temp_file, filename)
        try:
            total_bytes = int(r.headers["Content-Length"])
        except:
            total_bytes = 0
        block_size = 1000
        cached_bytes = 0
        if not quiet:
            pb = xbmcgui.DialogProgress()
            pb.create("Downloading", filename, " ", " ")
        kodi.sleep(150)
        start = time.time()
        is_64bit = sys.maxsize > 2**32
        with open(temp_file, "wb") as f:
            for chunk in r.iter_content(chunk_size=block_size):
                if chunk:
                    if not quiet and pb.iscanceled():
                        raise downloaderException("Download Aborted")
                        return False
                    cached_bytes += len(chunk)
                    shutil.copyfileobj(functionIO(chunk), f, 8096)
                    if total_bytes > 0:
                        delta = int(time.time() - start)
                        if delta:
                            bs = int(cached_bytes / (delta))
                        else:
                            bs = 0
                        if not quiet:
                            percent = int(cached_bytes * 100 / total_bytes)
                            pb.update(
                                percent,
                                "Downloading",
                                filename,
                                format_status(cached_bytes, total_bytes, bs),
                            )

        if not quiet:
            pb.close()
        if verify_hash:
            local_sha = hash_func(temp_file, "sha1")
            remote_sha = get_sha(full_name, url)
            if remote_sha != local_sha:
                kodi.close_busy_dialog()
                kodi.handel_error("Download Error", "Checksum mismatch!")

        if unzip:
            if is_64bit:
                zip_ref = zipfile.ZipFile(temp_file, "r")
            else:
                with open(temp_file, "rb") as zip_file:
                    zip_ref = zip_file.ZipFile(functionIO(zip_file.read()))
            zip_ref.extractall(destination)
            zip_ref.close()
            kodi.vfs.rm(temp_file, quiet=True)
            try:
                xml = kodi.vfs.read_file(
                    kodi.vfs.join(destination,
                                  kodi.vfs.join(addon_id, "addon.xml")),
                    soup=True,
                )
                version = get_version_by_xml(xml)
                if not version:
                    version = get_version_by_name(filename)
            except:
                kodi.log(
                    "Unable to fine version from addon.xml for addon: %s" %
                    addon_id)
        else:
            kodi.vfs.mv(temp_file, kodi.vfs.join(destination, filename))
    else:
        kodi.close_busy_dialog()
        raise downloaderException(r.status_code)
    return version
Esempio n. 12
0
import sys
import cgi
import socket
import hashlib
import datetime
from os import curdir, sep
from urlparse import urlparse
from BaseHTTPServer import BaseHTTPRequestHandler
from commoncore import kodi
from commoncore import core
from commoncore import fanart
from commoncore import trakt
from commoncore.dispatcher import FunctionDispatcher

HOST_ADDRESS = socket.gethostname()
LOG_FILE = kodi.vfs.join(kodi.get_profile(), 'access.log')
BAD_FILE = kodi.vfs.join(kodi.get_profile(), 'badart.log')
kodi.log("Setting Fanart API Access log to: %s" % LOG_FILE)
DEFAULT_POSTER = kodi.vfs.join(kodi.get_path(),
                               'resources/artwork/no_poster.jpg')
DEFAULT_SCREENSHOT = kodi.vfs.join(kodi.get_path(),
                                   'resources/artwork/no_screenshot.jpg')
DEFAULT_FANART = kodi.vfs.join(kodi.get_path(),
                               'resources/artwork/no_fanart.jpg')
DEFAULT_PERSON = kodi.vfs.join(kodi.get_path(),
                               'resources/artwork/no_person.jpg')
client_host = '127.0.0.1'
client_port = kodi.get_setting('control_port', 'service.fanart.proxy')
client_protocol = kodi.get_setting('control_protocol', 'service.fanart.proxy')
BASE_FANART_URL = '%s://%s:%s' % (client_protocol, client_host, client_port)
Esempio n. 13
0
*"""
import time
import json
import random
import hashlib
import zlib
import requests
import traceback
from sqlite3 import dbapi2 as database
from commoncore import kodi
from commoncore.filelock import FileLock
from commoncore import dom_parser
from commoncore.beautifulsoup import BeautifulSoup

vfs = kodi.vfs
CACHE = vfs.join(kodi.get_profile(), "API_CACHE")
if not vfs.exists(CACHE):
    vfs.mkdir(CACHE, True)

try:
    from urllib.parse import urlencode
except ImportError:
    from urllib import urlencode

try:
    str_type = unicode
except:
    str_type = str

TYPES = kodi.enum(
    TEXT=str_type,