Esempio n. 1
0
    def GetWatchedStatus(self, metaInfo):
        # Do nothing if we do not know where to look
        if not metaInfo['seriesName']:
            return False
            
        # Generate the file system friendly name
        fileName = os.path.join(self.cache_dir, 'watched_' + self.format_filename(metaInfo['episodeSeriesName']) + '.txt')
        fileName = fileName.strip()

        # If the file does not exist then we have not watched this entry yet
        if not sfile.isfile(fileName):
            return False
        
        try:
            # Check if we still know this file, otherwise try to open it
            # This way, the content will be read only once for consecutive requests on the same series
            if not metaInfo['episodeSeriesName'] == self.lastName:
                self.lastName    = metaInfo['episodeSeriesName']
                self.lastContent = sfile.readlines(fileName)
                
            # Generate a string for the episode
            epName = self._GenerateEPName(metaInfo)
            
            # Look this episode name up in the table
            for line in self.lastContent:
                line = line.split(DELIMETER)
                if line[0] == epName:
                    return line[1] == '1'

        except Exception,e:
            # Reset everything
            self.lastContent = []
            self.lastName    = ''
            print 'WCO EXCEPTION: READING META ' + str(e)
            raise
Esempio n. 2
0
def isPlayable(path, ignore, maxAge=-1):
    if not sfile.exists(path):
        return False

    if sfile.isfile(path):
        playable = isFilePlayable(path, maxAge)
        return playable

    try:
        if sfile.getfilename(path)[0] in ignore:
            return False
    except:
        pass
         
    current, dirs, files = sfile.walk(path)

    for file in files:
        if isPlayable(os.path.join(current, file), ignore, maxAge):
            return True

    for dir in dirs:
        try: 
            if isPlayable(os.path.join(current, dir), ignore, maxAge):
                return True
        except:
            pass

    return False
Esempio n. 3
0
    def SetWatchedStatus(self, metaInfo, status):
        # If the seriesName is not known then we do not know where to put the information
        if not metaInfo['episodeSeriesName']:
            return

        try:
            # Generate the file system friendly name
            fileName = os.path.join(self.cache_dir, 'watched_' + self.format_filename(metaInfo['episodeSeriesName']) + '.txt')
            fileName = fileName.strip()

            # Generate the field name from the meta info
            epName   = self._GenerateEPName(metaInfo)
            stateStr = '1' if status == True else '0'
            
            valueFound = False
            lines = []
            
            # If the file exists then read the content and try to find the content
            if sfile.isfile(fileName):
                lines = sfile.readlines(fileName)
                for idx, line in enumerate(lines):
                    if line.split(DELIMETER)[0] == epName:
                        lines[idx] = '%s%s%s' % (epName, DELIMETER, stateStr)
                        valueFound = True
                        break
                        
            # ... otherwise append the content
            if not valueFound:
                lines.append('%s%s%s' % (epName, DELIMETER, stateStr))
            
            # Write the file back
            sfile.writelines(fileName, lines)
        except Exception, e:
            print 'WCO EXCEPTION: WRITING METADATA: ' + str(e)
Esempio n. 4
0
def getLocalContent(url, ext):
    filename = None
    try:
        if sfile.isfile(url):
            filename = removeExtension(url) + '.' + ext
        
        if sfile.isdir(url):
            filename = url + '.' + ext

        if filename:
            return sfile.read(filename)

    except:
        pass

    return ''
Esempio n. 5
0
def isPlayable(path):
    if not sfile.exists(path):
        return False

    if sfile.isfile(path):
        playable = isFilePlayable(path)
        return playable

    current, dirs, files = sfile.walk(path)

    for file in files:
        if isPlayable(os.path.join(current, file)):
            return True

    for dir in dirs:
        if isPlayable(os.path.join(current, dir)):
            return True

    return False
Esempio n. 6
0
def isPlayable(path):
    if not sfile.exists(path):
        return False

    if sfile.isfile(path):
        playable = isFilePlayable(path)
        return playable
         
    current, dirs, files = sfile.walk(path)

    for file in files:
        if isPlayable(os.path.join(current, file)):
            return True

    for dir in dirs:        
        if isPlayable(os.path.join(current, dir)):
            return True

    return False
Esempio n. 7
0
    def GetWatchedStatus(self, metaInfo):
        # Do nothing if we do not know where to look
        if not metaInfo['seriesName']:
            return False

        # Generate the file system friendly name
        fileName = os.path.join(
            self.cache_dir,
            'watched_' + self.format_filename(metaInfo['seriesName']) + '.txt')
        fileName = fileName.strip()

        # If the file does not exist then we have not watched this entry yet
        if not sfile.isfile(fileName):
            return False

        try:
            # Check if we still know this file, otherwise try to open it
            # This way, the content will be read only once for consecutive requests on the same series
            if not metaInfo['seriesName'] == self.lastName:
                self.lastName = metaInfo['seriesName']
                self.lastContent = sfile.readlines(fileName)

            # Generate a string for the episode
            epName = self._GenerateEPName(metaInfo)

            # Look this episode name up in the table
            for line in self.lastContent:
                line = line.split(DELIMETER)
                if line[0] == epName:
                    return line[1] == '1'

        except Exception, e:
            # Reset everything
            self.lastContent = []
            self.lastName = ''
            print 'WCO EXCEPTION: READING META ' + str(e)
            raise
Esempio n. 8
0
    def SetWatchedStatus(self, metaInfo, status):
        # If the seriesName is not known then we do not know where to put the information
        if not metaInfo['seriesName']:
            return

        try:
            # Generate the file system friendly name
            fileName = os.path.join(
                self.cache_dir, 'watched_' +
                self.format_filename(metaInfo['seriesName']) + '.txt')
            fileName = fileName.strip()

            # Generate the field name from the meta info
            epName = self._GenerateEPName(metaInfo)
            stateStr = '1' if status == True else '0'

            valueFound = False
            lines = []

            # If the file exists then read the content and try to find the content
            if sfile.isfile(fileName):
                lines = sfile.readlines(fileName)
                for idx, line in enumerate(lines):
                    if line.split(DELIMETER)[0] == epName:
                        lines[idx] = '%s%s%s' % (epName, DELIMETER, stateStr)
                        valueFound = True
                        break

            # ... otherwise append the content
            if not valueFound:
                lines.append('%s%s%s' % (epName, DELIMETER, stateStr))

            # Write the file back
            sfile.writelines(fileName, lines)
        except Exception, e:
            print 'WCO EXCEPTION: WRITING METADATA: ' + str(e)
Esempio n. 9
0
def _getCmd(path, fanart, desc, window, filename, isFolder, meta, picture):
    if path.lower().startswith('addons://user/'):
        path     = path.replace('addons://user/', 'plugin://')
        isFolder = True
        window   = 10025

    window = fixWindowID(window)

    if window == 10003:#FileManager
        import sfile
        import os

        isFolder = sfile.isdir(path)
        if isFolder:
            #special paths fail to open - http://trac.kodi.tv/ticket/17333
            if path.startswith('special://'):
                path = xbmc.translatePath(path)
            path = path.replace('%s%s' % (os.sep, os.sep), os.sep)
            path = path.replace(os.sep, '/')
            folder = path
            if folder.endswith('/'):
                folder = folder[:-1]
            folder = folder.rsplit('/', 1)[-1]
            #if not utils.DialogYesNo(GETTEXT(30271) % folder, GETTEXT(30272)):
            #    return None
        else:
            if not sfile.isfile(path):
                return None

    if favourite.isKodiCommand(path):
        return path
    elif len(picture) > 0:
        cmd = 'ShowPicture("%s")'  % picture
    elif isFolder:
        cmd =  'ActivateWindow(%d,"%s' % (window, path)
    elif path.lower().startswith('script'):
        #if path[-1] == '/':
        #    path = path[:-1]
        cmd = 'RunScript("%s' % path.replace('script://', '')
    elif path.lower().startswith('videodb') and len(filename) > 0:
        cmd = 'PlayMedia("%s' % filename.replace('\\', '\\\\')
    #elif path.lower().startswith('musicdb') and len(filename) > 0:
    #    cmd = 'PlayMedia("%s")' % filename
    elif path.lower().startswith('androidapp'):
        cmd = 'StartAndroidActivity("%s")' % path.replace('androidapp://sources/apps/', '', 1)
    else:            
        cmd = 'PlayMedia("%s")' % path
        cmd = favourite.updateSFOption(cmd, 'winID', window)

    cmd = favourite.addFanart(cmd, fanart)
    cmd = favourite.updateSFOption(cmd, 'desc', desc)

    if meta:
        import urllib
        meta = utils.convertDictToURL(meta)
        cmd  = favourite.updateSFOption(cmd, 'meta', urllib.quote_plus(meta))

    if isFolder:
        cmd = cmd.replace('")', '",return)')

    return cmd
Esempio n. 10
0
def _getCmd(path, fanart, desc, window, filename, isFolder, meta, picture):
    if path.lower().startswith('addons://user/'):
        path = path.replace('addons://user/', 'plugin://')
        isFolder = True
        window = 10025

    window = fixWindowID(window)

    if window == 10003:  #FileManager
        import sfile
        import os

        isFolder = sfile.isdir(path)
        if isFolder:
            #special paths fail to open - http://trac.kodi.tv/ticket/17333
            if path.startswith('special://'):
                path = xbmc.translatePath(path)
            path = path.replace('%s%s' % (os.sep, os.sep), os.sep)
            path = path.replace(os.sep, '/')
            folder = path
            if folder.endswith('/'):
                folder = folder[:-1]
            folder = folder.rsplit('/', 1)[-1]
            #if not utils.DialogYesNo(GETTEXT(30271) % folder, GETTEXT(30272)):
            #    return None
        else:
            if not sfile.isfile(path):
                return None

    if favourite.isKodiCommand(path):
        return path
    elif len(picture) > 0:
        cmd = 'ShowPicture("%s")' % picture
    elif isFolder:
        cmd = 'ActivateWindow(%d,"%s' % (window, path)
    elif path.lower().startswith('script'):
        #if path[-1] == '/':
        #    path = path[:-1]
        cmd = 'RunScript("%s' % path.replace('script://', '')
    elif path.lower().startswith('videodb') and len(filename) > 0:
        cmd = 'PlayMedia("%s' % filename.replace('\\', '\\\\')
    #elif path.lower().startswith('musicdb') and len(filename) > 0:
    #    cmd = 'PlayMedia("%s")' % filename
    elif path.lower().startswith('androidapp'):
        cmd = 'StartAndroidActivity("%s")' % path.replace(
            'androidapp://sources/apps/', '', 1)
    else:
        cmd = 'PlayMedia("%s")' % path
        cmd = favourite.updateSFOption(cmd, 'winID', window)

    cmd = favourite.addFanart(cmd, fanart)
    cmd = favourite.updateSFOption(cmd, 'desc', desc)

    if meta:
        import urllib
        meta = utils.convertDictToURL(meta)
        cmd = favourite.updateSFOption(cmd, 'meta', urllib.quote_plus(meta))

    if isFolder:
        cmd = cmd.replace('")', '",return)')

    return cmd