예제 #1
0
파일: togo.py 프로젝트: wynneth/pytivo
    def get_tivo_file(self, tivoIP, url, mak, togo_path):
        # global status
        status[url].update({'running': True, 'queued': False})

        parse_url = urlparse.urlparse(url)

        name = unquote(parse_url[2])[10:].split('.')
        id = unquote(parse_url[4]).split('id=')[1]
        name.insert(-1, ' - ' + id + '.')
        if status[url]['decode']:
            name[-1] = 'mpg'
        outfile = os.path.join(togo_path, ''.join(name))

        if status[url]['save']:
            meta = basic_meta[url]
            details_url = 'https://%s/TiVoVideoDetails?id=%s' % (tivoIP, id)
            try:
                handle = self.tivo_open(details_url)
                meta.update(metadata.from_details(handle))
                handle.close()
            except:
                pass
            metafile = open(outfile + '.txt', 'w')
            metadata.dump(metafile, meta)
            metafile.close()

        auth_handler.add_password('TiVo DVR', url, 'tivo', mak)
        try:
            handle = self.tivo_open(url)
        except urllib2.HTTPError, e:
            status[url]['running'] = False
            status[url]['error'] = e.code
            logger.error(e.code)
            return
예제 #2
0
    def get_tivo_file(self, tivoIP, url, mak, togo_path):
        # global status
        status[url].update({'running': True, 'queued': False})

        parse_url = urlparse.urlparse(url)

        name = unquote(parse_url[2])[10:].split('.')
        id = unquote(parse_url[4]).split('id=')[1]
        name.insert(-1, ' - ' + id + '.')
        if status[url]['decode']:
            name[-1] = 'mpg'
        outfile = os.path.join(togo_path, ''.join(name))

        if status[url]['save']:
            meta = basic_meta[url]
            details_url = 'https://%s/TiVoVideoDetails?id=%s' % (tivoIP, id)
            try:
                handle = self.tivo_open(details_url)
                meta.update(metadata.from_details(handle))
                handle.close()
            except:
                pass
            metafile = open(outfile + '.txt', 'w')
            metadata.dump(metafile, meta)
            metafile.close()

        auth_handler.add_password('TiVo DVR', url, 'tivo', mak)
        try:
            handle = self.tivo_open(url)
        except urllib2.HTTPError, e:
            status[url]['running'] = False
            status[url]['error'] = e.code
            logger.error(e.code)
            return
예제 #3
0
파일: togo.py 프로젝트: myeh/pytivo
    def get_tivo_file(self, tivoIP, url, mak, togo_path):
        # global status
        status[url].update({'running': True, 'queued': False})

        parse_url = urlparse.urlparse(url)

        if status[url]['save']:
            meta = basic_meta[url]

        name = unicode(unquote(parse_url[2]),
                       'utf-8').split('/')[-1].split('.')
        try:
            name.insert(-1, ' - ' + meta['episodeTitle'])
        except:
            pass
        ts = status[url]['ts_format']
        if status[url]['decode']:
            if ts:
                name[-1] = 'ts'
            else:
                name[-1] = 'mpg'
        else:
            if ts:
                name.insert(-1, ' (TS)')
            else:
                name.insert(-1, ' (PS)')
        name.insert(-1, '.')
        name = ''.join(name)
        for ch in BADCHAR:
            name = name.replace(ch, BADCHAR[ch])
        outfile = os.path.join(togo_path, name)

        if status[url]['save']:
            meta = basic_meta[url]
            try:
                handle = self.tivo_open(details_urls[url])
                meta.update(metadata.from_details(handle.read()))
                handle.close()
            except:
                pass
            metafile = open(outfile + '.txt', 'w')
            metadata.dump(metafile, meta)
            metafile.close()

        auth_handler.add_password('TiVo DVR', url, 'tivo', mak)
        try:
            if status[url]['ts_format']:
                handle = self.tivo_open(url + '&Format=video/x-tivo-mpeg-ts')
            else:
                handle = self.tivo_open(url)
        except Exception, msg:
            status[url]['running'] = False
            status[url]['error'] = str(msg)
            return
예제 #4
0
파일: togo.py 프로젝트: OmniWolfe/pytivo
    def get_tivo_file(self, tivoIP, url, mak, togo_path):
        # global status
        status[url].update({'running': True, 'queued': False})

        parse_url = urlparse.urlparse(url)

        name = unicode(unquote(parse_url[2]), 'utf-8').split('/')[-1].split('.')
        try:
            id = unquote(parse_url[4]).split('id=')[1]
            name.insert(-1, ' - ' + id)
        except:
            pass
        ts = status[url]['ts_format']
        if status[url]['decode']:
            if ts:
                name[-1] = 'ts'
            else:
                name[-1] = 'mpg'
        else:
            if ts:
                name.insert(-1, ' (TS)')
            else:
                name.insert(-1, ' (PS)')
        name.insert(-1, '.')
        name = ''.join(name)
        for ch in BADCHAR:
            name = name.replace(ch, BADCHAR[ch])
        outfile = os.path.join(togo_path, name)

        if status[url]['save']:
            meta = basic_meta[url]
            try:
                handle = self.tivo_open(details_urls[url])
                meta.update(metadata.from_details(handle.read()))
                handle.close()
            except:
                pass
            metafile = open(outfile + '.txt', 'w')
            metadata.dump(metafile, meta)
            metafile.close()

        auth_handler.add_password('TiVo DVR', url, 'tivo', mak)
        try:
            if status[url]['ts_format']:
                handle = self.tivo_open(url + '&Format=video/x-tivo-mpeg-ts')
            else:
                handle = self.tivo_open(url)
        except Exception, msg:
            status[url]['running'] = False
            status[url]['error'] = str(msg)
            return
예제 #5
0
	def handlekeypress(self, keynum, rawcode):
		if keynum == KEY_TIVO and rawcode == MYKEY_PUSHRESUME:
			tivo = 0
			if self.submenu:
				tivo = self.submenu.getResult()
				self.submenu = None

			if tivo == -1:
				self.isactive = False
				self.app.send_key(KEY_TIVO, MYKEY_PUSHCOMPLETE)
				return

			tivoname = self.menu[tivo]
			tsn = self.tsns[tivo]
		
			if self.sep is None or self.sep == os.path.sep:
				relfile = os.path.sep + self.vf.getRelativePath(self.container)
			else:
				relfile = self.sep + self.vf.getRelativePath(self.container).translate(maketrans(os.path.sep, self.sep))
			
			params = urllib.urlencode({'Command': 'Push', 'Container': self.container,
						'File': relfile,
						'tsn': tsn})
			url = 'http://%s:%s/TivoConnect' % (self.ip, self.port)

			try:
				f = urllib.urlopen(url, params)
				html = f.read()
				
			except:
				MessageBox(self.app, "Push Error",
						"An unknown exception has occurred during HTML request - verify configuration",
						'bonk',
						[[[], MYKEY_PUSHCOMPLETE]])
			else:
				if html.lower().count('queue') != 0:
					if self.opts['savepushdata']:
						self.vf.setMetaItem("pushDate", strftime("%Y-%m-%dT%H:%M:%SZ", gmtime()))
						self.vf.setMetaItem("vPushTivo", tivoname)
						meta = self.vf.getMeta()
						try:
							fn = self.vf.getMetaFileName()
							metafile = open(fn, 'w')
							metadata.dump(metafile, meta)
							metafile.close()
						except:
							pass
					MessageBox(self.app, "Successfully Queued",
							"File has been successfully queued for push to " + tivoname,
							'alert',
							[[[], MYKEY_PUSHCOMPLETE]])
					
				else:
					MessageBox(self.app, "Push Error",
							"PyTivo responded with an unknown message (%s) push may still occur" % html,
							'alert',
							[[[], MYKEY_PUSHCOMPLETE]])

		elif self.submenu:
			self.submenu.handlekeypress(keynum, rawcode)

		else:
			self.app.sound('bonk')
예제 #6
0
                        continue

                    os.rename(outfile, new_outfile)
                    outfile = new_outfile
                    break

            if save_txt and os.path.isfile(outfile):
                meta = basic_meta[url]
                try:
                    handle = self.tivo_open(details_urls[url])
                    meta.update(metadata.from_details(handle.read()))
                    handle.close()
                except:
                    pass
                metafile = open(outfile + '.txt', 'w')
                metadata.dump(metafile, meta)
                metafile.close()

            status[url]['best_file'] = outfile
            status[url]['best_error_count'] = status[url]['ts_error_count']

            if retry_download:
                status[url]['rate'] = 0
                status[url]['size'] = 0
                status[url]['queued'] = True
                status[url]['retry'] += 1
                status[url]['ts_error_count'] = 0
                logger.info('TS sync losses detected, retrying download (%d)' %
                            status[url]['retry'])
                queue[tivoIP].insert(1, url)
            else: