Пример #1
0
 def last(self):
     last_file = vfs.path.join(self.__archive.path, 'last')
     try:
         last_file_object = vfs.File(last_file, 'r')
         last_content = last_file_object.read()
         last_file_object.close()
         return int(time.time() - int(__sx__.noNull(last_content)))
     except Exception, e:
         xbmc.log("%s: %s" % (last_file, str(e)))
         return -1
Пример #2
0
 def __dumpAllRecordingInfo(self):
     if self.LastFile(self).touch():
         for epgid in self.recordings:
             path = self.__getLocalEpgidPath(epgid)
             try:
                 vfs.File(self.__getEpgidJsonFile(epgid),
                          'w').write(json.dumps(self.recordings[epgid]))
             except Exception, e:
                 __sx__.Notification(path, str(e))
             else:
                 xbmc.log('wrote %s' % path)
Пример #3
0
 def __findAllRecordingInfo(self):
     for dir_name in vfs.listdir(self.path)[0]:
         json_file = self.__getEpgidJsonFile(dir_name)
         try:
             if vfs.exists(json_file):
                 if not isinstance(
                         json.loads(
                             __sx__.noNull(vfs.File(json_file).read())),
                         dict):
                     continue
             else:
                 continue
         except Exception, e:
             xbmc.log("%s: %s" % (json_file, str(e)))
         else:
             epgid = dir_name
             yield epgid
Пример #4
0
        def __init__(self, url, dest, progress=True, background=False, local=False):
            if local:
                # workaround for some bugy frodo pre-versions
                self.destination_file_path = dest
                self.temp_file_path = vfs.path.join(xbmc.translatePath('special://temp'), self.randomFilename(size=10))
                self.temp_file_handler = open(self.temp_file_path, 'wb')
            else:
                self.destination_file_path = dest
                self.temp_file_path =  dest + '.' + self.randomFilename(3)
                self.temp_file_handler = vfs.File(self.temp_file_path, 'wb')

            self.destination_file_name = url.split('/').pop()

            if progress:
                self.progress = xbmcgui.DialogProgress()
                self.progress.create("Download", self.destination_file_name)

            request = urllib2.Request(url)
            request.add_header('User-Agent', 'XBMC/OtrHandler')

            def download(request):
                response = urllib2.urlopen(request)
                self.size = self.chunk_read(response)

                if progress:
                    self.progress = xbmcgui.DialogProgress()
                    self.progress.create("Move", self.destination_file_name)

                xbmc.log("move %s -> %s" % (self.temp_file_path, self.destination_file_path))
                vfs.rename(self.temp_file_path, self.destination_file_path)
                if vfs.exists(self.temp_file_path):
                    vfs.copy(self.temp_file_path, self.destination_file_path)
                    vfs.delete(self.temp_file_path)

                self.progress.close()

            if background is True:
                bg = Simplebmc().Background()
                bg(download, request)
            else:
                download(request)
Пример #5
0
    def __findEpgidLocalCopies(self, local_path):
        for file_name in vfs.listdir(local_path)[1]:
            if file_name.endswith('.json.v1'):
                json_file = vfs.path.join(local_path, file_name)
                reference_file = json_file.rstrip('.json.v1')

                if not vfs.exists(reference_file):
                    continue

                try:
                    file_info = json.loads(
                        __sx__.noNull(vfs.File(json_file).read()))
                except Exception, e:
                    xbmc.log("%s: %s" % (json_file, str(e)))
                else:
                    if 'type' in file_info and file_info[
                            'type'] == 'local_copy':
                        file_info['file'] = reference_file
                        file_info['file_type'] = reference_file.split(
                            '.').pop()
                        file_info['json_file'] = json_file
                        yield {file_info['file_name']: file_info}
Пример #6
0
            'type': 'local_copy',
            'date': int(time.time())
        }

        try:
            xbmc.log("download: %s" % __sx__.Downloader(url, local_path))
        except IOError, e:
            __sx__.Notification(local_filename,
                                'could not write file (%s)' % str(e.strerror))
        except NoException, e:
            __sx__.Notification(local_filename, e)
        else:
            xbmc.log('wrote %s' % local_path)
            json_filename = local_path + '.json.v1'
            try:
                vfs.File(json_filename, 'w').write(json.dumps(file_info))
            except Exception, e:
                __sx__.Notification(json_filename, str(e))
            else:
                xbmc.log('wrote %s' % json_filename)
                return local_path
        return False

    def getImageUrl(self, epgid, filename):
        """
        liefert dynamisch die thumbnail url zurueck
        """
        url_local = vfs.path.join(self.__getLocalEpgidPath(epgid), filename)
        if vfs.exists(url_local):
            return url_local
        else: