Ejemplo n.º 1
0
    def run(self):
        from datetime import datetime
        from myaccounts.modules import alldebrid
        from myaccounts.modules import premiumize
        from myaccounts.modules import realdebrid
        xbmc.log(
            '[ script.module.myaccounts ]  Debrid Account Expiry Notification Service Starting...',
            LOGNOTICE)
        self.duration = [(15, 10), (11, 7), (8, 4), (5, 2), (3, 0)]
        if control.setting('alldebrid.username') != '' and control.setting(
                'alldebrid.expiry.notice') == 'true':
            account_info = alldebrid.AllDebrid().account_info()['user']
            if account_info:
                if not account_info['isSubscribed']:
                    # log_utils.log('AD account_info = %s' % account_info, log_utils.LOGNOTICE)
                    expires = datetime.fromtimestamp(
                        account_info['premiumUntil'])
                    days_remaining = (expires - datetime.today()).days  # int
                    if self.withinRangeCheck('alldebrid', days_remaining):
                        control.notification(
                            message='AllDebrid Account expires in %s days' %
                            days_remaining,
                            icon=control.joinPath(control.artPath(),
                                                  'alldebrid.png'))

        if control.setting('premiumize.username') != '' and control.setting(
                'premiumize.expiry.notice') == 'true':
            account_info = premiumize.Premiumize().account_info()
            if account_info:
                # log_utils.log('PM account_info = %s' % account_info, log_utils.LOGNOTICE)
                expires = datetime.fromtimestamp(account_info['premium_until'])
                days_remaining = (expires - datetime.today()).days  # int
                if self.withinRangeCheck('premiumize', days_remaining):
                    control.notification(
                        message='Premiumize.me Account expires in %s days' %
                        days_remaining,
                        icon=control.joinPath(control.artPath(),
                                              'premiumize.png'))

        if control.setting('realdebrid.username') != '' and control.setting(
                'realdebrid.expiry.notice') == 'true':
            account_info = realdebrid.RealDebrid().account_info()
            if account_info:
                import time
                # log_utils.log('RD account_info = %s' % account_info, log_utils.LOGNOTICE)
                FormatDateTime = "%Y-%m-%dT%H:%M:%S.%fZ"
                try:
                    expires = datetime.strptime(account_info['expiration'],
                                                FormatDateTime)
                except:
                    expires = datetime(*(time.strptime(
                        account_info['expiration'], FormatDateTime)[0:6]))
                days_remaining = (expires - datetime.today()).days  # int
                if self.withinRangeCheck('realdebrid', days_remaining):
                    control.notification(
                        message='Real-Debrid Account expires in %s days' %
                        days_remaining,
                        icon=control.joinPath(control.artPath(),
                                              'realdebrid.png'))
Ejemplo n.º 2
0
def log(msg, caller=None, level=LOGNOTICE):
    debug_enabled = getSetting('debug.enabled') == 'true'
    if not debug_enabled: return
    debug_location = getSetting('debug.location')

    try:
        if caller is not None and level != LOGERROR:
            func = inspect.currentframe().f_back.f_code
            line_number = inspect.currentframe().f_back.f_lineno
            caller = "%s.%s()" % (caller, func.co_name)
            msg = 'From func name: %s Line # :%s\n                       msg : %s' % (
                caller, line_number, msg)
        elif caller is not None and level == LOGERROR:
            msg = 'From func name: %s.%s() Line # :%s\n                       msg : %s' % (
                caller[0], caller[1], caller[2], msg)

        try:
            msg = msg.encode('ascii', errors='ignore').decode('ascii',
                                                              errors='ignore')
        except:
            pass

        try:
            if isinstance(msg, py_tools.text_type):
                msg = '%s (ENCODED)' % (py_tools.ensure_str(msg,
                                                            errors='replace'))
        except:
            pass

        if debug_location == '1':
            log_file = joinPath(LOGPATH, 'myaccounts.log')
            if not existsPath(log_file):
                f = open(log_file, 'w')
                f.close()
            reverse_log = getSetting('debug.reversed') == 'true'
            if not reverse_log:
                with open(log_file, 'a', encoding='utf-8'
                          ) as f:  #with auto cleans up and closes
                    line = '[%s %s] %s: %s' % (
                        datetime.now().date(), str(datetime.now().time())[:8],
                        DEBUGPREFIX % debug_list[level], msg)
                    f.write(line.rstrip('\r\n') + '\n')
            else:
                with open(log_file, 'r+', encoding='utf-8') as f:
                    line = '[%s %s] %s: %s' % (
                        datetime.now().date(), str(datetime.now().time())[:8],
                        DEBUGPREFIX % debug_list[level], msg)
                    log_file = f.read()
                    f.seek(0, 0)
                    f.write(line.rstrip('\r\n') + '\n' + log_file)
        else:
            import xbmc
            xbmc.log('%s: %s' % (DEBUGPREFIX % debug_list[level], msg, level))
    except Exception as e:
        import xbmc
        xbmc.log('log.log() Logging Failure: %s' % (e), LOGERROR)
Ejemplo n.º 3
0
def get():
    myaccounts_path = addonPath()
    myaccounts_version = addonVersion()
    changelogfile = joinPath(myaccounts_path, 'changelog.txt')
    r = open(changelogfile, 'r', encoding='utf-8', errors='ignore')
    text = r.read()
    r.close()
    heading = '[B]My Accounts -  v%s - ChangeLog[/B]' % myaccounts_version
    windows = TextViewerXML('textviewer.xml',
                            myaccounts_path,
                            heading=heading,
                            text=text)
    windows.run()
    del windows
Ejemplo n.º 4
0
def get(file):
    myaccounts_path = addonPath()
    myaccounts_version = addonVersion()
    helpFile = joinPath(myaccounts_path, 'lib', 'myaccounts', 'help',
                        file + '.txt')
    r = open(helpFile, 'r', encoding='utf-8', errors='ignore')
    text = r.read()
    r.close()
    heading = '[B]My Accounts -  v%s - %s[/B]' % (myaccounts_version, file)
    windows = TextViewerXML('textviewer.xml',
                            myaccounts_path,
                            heading=heading,
                            text=text)
    windows.run()
    del windows
Ejemplo n.º 5
0
def upload_LogFile():
    from myaccounts.modules.control import notification
    url = 'https://paste.kodi.tv/'
    log_file = joinPath(LOGPATH, 'myaccounts.log')
    if not existsPath(log_file):
        return notification(
            message='Log File not found, likely logging is not enabled.')
    try:
        import requests
        from myaccounts.modules.control import addonVersion, selectDialog
        f = open(log_file, 'r', encoding='utf-8', errors='ignore')
        text = f.read()
        f.close()
        UserAgent = 'MyAccounts %s' % addonVersion()
        response = requests.post(url + 'documents',
                                 data=text.encode('utf-8', errors='ignore'),
                                 headers={'User-Agent': UserAgent})
        # log('log_response: ' + str(response))
        if 'key' in response.json():
            result = url + response.json()['key']
            log('My Accounts log file uploaded to: %s' % result)
            from sys import platform as sys_platform
            supported_platform = any(value in sys_platform
                                     for value in ['win32', 'linux2'])
            highlight_color = 'gold'
            list = [
                ('[COLOR %s]url:[/COLOR]  %s' % (highlight_color, str(result)),
                 str(result))
            ]
            if supported_platform:
                list += [('[COLOR %s]  -- Copy url To Clipboard[/COLOR]' %
                          highlight_color, ' ')]
            select = selectDialog([i[0] for i in list], lang(32349))
            if 'Copy url To Clipboard' in list[select][0]:
                copy2clip(list[select - 1][1])
        elif 'message' in response.json():
            notification(message='myaccounts Log upload failed: %s' %
                         str(response.json()['message']))
            log('My Accounts Log upload failed: %s' %
                str(response.json()['message']),
                level=LOGERROR)
        else:
            notification(message='myaccounts Log upload failed')
            log('My Accounts Log upload failed: %s' % response.text,
                level=LOGERROR)
    except:
        error('My Accounts log upload failed')
        notification(message='pastebin post failed: See log for more info')
Ejemplo n.º 6
0
def clear_logFile():
    cleared = False
    try:
        from myaccounts.modules.control import yesnoDialog
        if not yesnoDialog(lang(32074), '', ''): return 'canceled'
        log_file = joinPath(LOGPATH, 'myaccounts.log')
        if not existsPath(log_file):
            f = open(log_file, 'w')
            return f.close()
        f = open(log_file, 'r+')
        f.truncate(0)  # need '0' when using r
        f.close()
        cleared = True
    except Exception as e:
        import xbmc
        xbmc.log(
            '[ script.module.myaccounts ] log_utils.clear_logFile() Failure: %s'
            % (e), LOGERROR)
        cleared = False
    return cleared
Ejemplo n.º 7
0
def log(msg, caller=None, level=LOGNOTICE):
    debug_enabled = control.setting('debug.enabled') == 'true'
    debug_log = control.setting('debug.location')

    if not debug_enabled:
        return
    try:
        if caller is not None and level == LOGDEBUG:
            func = inspect.currentframe().f_back.f_code
            line_number = inspect.currentframe().f_back.f_lineno
            caller = "%s.%s()" % (caller, func.co_name)
            msg = 'From func name: %s Line # :%s\n                       msg : %s' % (
                caller, line_number, msg)

        if caller is not None and level == LOGERROR:
            msg = 'From func name: %s.%s() Line # :%s\n                       msg : %s' % (
                caller[0], caller[1], caller[2], msg)

        if isinstance(msg, unicode):
            msg = '%s (ENCODED)' % (msg.encode('utf-8'))

        if debug_log == '1':
            log_file = control.joinPath(LOGPATH, 'myaccounts.log')
            if not control.existsPath(log_file):
                f = open(log_file, 'w')
                f.close()
            with open(log_file, 'a') as f:
                line = '[%s %s] %s: %s' % (datetime.now().date(),
                                           str(datetime.now().time())[:8],
                                           DEBUGPREFIX, msg)
                f.write(line.rstrip('\r\n') + '\n')
        else:
            print('%s: %s' % (DEBUGPREFIX, msg))
    except Exception as e:
        import traceback
        traceback.print_exc()

        try:
            xbmc.log('Logging Failure: %s' % (e), level)
        except:
            pass
Ejemplo n.º 8
0
def view_LogFile(name):
    try:
        from myaccounts.windows.textviewer import TextViewerXML
        from myaccounts.modules.control import addonPath
        log_file = joinPath(LOGPATH, '%s.log' % name.lower())
        if not existsPath(log_file):
            from myaccounts.modules.control import notification
            return notification(
                message='Log File not found, likely logging is not enabled.')
        f = open(log_file, 'r', encoding='utf-8', errors='ignore')
        text = f.read()
        f.close()
        heading = '[B]%s -  LogFile[/B]' % name
        windows = TextViewerXML('textviewer.xml',
                                addonPath(),
                                heading=heading,
                                text=text)
        windows.run()
        del windows
    except:
        error()
Ejemplo n.º 9
0
# -*- coding: utf-8 -*-
"""
	My Accounts
"""

from myaccounts.modules import control

myaccounts_path = control.addonPath()
myaccounts_version = control.addonVersion()
changelogfile = control.joinPath(myaccounts_path, 'changelog.txt')


def get():
    r = open(changelogfile)
    text = r.read()
    r.close()
    control.dialog.textviewer(
        '[COLOR red]My Accounts[/COLOR] -  v%s - ChangeLog' %
        myaccounts_version, text)
Ejemplo n.º 10
0
def get(file):
	helpFile = control.joinPath(myaccounts_path, 'lib', 'myaccounts', 'help', file + '.txt')
	r = open(helpFile)
	text = r.read()
	r.close()
	control.dialog.textviewer('[COLOR red]My Accounts[/COLOR] -  v%s - %s' % (myaccounts_version, file), text)
Ejemplo n.º 11
0
# -*- coding: utf-8 -*-
"""
	My Accounts
"""

import requests

from myaccounts.modules import control
from myaccounts.modules import log_utils

CLIENT_ID = '776741998'  # used to auth
BaseUrl = 'https://www.premiumize.me/api'
account_info_url = '%s/account/info' % BaseUrl
pm_icon = control.joinPath(control.artPath(), 'premiumize.png')


class Premiumize:
    name = "Premiumize.me"

    def __init__(self):
        self.token = control.setting('premiumize.token')
        self.headers = {
            'User-Agent': 'My Accounts for Kodi',
            'Authorization': 'Bearer %s' % self.token
        }
        self.server_notifications = False

    def _get(self, url):
        try:
            response = requests.get(url, headers=self.headers,
                                    timeout=15).json()
Ejemplo n.º 12
0
# -*- coding: utf-8 -*-
'''
	My Accounts
'''

import requests
import time

from myaccounts.modules import control
from myaccounts.modules import log_utils

trakt_icon = control.joinPath(control.artPath(), 'trakt.png')


class Trakt():
    def __init__(self):
        self.api_endpoint = 'https://api-v2launch.trakt.tv/%s'
        self.client_id = '1ff09b52d009f286be2d9bdfc0314c688319cbf931040d5f8847e7694a01de42'
        self.client_secret = '0c5134e5d15b57653fefed29d813bfbd58d73d51fb9bcd6442b5065f30c4d4dc'
        self.expires_at = control.setting('trakt.expires')
        self.token = control.setting('trakt.token')

    def call(self,
             path,
             data=None,
             with_auth=True,
             method=None,
             suppress_error_notification=False):
        try:

            def error_notification(line1, error):
Ejemplo n.º 13
0
	My Accounts
"""

import json
import requests

from myaccounts.modules import control
from myaccounts.modules import log_utils

FormatDateTime = "%Y-%m-%dT%H:%M:%S.%fZ"
rest_base_url = 'https://api.real-debrid.com/rest/1.0/'
oauth_base_url = 'https://api.real-debrid.com/oauth/v2/'
device_code_url = 'device/code?%s'
credentials_url = 'device/credentials?%s'

rd_icon = control.joinPath(control.artPath(), 'realdebrid.png')


class RealDebrid:
    def __init__(self):
        self.token = control.setting('realdebrid.token')
        self.client_ID = control.setting('realdebrid.client_id')
        if self.client_ID == '':
            self.client_ID = 'X245A4XAIBGVM'
        self.secret = control.setting('realdebrid.secret')
        self.device_code = ''
        self.auth_timeout = 0
        self.auth_step = 0

    def _get(self, url, fail_check=False, token_ck=False):
        try:
Ejemplo n.º 14
0
# -*- coding: utf-8 -*-
"""
	My Accounts
"""

import requests
from myaccounts.modules import control
from myaccounts.modules import log_utils

base_url = 'https://api.alldebrid.com/v4/'
user_agent = 'My%20Accounts%20for%20Kodi'
ad_icon = control.joinPath(control.artPath(), 'alldebrid.png')


class AllDebrid:
    name = "AllDebrid"

    def __init__(self):
        self.token = control.setting('alldebrid.token')
        self.timeout = 15.0

    def _get(self, url, url_append=''):
        result = None
        try:
            if self.token == '': return None
            url = base_url + url + '?agent=%s&apikey=%s' % (
                user_agent, self.token) + url_append
            result = requests.get(url, timeout=self.timeout).json()
            if result.get('status') == 'success':
                if 'data' in result: result = result['data']
        except requests.exceptions.ConnectionError: