Beispiel #1
0
    def startXMPP(self):
        m = mind.getMind()
        xmpp_info = m.getXMPPLoginInfo()

        jid=xmpp.protocol.JID(xmpp_info['username'] + '/pyTivo')
        cl=xmpp.Client(
            server=xmpp_info['server'],
            port=xmpp_info['port'],
            debug=[],
        )
        self.__logger.debug('Connecting to %s:%s' % (xmpp_info['server'],
                                                     xmpp_info['port']))
        cl.connect()
        cl.RegisterHandler('message', self.processMessage)
        self.__logger.debug('Loging in as %s/pyTivo' % xmpp_info['username'])
        cl.auth(user=jid.getNode(), password=config.get_server('tivo_password'),
                resource='pyTivo')

        cl.sendInitPresence(requestRoster=0)

        for user_name in xmpp_info['presence_list']:
            self.__logger.debug('Sending presence to %s' % user_name)
            jid = xmpp.protocol.JID(user_name)
            cl.sendPresence(jid)

        t = threading.Thread(target=self.processXMPP, args=(cl,))
        t.setDaemon(True)
        t.start()
    def push_one_file(self, f):
        file_info = VideoDetails()
        file_info['valid'] = transcode.supported_format(f['path'])

        temp_share = config.get_server('temp_share', '')
        temp_share_path = ''
        if temp_share:
            for name, data in config.getShares():
                if temp_share == name:
                    temp_share_path = data.get('path')

        mime = 'video/mpeg'
        if config.isHDtivo(f['tsn']):
            for m in ['video/mp4', 'video/bif']:
                if transcode.tivo_compatible(f['path'], f['tsn'], m)[0]:
                    mime = m
                    break

            if (mime == 'video/mpeg' and
                transcode.mp4_remuxable(f['path'], f['tsn'])):
                new_path = transcode.mp4_remux(f['path'], f['name'], f['tsn'], temp_share_path)
                if new_path:
                    mime = 'video/mp4'
                    f['name'] = new_path
                    if temp_share_path:
                        ip = config.get_ip()
                        port = config.getPort()
                        container = quote(temp_share) + '/'
                        f['url'] = 'http://%s:%s/%s' % (ip, port, container)

        if file_info['valid']:
            file_info.update(self.metadata_full(f['path'], f['tsn'], mime))

        url = f['url'] + quote(f['name'])

        title = file_info['seriesTitle']
        if not title:
            title = file_info['title']

        source = file_info['seriesId']
        if not source:
            source = title

        subtitle = file_info['episodeTitle']
        try:
            m = mind.getMind(f['tsn'])
            m.pushVideo(
                tsn = f['tsn'],
                url = url,
                description = file_info['description'],
                duration = file_info['duration'] / 1000,
                size = file_info['size'],
                title = title,
                subtitle = subtitle,
                source = source,
                mime = mime,
                tvrating = file_info['tvRating'])
        except Exception, msg:
            logger.error(msg)
Beispiel #3
0
    def xmpp_cdsupdate(self, xml=None):
        m = mind.getMind()

        self.in_progress_lock.acquire()
        try:
            for request in m.getDownloadRequests():
                if not request['bodyOfferId'] in self.in_progress:
                    self.__logger.debug('Adding request to queue, %s' % request)
                    self.in_progress[request['bodyOfferId']] = True
                    self.work_queue.put(request)
        finally:
            self.in_progress_lock.release()
Beispiel #4
0
    def processDlRequest(self):

        while True:
            data = self.work_queue.get()

            for share_name, settings in config.getShares():
                if settings['type'] == 'webvideo':
                    break
            self.__logger.debug('Processing request: %s' % data)

            path = settings['path']

            file_name = os.path.join(path, '%s-%s' % 
                                     (data['bodyOfferId'].replace(':', '-'),
                                      data['url'].split('/')[-1]))

            status = self.downloadFile(data['url'], file_name)
            mime = 'video/mpeg'

            if status:
                tsn = data['bodyId'][4:]
                file_info = VideoDetails()

                if config.isHDtivo(tsn):
                    for m in ['video/mp4', 'video/bif']:
                        if tivo_compatible(file_name, tsn, m)[0]:
                            mime = m
                            break

                file_info.update(self.metadata_full(file_name, tsn, mime))

                ip = config.get_ip()
                port = config.getPort()

                data['url'] = ('http://%s:%s' % (ip, port) +
                               urllib.quote('/%s/%s' % (share_name,
                                            os.path.basename(file_name))))
                data['duration'] = file_info['duration'] / 1000
                data['size'] = file_info['size']

            self.__logger.debug('Complete request: %s' % data)

            m = mind.getMind()
            m.completeDownloadRequest(data, status, mime)

            self.in_progress_lock.acquire()
            try:
                del self.in_progress[data['bodyOfferId']]
            finally:
                self.in_progress_lock.release()
Beispiel #5
0
    def push_one_file(self, f):
        file_info = VideoDetails()
        file_info['valid'] = transcode.supported_format(f['path'])

        mime = 'video/mpeg'
        if config.isHDtivo(f['tsn']):
            for m in ['video/mp4', 'video/bif']:
                if transcode.tivo_compatible(f['path'], f['tsn'], m)[0]:
                    mime = m
                    break

            if (mime == 'video/mpeg' and
                transcode.mp4_remuxable(f['path'], f['tsn'])):
                new_path = transcode.mp4_remux(f['path'], f['name'], f['tsn'])
                if new_path:
                    mime = 'video/mp4'
                    f['name'] = new_path

        if file_info['valid']:
            file_info.update(self.metadata_full(f['path'], f['tsn'], mime))

        url = f['url'] + quote(f['name'])

        title = file_info['seriesTitle']
        if not title:
            title = file_info['title']

        source = file_info['seriesId']
        if not source:
            source = title

        subtitle = file_info['episodeTitle']
        try:
            m = mind.getMind(f['tsn'])
            m.pushVideo(
                tsn = f['tsn'],
                url = url,
                description = file_info['description'],
                duration = file_info['duration'] / 1000,
                size = file_info['size'],
                title = title,
                subtitle = subtitle,
                source = source,
                mime = mime,
                tvrating = file_info['tvRating'])
        except Exception, msg:
            logger.error(msg)
Beispiel #6
0
    def push_one_file(self, f):
        file_info = VideoDetails()
        file_info["valid"] = transcode.supported_format(f["path"])

        mime = "video/mpeg"
        if config.isHDtivo(f["tsn"]):
            for m in ["video/mp4", "video/bif"]:
                if transcode.tivo_compatible(f["path"], f["tsn"], m)[0]:
                    mime = m
                    break

            if mime == "video/mpeg" and transcode.mp4_remuxable(f["path"], f["tsn"]):
                new_path = transcode.mp4_remux(f["path"], f["name"], f["tsn"])
                if new_path:
                    mime = "video/mp4"
                    f["name"] = new_path

        if file_info["valid"]:
            file_info.update(self.metadata_full(f["path"], f["tsn"], mime))

        url = f["url"] + quote(f["name"])

        title = file_info["seriesTitle"]
        if not title:
            title = file_info["title"]

        source = file_info["seriesId"]
        if not source:
            source = title

        subtitle = file_info["episodeTitle"]
        try:
            m = mind.getMind(f["tsn"])
            m.pushVideo(
                tsn=f["tsn"],
                url=url,
                description=file_info["description"],
                duration=file_info["duration"] / 1000,
                size=file_info["size"],
                title=title,
                subtitle=subtitle,
                source=source,
                mime=mime,
                tvrating=file_info["tvRating"],
            )
        except Exception, msg:
            logger.error(msg)
Beispiel #7
0
    def push_one_file(self, f):
        file_info = VideoDetails()
        file_info['valid'] = transcode.supported_format(f['path'])

        mime = 'video/mpeg'
        if config.isHDtivo(f['tsn']):
            for m in ['video/mp4', 'video/bif']:
                if transcode.tivo_compatible(f['path'], f['tsn'], m)[0]:
                    mime = m
                    break

            if (mime == 'video/mpeg' and
                transcode.mp4_remuxable(f['path'], f['tsn'])):
                new_path = transcode.mp4_remux(f['path'], f['name'], f['tsn'])
                if new_path:
                    mime = 'video/mp4'
                    f['name'] = new_path

        if file_info['valid']:
            file_info.update(self.metadata_full(f['path'], f['tsn'], mime))

        url = f['url'] + quote(f['name'])

        title = file_info['seriesTitle']
        if not title:
            title = file_info['title']

        source = file_info['seriesId']
        if not source:
            source = title

        subtitle = file_info['episodeTitle']
        try:
            m = mind.getMind(f['tsn'])
            m.pushVideo(
                tsn = f['tsn'],
                url = url,
                description = file_info['description'],
                duration = file_info['duration'] / 1000,
                size = file_info['size'],
                title = title,
                subtitle = subtitle,
                source = source,
                mime = mime,
                tvrating = file_info['tvRating'])
        except Exception, msg:
            logger.error(msg)
Beispiel #8
0
    def push_one_file(self, f):
        file_info = VideoDetails()
        file_info['valid'] = transcode.supported_format(f['path'])

        temp_share = config.get_server('temp_share', '')
        temp_share_path = ''
        remux_path = os.path.dirname(f['path'])
        if temp_share:
            for name, data in config.getShares():
                if temp_share == name:
                    temp_share_path = data.get('path')
                    remux_path = temp_share_path

        mime = 'video/mpeg'
        if config.isHDtivo(f['tsn']):
            for m in ['video/mp4', 'video/bif']:
                if transcode.tivo_compatible(f['path'], f['tsn'], m)[0]:
                    mime = m
                    break

            if (mime == 'video/mpeg' and
                transcode.mp4_remuxable(f['path'], f['tsn'])):
                if config.get_freeSpace(remux_path, f['path']):
                    new_path = transcode.mp4_remux(f['path'], f['name'], f['tsn'], temp_share_path)
                    if new_path:
                        mime = 'video/mp4'
                        f['name'] = new_path
                        if temp_share_path:
                            ip = config.get_ip()
                            port = config.getPort()
                            container = quote(temp_share) + '/'
                            f['url'] = 'http://%s:%s/%s' % (ip, port, container)
                else:
                    logger.warning('Not enough disk space to perform remux, ' +
                                   'transcoding instead.')

        if file_info['valid']:
            file_info.update(self.metadata_full(f['path'], f['tsn'], mime))

        url = f['url'] + quote(f['name'])

        title = file_info['seriesTitle']
        if not title:
            title = file_info['title']

        source = file_info['seriesId']
        if not source:
            source = title

        subtitle = file_info['episodeTitle']
        try:
            m = mind.getMind(f['tsn'])
            m.pushVideo(
                tsn = f['tsn'],
                url = url,
                description = file_info['description'],
                duration = file_info['duration'] / 1000,
                size = file_info['size'],
                title = title,
                subtitle = subtitle,
                source = source,
                mime = mime,
                tvrating = file_info['tvRating'])
        except ValueError, msg:
            if 'usernamePasswordError' in msg:
                if f['name'].endswith('.pyTivo-temp'):
                    fname = os.path.join(remux_path, os.path.basename(f['name']))
                    fname = unicode(fname, 'utf-8')
                    os.remove(fname)
                    logger.debug(fname + ' has been removed')
Beispiel #9
0
    def Push(self, handler, query):
        tsn = query['tsn'][0]
        for key in config.tivo_names:
            if config.tivo_names[key] == tsn:
                tsn = key
                break
        tivo_name = config.tivo_names.get(tsn, tsn)

        container = quote(query['Container'][0].split('/')[0])
        ip = config.get_ip()
        port = config.getPort()

        baseurl = 'http://%s:%s' % (ip, port)
        if config.getIsExternal(tsn):
            exturl = config.get_server('externalurl')
            if exturl:
                baseurl = exturl
            else:
                ip = self.readip()
                baseurl = 'http://%s:%s' % (ip, port)
 
        path = self.get_local_base_path(handler, query)

        files = query.get('File', [])
        for f in files:
            file_path = path + os.path.normpath(f)

            file_info = VideoDetails()
            file_info['valid'] = transcode.supported_format(file_path)

            mime = 'video/mpeg'
            if config.isHDtivo(tsn):
                for m in ['video/mp4', 'video/bif']:
                    if transcode.tivo_compatible(file_path, tsn, m)[0]:
                        mime = m
                        break

            if file_info['valid']:
                file_info.update(self.metadata_full(file_path, tsn, mime))

            url = baseurl + '/%s%s' % (container, quote(f))

            title = file_info['seriesTitle']
            if not title:
                title = file_info['title']

            source = file_info['seriesId']
            if not source:
                source = title

            subtitle = file_info['episodeTitle']
            try:
                m = mind.getMind(tsn)
                m.pushVideo(
                    tsn = tsn,
                    url = url,
                    description = file_info['description'],
                    duration = file_info['duration'] / 1000,
                    size = file_info['size'],
                    title = title,
                    subtitle = subtitle,
                    source = source,
                    mime = mime,
                    tvrating = file_info['tvRating'])
            except Exception, e:
                handler.send_response(500)
                handler.end_headers()
                handler.wfile.write('%s\n\n%s' % (e, traceback.format_exc() ))
                raise

            logger.info('[%s] Queued "%s" for Push to %s' %
                        (time.strftime('%d/%b/%Y %H:%M:%S'),
                         unicode(file_path, 'utf-8'), tivo_name))