Esempio n. 1
0
        def chunk_read(self, response, chunk_size=1024*100, report_hook=None):

            if report_hook is None:
                report_hook = self.chunk_report

            total_size = response.info().getheader('Content-Length').strip()
            total_size = int(total_size)
            bytes_so_far = 0

            while True:
                chunk = response.read(chunk_size)
                bytes_so_far += len(chunk)

                if not chunk:
                    self.temp_file_handler.close()
                    break

                if self.progress:
                    if self.progress.iscanceled():
                        self.temp_file_handler.close()
                        vfs.delete(self.temp_file_path)
                        self.progress.close()

                if report_hook:
                    self.temp_file_handler.write( chunk )
                    report_hook(bytes_so_far, total_size)

            return bytes_so_far
Esempio n. 2
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
Esempio n. 3
0
    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:

            date_match = re.match('.*_(\d\d\.\d\d\.\d\d)_.*', filename)
            if date_match:
                date_part = "%s/" % date_match.group(1)
            else:
                date_part = ""

            url_online = 'http://thumbs.onlinetvrecorder.com/' + date_part + filename
            print url_online
            try:
                __sx__.Downloader(url_online,
                                  url_local,
                                  progress=False,
                                  background=True)
                xbmc.log('wrote pic %s' % url_local)
                return url_local
            except Exception, e:
                xbmc.log('%s: %s' % (url_local, str(e)))
                return url_online
Esempio n. 4
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
Esempio n. 5
0
    def __init__(self):

        self.recordings = dict()

        # set path
        if __addon__.getSetting('otrDownloadFolder') in ['special://temp', '']:
            self.path = vfs.path.join(xbmc.translatePath('special://temp'), __addon__.getAddonInfo('id'))
        else:
            self.path = __addon__.getSetting('otrDownloadFolder')

        try:
            if not vfs.exists(self.path):
                vfs.mkdir(self.path)
                print "created dir %s" % self.path
        except OSError,e :
            __sx__.Notification(self.path, 'could not create dir (%s)' % str(e.strerror))
            sys.exit(0)
Esempio n. 6
0
 def load(self):
     for epgid in self.__findAllRecordingInfo():
         recording_info = json.loads(
             __sx__.noNull(vfs.File(self.__getEpgidJsonFile(epgid)).read()))
         local_path = vfs.path.join(self.path, epgid)
         recording_info['copies'] = dict()
         for copy in self.__findEpgidLocalCopies(local_path):
             recording_info['copies'].update(copy)
         self.recordings[epgid] = recording_info
Esempio n. 7
0
 def touch(self):
     last_file = vfs.path.join(self.__archive.path, 'last')
     try:
         last_file_object = vfs.File(last_file, 'w')
         last_file_object.write(str(int(time.time())))
         last_file_object.close()
     except Exception, e:
         __sx__.Notification(last_file, str(e))
         return False
Esempio n. 8
0
 def __cleanupAllLocalCopies(self):
     for epgid in self.__findAllRecordingInfo():
         if len(
                 list(
                     self.__findEpgidLocalCopies(
                         self.__getLocalEpgidPath(epgid)))) < 1:
             self.deleteLocalEpgidPath(epgid=epgid)
         else:
             json_file = self.__getEpgidJsonFile(epgid)
             recording_info = json.loads(
                 __sx__.noNull(vfs.File(json_file).read()))
             recording_info['streams'] = {}
             try:
                 vfs.File(json_file, 'w').write(json.dumps(recording_info))
             except Exception, e:
                 __sx__.Notification(json_file, str(e))
             else:
                 xbmc.log('wrote %s' % json_file)
Esempio n. 9
0
    def __init__(self):

        self.recordings = dict()

        # set path
        if __addon__.getSetting('otrDownloadFolder') in ['special://temp', '']:
            self.path = vfs.path.join(xbmc.translatePath('special://temp'),
                                      __addon__.getAddonInfo('id'))
        else:
            self.path = __addon__.getSetting('otrDownloadFolder')

        try:
            if not vfs.exists(self.path):
                vfs.mkdir(self.path)
                print "created dir %s" % self.path
        except OSError, e:
            __sx__.Notification(self.path,
                                'could not create dir (%s)' % str(e.strerror))
            sys.exit(0)
Esempio n. 10
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}
Esempio n. 11
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
Esempio n. 12
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)
Esempio n. 13
0
    def _play(self, otr, url=False):
        if not url:
            url = call.params['url']

        if not vfs.exists(url) and url.startswith('http'):
            url = self._downloadqueue(otr, url)

        if url:
            print "playing url %s" % url
            xbmc.Player().play(url)
            print "player returned"
        return True
Esempio n. 14
0
    def _play(self, otr, url=False):
        if not url:
            url = call.params['url']

        if not vfs.exists(url) and url.startswith('http'):
            url = self._downloadqueue(otr, url)

        if url:
            print "playing url %s" % url
            xbmc.Player().play(url)
            print "player returned"
        return True
Esempio n. 15
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}
Esempio n. 16
0
            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()
Esempio n. 17
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)
Esempio n. 18
0
    def InitList (self, pList, pVfs = None):
        #print 'init List'
        #create new Vfs stack for this list control object (if not already done)
        if self.m_mapStackIdx.get (pList, 0) == 0:
            #stack does not exist for this list, create new one
            #tVfsStack stack;
            stack=[]
            stack.append (Vfs())
            self.m_lstStacks.append (stack)
            #typedef std::vector<Vfs *> tVfsStack;

            #remember stack index
            self.m_mapStackIdx[pList] = len (self.m_lstStacks) - 1

        if (None == pVfs):
          pVfs = Vfs_Local()

        self.VfsStackPush(pList, pVfs)

        # TOFIX: remove this
        #ifdef __WXMSW__
        pList.SetDirectory ('C:\\')
Esempio n. 19
0
    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:

            date_match = re.match('.*_(\d\d\.\d\d\.\d\d)_.*', filename)
            if date_match:
                date_part = "%s/" % date_match.group(1)
            else:
                date_part = ""

            url_online = 'http://thumbs.onlinetvrecorder.com/' + date_part + filename
            print url_online
            try:
                __sx__.Downloader(url_online, url_local, progress=False, background=True)
                xbmc.log('wrote pic %s' % url_local)
                return url_local
            except Exception, e:
                xbmc.log('%s: %s' % (url_local, str(e)))
                return url_online
Esempio n. 20
0
 def __getLocalEpgidPath(self, epgid, mkdir=True):
     path = vfs.path.join(self.path, epgid)
     if not vfs.exists(path) and mkdir:
         vfs.mkdir(path)
         print "created dir %s" % path
     return path
Esempio n. 21
0
    def deleteLocalEpgidPath(self, epgid=False, file=False):

        if epgid:
            path = self.__getLocalEpgidPath(epgid, mkdir=False)
            json_file = self.__getEpgidJsonFile(epgid)
        elif file:
            path = file
            json_file = path + '.json.v1'
        else:
            return False

        if not vfs.exists(json_file):
            xbmc.log('could not delete %s, no info file found' % path)
            return False

        else:
            try:
                if file:
                    if vfs.exists(path):
                        vfs.delete(path)
                    if vfs.exists(json_file):
                        vfs.delete(json_file)
                elif epgid and vfs.exists(path):
                    for file_name in vfs.listdir(path)[1]:
                        file_path = vfs.path.join(path, file_name)
                        vfs.delete(file_path)
                    vfs.rmdir(path)
            except Exception, e:
                xbmc.log("failed to delete %s (%s)" % (path, str(e)))
            else:
Esempio n. 22
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:
Esempio n. 23
0
    def deleteLocalEpgidPath(self, epgid=False, file=False):

        if epgid:
            path = self.__getLocalEpgidPath(epgid, mkdir=False)
            json_file = self.__getEpgidJsonFile(epgid)
        elif file:
            path = file
            json_file = path + '.json.v1'
        else:
            return False

        if not vfs.exists(json_file):
            xbmc.log('could not delete %s, no info file found' % path)
            return False

        else:
            try:
                if file:
                    if vfs.exists(path):
                        vfs.delete(path)
                    if vfs.exists(json_file):
                        vfs.delete(json_file)
                elif epgid and vfs.exists(path):
                    for file_name in vfs.listdir(path)[1]:
                        file_path = vfs.path.join(path, file_name)
                        vfs.delete(file_path)
                    vfs.rmdir(path)
            except Exception, e:
                xbmc.log("failed to delete %s (%s)" % (path, str(e)))
            else:
Esempio n. 24
0
 def __getLocalEpgidPath(self, epgid, mkdir=True):
     path = vfs.path.join(self.path, epgid)
     if not vfs.exists(path) and mkdir:
         vfs.mkdir(path)
         print "created dir %s" % path
     return path