class RtAgent(object): def __init__(self, conf): self.gb = GeneralBase(conf) self.app = App(conf) self.vod = Vod(conf) self.guide = Guide(conf) self.cat = Cat(conf) def interrupt(self): pass def accept(self, p, isnew = True): if p.get('_type') != 'normal': return if p.get('_device', '').lower() not in ['a11', 'a21', 'k72', 'k82', 'ud10a', 'ds70a', 'lx750a', 'lx755a', 'lx850a', 'lx960a', 'k91', 's31', 's51', 's61', 'e31', 'e62']: return if p.get('event') not in ['video_exit', 'app_start', 'launcher_vod_click', 'video_category_out']: return if isnew: if self.gb.run(p): self.app.run(p) self.vod.run(p) self.guide.run(p) self.cat.run(p) else: self.vod.run(p)
def __init__(self, video_player, controls, config, server_ip=None, server_port=None): QtGui.QDialog.__init__(self) self.config = config self.server_ip = server_ip self.server_port = server_port self.sock = None self.msg_q = asyncio.Queue() if server_ip else None self.timer = None self.video_player = video_player self.controls = controls self.guide = Guide() self.remote_vals = self.load_remote_vals() self.remote = None self.setup_ui() self.prev_volume = 100 self.muted = False self.setFixedSize(self.size()) if server_ip: self.sock = WebsocketServer(self.server_port, host=self.server_ip) self.sock.set_fn_new_client(self.on_open) self.sock.set_fn_message_received(self.on_message) self.sock_thread = threading.Thread(target=self.sock.run_forever, daemon=True) self.sock_thread.start()
def load(database): """ Load a database """ global guide guide = Guide(database) return guide
def refresh(self): '''Refetch instance data from the API. ''' response = requests.get('%s/categories/%s' % (API_BASE_URL, self.name)) attributes = response.json() self.ancestors = [Category(name) for name in attributes['ancestors']] self.contents = WikiText(attributes['contents_raw'], attributes['contents_rendered']) self.description = attributes['description'] self.guides = [] for guide in attributes['guides']: self.guides.append(Guide(guide['guideid'])) # Unlike guides, categories return flags as a dict, keyed by flagid. # *Except* when it's empty, in which case we get an empty list due to # PHP's json_encode() not knowing the difference between an empty array # and an empty dict. flags = dict(attributes['flags']).values() self.flags = [Flag.from_id(flag['flagid']) for flag in flags] self.image = Image( attributes['image']['id']) if attributes['image'] else None self.locale = attributes['locale'] #self.parts = attributes['parts'] #self.solutions = attributes['solutions'] self.title = attributes['display_title']
def createGuides(self): prevGuide = None for i in range(self.nJnt): guide = Guide(shader = self.shader,name=self.name + '_guide_' + (str(i)).zfill(2),moduleParent = self.name) guide.drawGuide() pos = [0,0,i*10] if i == 0: self.moduleCtrl ,self.moduleCtrlGrp = utils.buildBoxController(guide.name,self.name + '_ctrl',2) pm.parent(self.moduleCtrlGrp,self.moduleGrp) pm.parent(self.moduleGuidesGrp,self.moduleCtrl) guide.setPos(pos) self.guidesList.append(guide.name) pm.parent(guide.guideGrp,self.moduleGuidesGrp) attrName = 'guide_' + (str(i)).zfill(2) pm.addAttr(self.moduleCtrl,ln=attrName,at='message') guide.transform.message.connect( self.moduleCtrl.attr(attrName)) if i > 0: connectionGrp = prevGuide.drawConnectionTo(guide) pm.parent(connectionGrp,self.moduleConnectionsGrp) prevGuide = guide self.moduleRebuildInfo['guidesList'] = self.guidesList self.moduleCtrlGrp.setTranslation(self.position,space='world')
def __init__(self, verbose=VERBOSE, checker=None): self.myverbose = verbose # now unused self.checker = checker self.base = None self.links = {} self.runtime = None self.channel = None self.title = None self.titleid = None self.svcid = None self.start_time = None self.starting_time = None self.event_time = None self.event_hour = None self.event_date = None self.starting_point = 973728000.0 self.starting_point = 973728000.0 + (4 * 60 * 60) self.prime_start_time = 0 self.guide = Guide() sgmllib.SGMLParser.__init__(self)
def exampleB(template="harbie_biped", build=True): start = dt.now() path = os.path.join(os.path.dirname(__file__), "templates", template + ".xml") guide = Guide.fromXml(path) print "Create Rig from Template", dt.now() - start if build: start = dt.now() guide.build() print "Build Rig", dt.now() - start return guide
def __init__(self, mapNodes, north, voice): ### OBJECTS ### if constants.VISUALISATION: self.visual = visualiseMap(1300, 1300) self.visual.setMap(mapNodes, 0) self.path = Path(mapNodes) self.guide = Guide(voice) self.voiceOutput = voice ### CLASS ATTRIBUTES ### self.mapNodes = mapNodes self.mapNorth = north self.currNode = {} self.currCoor = [] self.nextNode = 0 self.nextCoor = 0 self.lastUpdatedTime = 0 self.destinationNode = {} self.destinationCoor = [] self.routeNodes = {}
def __init__(self, verbose=VERBOSE, checker=None): self.myverbose = verbose # now unused self.checker = checker self.base = None self.links = {} self.runtime = None self.channel = None self.title = None self.titleid = None self.svcid = None self.start_time=None self.starting_time = None self.event_time=None self.event_hour = None self.event_date = None self.starting_point = 973728000.0 self.starting_point = 973728000.0 + (4 * 60 * 60) self.prime_start_time = 0; self.guide = Guide(); sgmllib.SGMLParser.__init__(self)
def game_loop(args, clock): global hud, controller, world, display # attack_performed = 0 pygame.init() pygame.font.init() guide_me = Guide() try: client = carla.Client(args.host, args.port) client.set_timeout(2.0) # timeout in case the client loses connection log = create_logfile(args) display = pygame.display.set_mode((args.width, args.height), pygame.HWSURFACE | pygame.DOUBLEBUF) hud = HUD(args, log, __doc__) world = World(client.get_world(), hud, args.filter) controller = DualControl(world, args) if args.cyberattack: thread.start_new_thread(controller.attack_trigger, ()) time.sleep(1.5) thread.start_new_thread(hud.write_driving_data, (True, )) while True: clock.tick_busy_loop(40) # max fps in client if controller.parse_events(world, clock): return world.tick(clock) world.render() guide.render(guide_me) pygame.display.flip() finally: time.sleep(1) # delay to allow threads to finish first controller.video.stop_recording() if world is not None: world.destroy() pygame.quit()
def create_guide(self): self.guide = Guide() return
class Navigation: def __init__(self, mapNodes, north, voice): ### OBJECTS ### if constants.VISUALISATION: self.visual = visualiseMap(1300, 1300) self.visual.setMap(mapNodes, 0) self.path = Path(mapNodes) self.guide = Guide(voice) self.voiceOutput = voice ### CLASS ATTRIBUTES ### self.mapNodes = mapNodes self.mapNorth = north self.currNode = {} self.currCoor = [] self.nextNode = 0 self.nextCoor = 0 self.lastUpdatedTime = 0 self.destinationNode = {} self.destinationCoor = [] self.routeNodes = {} ########################################## # Functions called by Main ########################################## def getRoute(self, start_point, end_point): self.path.shortestPath(start_point) route = self.path.routeToTravel(start_point, end_point) self.routeNodes = self.getRouteNodes(route) self.setAttributes(start_point, end_point) if constants.VISUALISATION: self.visual.setMap(self.routeNodes, 1) self.visual.printMap() return self.routeNodes def beginNavigation(self, apNodes): while abs(self.currCoor[0] - self.destinationCoor[0]) > (constants.PROXIMITY_RADIUS * 100) or abs( self.currCoor[1] - self.destinationCoor[1] ) > (constants.PROXIMITY_RADIUS * 100): offset = int(self.calculateOffset()) bearingToFace = (self.mapNorth + offset) % 360 self.currCoor = self.guide.updateCoordinates(self.currCoor, self.mapNorth, apNodes, bearingToFace) self.guide.warnUser(self.currCoor, self.mapNorth) if self.checkLocation(bearingToFace): break self.guide.checkBearing(bearingToFace, self.currCoor, self.nextCoor) # self.guide.destinationReached() ########################################## # Helper Functions ########################################## def getRouteNodes(self, route): route_nodes = {} for i in range(len(route)): route_nodes[route[i]] = self.mapNodes[route[i]] if i != len(route) - 1: route_nodes[route[i]]["linkTo"] = [route[i + 1]] else: del route_nodes[route[i]]["linkTo"] return route_nodes def setAttributes(self, start_point, end_point): self.currNode = self.routeNodes.get(start_point) self.currCoor = [int(self.currNode.get("x")), int(self.currNode.get("y"))] self.destinationNode = self.routeNodes.get(end_point) self.destinationCoor = [int(self.destinationNode.get("x")), int(self.destinationNode.get("y"))] self.nextNode = self.routeNodes.get((self.currNode.get("linkTo"))[0]) self.nextCoor = [int(self.nextNode.get("x")), int(self.nextNode.get("y"))] self.guide.lastUpdatedTime = time.time() def calculateOffset(self): if self.currCoor[0] < self.nextCoor[0]: if self.currCoor[1] < self.nextCoor[1]: return math.degrees( math.atan2((self.nextCoor[0] - self.currCoor[0]), (self.nextCoor[1] - self.currCoor[1])) ) elif self.currCoor[1] > self.nextCoor[1]: return 180 - math.degrees( math.atan2((self.nextCoor[0] - self.currCoor[0]), (self.currCoor[1] - self.nextCoor[1])) ) else: return 90 elif self.currCoor[0] > self.nextCoor[0]: if self.currCoor[1] < self.nextCoor[1]: return 360 - math.degrees( math.atan2((self.currCoor[0] - self.nextCoor[0]), (self.nextCoor[1] - self.currCoor[1])) ) elif self.currCoor[1] > self.nextCoor[1]: return 180 + math.degrees( math.atan2((self.currCoor[0] - self.nextCoor[0]), (self.currCoor[1] - self.nextCoor[1])) ) else: return 270 else: if self.currCoor[1] < self.nextCoor[1]: return 360 else: return 180 def checkLocation(self, bearingToFace): if abs(self.currCoor[0] - self.nextCoor[0]) < (constants.PROXIMITY_RADIUS * 100) and abs( self.currCoor[1] - self.nextCoor[1] ) < (constants.PROXIMITY_RADIUS * 100): self.currNode = self.nextNode if self.currNode == self.destinationNode: # why?!?! return True self.nextNode = self.routeNodes.get((self.currNode.get("linkTo"))[0]) self.nextCoor = (int(self.nextNode.get("x")), int(self.nextNode.get("y"))) self.guide.userReachedNode(self.currNode) self.guide.userNextNode(self.nextNode) if (self.currNode.get("name")) == "P16" and (self.nextNode.get("name") == "P37"): message = messages.STAIRS_AHEAD_TEMPLATE.format(steps=int(4.5 / constants.STEP_LENGTH)) self.voiceOutput.addToQueue(message, constants.HIGH_PRIORITY) elif (self.currNode.get("name")) == "P37" and (self.nextNode.get("name") == "P16"): message = messages.STAIRS_AHEAD_TEMPLATE.format(steps=2) self.voiceOutput.addToQueue(message, constants.HIGH_PRIORITY) elif (self.currNode.get("name")) == "Student Area" and (self.nextNode.get("name") == "P13"): message = messages.STAIRS_AHEAD_TEMPLATE.format(steps=int(3.0 / constants.STEP_LENGTH)) self.voiceOutput.addToQueue(message, constants.HIGH_PRIORITY) elif (self.currNode.get("name")) == "P13" and (self.nextNode.get("name") == "Student Area"): message = messages.STAIRS_AHEAD_TEMPLATE.format(steps=int(5.0 / constants.STEP_LENGTH)) self.voiceOutput.addToQueue(message, constants.HIGH_PRIORITY) self.guide.checkBearing(bearingToFace, self.currCoor, self.nextCoor) return False
def exampleA(mirror=False, showWindow=False): '''Built a basic and a chain system. Set the basic to be dynamic and connect the chain to it. Args: mirror (bool): True to duplicate the systems on the right side showWindow (bool): True to popup Brigks Main Window ''' # Building Matrix for guide positions basicMatrices = dict( Part1=Transformation.fromParts(translation=Vector3([2, 2, 0])), Part2=Transformation.fromParts(translation=Vector3([4, 2, 0])), ) chainMatrices = dict( Part1=Transformation.fromParts(translation=Vector3([2, 3, 0])), Part2=Transformation.fromParts(translation=Vector3([4, 4, 0])), Part3=Transformation.fromParts(translation=Vector3([6, 3, 0])), ) # Create Guide, add a layer and a couple Systems guide = Guide() guide.setSettings(hideRig=False) guide.setSettings(hideJoints=False) layer = guide.addLayer("MyFirstLayer") basic = layer.addSystem("basic", "L", "Basic", basicMatrices) chain = layer.addSystem("chain", "L", "Chain", chainMatrices) # System Settings basic.setSettings(dynamic=True, dynamicAnimatable=True, strap=True) # Connections chain.addConnection("Root", "slotParent", key=basic.key(), slot="Part1") if mirror: for system in layer.systems().values(): system.duplicate(mirror=True) # Save edit guide.commit() # Build all rig guide.build() if showWindow: showWindow() return guide
class TvGuideParser(sgmllib.SGMLParser): def __init__(self, verbose=VERBOSE, checker=None): self.myverbose = verbose # now unused self.checker = checker self.base = None self.links = {} self.runtime = None self.channel = None self.title = None self.titleid = None self.svcid = None self.start_time = None self.starting_time = None self.event_time = None self.event_hour = None self.event_date = None self.starting_point = 973728000.0 self.starting_point = 973728000.0 + (4 * 60 * 60) self.prime_start_time = 0 self.guide = Guide() sgmllib.SGMLParser.__init__(self) # self.zone_offset = time.timezone def translate(self, translate_data): self.translate_data = translate_data def filter(self, filter_data): self.filter_data = filter_data def set_event_time(self, event_time): self.event_time = event_time self.starting_time = None # # convert tvguide time to unix time # def tvguide_seconds(self, start_time): # 86400 = 1800 * 48 time_sec = start_time - 36839.2083333333 temp = self.starting_point + time_sec * 86400 + 290 temp = temp - (temp % 300) return temp # # convret unix time to tvguide time # def seconds_tvguide(self, start_time): start_time = (start_time - self.starting_point) / 86400 start_time = start_time + 36839.2083333333333 return start_time def start_td(self, attributes): for name, value in attributes: if name == 'colspan': self.runtime = atoi(value) * 5 def start_tr(self, attributes): self.start_time = self.event_time self.channel = None def start_a(self, attributes): self.svcid = None self.titleid = None # self.print_attrib("start_a", attributes) for name, value in attributes: if (name == 'href'): start = find(value, "cl(") if start < 0: return start = start + 3 end = find(value, ",") if end < 0: return self.svcid = value[start:end] start = end + 1 end = find(value, ')') if end < 0: self.svcid = None reutrn self.titleid = value[start:end] def start_b(self, attributes): if self.starting_time == None: self.prime_start_time = 1 def end_b(self): self.prime_start_time = 0 def end_a(self): if self.svcid != None and self.titleid != None and self.title != None: if self.translate_data.has_key(self.channel): self.channel = self.translate_data[self.channel] if self.filter_data.has_key(self.channel): if VERBOSE: print "found titleid=", self.titleid, "title=", self.title, "runtime=", self.runtime, "time=", self.start_time, "channel=", self.channel curr_time = self.tvguide_seconds(self.start_time) self.guide.append([ curr_time, self.channel, self.runtime, self.title, self.svcid + ',' + self.titleid ]) self.start_time = self.start_time + float( self.runtime) / (24.0 * 60.0) self.svcid = None self.titleid = None self.title = None self.runtime = None def handle_data(self, data): if self.starting_time == None: if self.prime_start_time == 1: # print "start time: ", data, "starting_time=", self.starting_time self.prime_start_time = 0 if self.channel == None: self.channel = data self.start_time = self.event_time return if self.svcid != None and self.titleid != None: if self.title == None: self.title = data else: self.title = self.title + data def print_attrib(self, msg, attributes): print print print msg for name, value in attributes: print name, "->", value
def __init__(self): Guide.__init__(self) self.parser = TvGuideParser() self.starting_point = 973728000.0
class ControlsDialog(QtGui.QDialog): def __init__(self, video_player, controls, config, server_ip=None, server_port=None): QtGui.QDialog.__init__(self) self.config = config self.server_ip = server_ip self.server_port = server_port self.sock = None self.msg_q = asyncio.Queue() if server_ip else None self.timer = None self.video_player = video_player self.controls = controls self.guide = Guide() self.remote_vals = self.load_remote_vals() self.remote = None self.setup_ui() self.prev_volume = 100 self.muted = False self.setFixedSize(self.size()) if server_ip: self.sock = WebsocketServer(self.server_port, host=self.server_ip) self.sock.set_fn_new_client(self.on_open) self.sock.set_fn_message_received(self.on_message) self.sock_thread = threading.Thread(target=self.sock.run_forever, daemon=True) self.sock_thread.start() def on_message(self, cli, serv, msg): print(msg) p = msg.find(':') if p == -1: command = msg else: command = msg[:p] data = msg[p + 1:] if command == 'time': try: data = data.split('/') current_f = float(data[0]) total_f = float(data[1]) current = int(current_f * 1000) total = int(total_f * 1000) except ValueError: return pos = int((current / total) * 10000) self.controls.time_slider.setValue(pos) self.update_time_label(pos, total) if math.isclose(current_f, total_f): self.next_episode_button_clicked() elif command == 'vol': vol = int(float(data) * 100) self.controls.volume_slider.setValue(vol) def on_open(self, cli, serv): print('got connection') def load_remote_vals(self): vals = {} with open('remote.txt', 'r') as f: for line in f: if line: l = line.rstrip().split(' ') vals[l[0]] = l[1] for k, v in vals.items(): SerialRemote.values[v] = k return vals def setup_ui(self): self.controls.setupUi(self) self.remote_refresh_clicked() self.controls.host_box.addItems(self.guide.plugin_names) plugin = self.config.get('PyWatch', 'host', fallback=None) if plugin: self.controls.host_box.setCurrentIndex( self.controls.host_box.findText(plugin)) self.controls.type_box.clear() self.controls.type_box.addItems(self.guide.get_categories()) typ = self.config.get('PyWatch', 'type', fallback=None) if typ: self.controls.type_box.setCurrentIndex( self.controls.type_box.findText(typ)) series = self.config.get('PyWatch', 'series', fallback=None) if series: self.controls.series_box.setCurrentIndex( self.controls.series_box.findText(series)) epi = self.config.get('PyWatch', 'episode', fallback=None) if epi: self.controls.episode_box.setCurrentIndex( self.controls.episode_box.findText(epi)) if self.video_player: vol = int(self.config.get('PyWatch', 'volume', fallback=100)) speed = (float(self.config.get('PyWatch', 'speed', fallback=1.1)) * 100) // 2 remote = self.config.get('PyWatch', 'remote', fallback=None) self.controls.volume_slider.setValue(vol) self.volume_changed(vol) self.controls.speed_slider.setValue(speed) self.speed_changed(speed) if remote: self.controls.remote_box.setCurrentIndex( self.controls.remote_box.findText(remote)) self.timer = QtCore.QTimer(self) self.timer.setInterval(200) self.connect(self.timer, QtCore.SIGNAL("timeout()"), self.update_ui) self.timer.start() def remote_refresh_clicked(self): open_ports = [''] + SerialRemote.open_ports() self.controls.remote_box.clear() self.controls.remote_box.addItems(open_ports) def remote_box_changed(self, port): if self.remote: self.remote.stop() self.remote.wait() self.remote = None if port: self.remote = SerialRemote(port) self.remote.signal_chmin.connect(self.prev_episode_button_clicked) self.remote.signal_ch.connect(self.replay_button_clicked) self.remote.signal_chplus.connect(self.next_episode_button_clicked) self.remote.signal_volmin.connect(self.volume_down) self.remote.signal_volplus.connect(self.volume_up) self.remote.signal_eq.connect(self.toggle_mute) self.remote.signal_play.connect(self.toggle_pause_clicked) self.remote.signal_100.connect(self.large_jump_backwards_clicked) self.remote.signal_2.connect(self.small_jump_backwards_clicked) self.remote.signal_200.connect(self.large_jump_forwards_clicked) self.remote.signal_3.connect(self.small_jump_forwards_clicked) self.remote.signal_prev.connect(self.decrease_speed) self.remote.signal_next.connect(self.increase_speed) self.remote.start() def decrease_speed(self): self.controls.speed_slider.setValue( self.controls.speed_slider.value() - 1) self.speed_changed(self.controls.speed_slider.value()) def increase_speed(self): self.controls.speed_slider.setValue( self.controls.speed_slider.value() + 1) self.speed_changed(self.controls.speed_slider.value()) def volume_down(self): self.controls.volume_slider.setValue( self.controls.volume_slider.value() - 10) self.prev_volume = self.controls.volume_slider.value() self.volume_changed(self.prev_volume) self.muted = False def volume_up(self): self.controls.volume_slider.setValue( self.controls.volume_slider.value() + 10) self.prev_volume = self.controls.volume_slider.value() self.volume_changed(self.prev_volume) self.muted = False def toggle_mute(self): if self.muted: self.controls.volume_slider.setValue(self.prev_volume) self.volume_changed(self.prev_volume) self.muted = False else: self.prev_volume = self.controls.volume_slider.value() self.controls.volume_slider.setValue(0) self.volume_changed(0) self.muted = True def replay_button_clicked(self): if self.video_player and self.video_player.current_url: self.video_player.media.parse() self.play(self.video_player.current_url) self.video_player.pause(False) elif self.sock: self.sock.send_message_to_all('replay') def next_episode_button_clicked(self): next_index = self.controls.episode_box.currentIndex() + 1 self.controls.episode_box.setCurrentIndex(next_index) index = self.controls.episode_box.currentIndex() if index == next_index: self.play_episode_clicked() if self.video_player: self.video_player.pause(False) def prev_episode_button_clicked(self): next_index = self.controls.episode_box.currentIndex() - 1 if next_index >= 0: self.controls.episode_box.setCurrentIndex(next_index) index = self.controls.episode_box.currentIndex() if index == next_index: self.play_episode_clicked() if self.video_player: self.video_player.pause(False) def toggle_pause_clicked(self): if self.video_player: self.video_player.pause(not self.video_player.paused) elif self.sock: self.sock.send_message_to_all('toggle_pause') def small_jump_forwards_clicked(self): self.offset_time(10000) def small_jump_backwards_clicked(self): self.offset_time(-10000) def large_jump_forwards_clicked(self): self.offset_time(60000) def large_jump_backwards_clicked(self): self.offset_time(-60000) def offset_time(self, offset): if self.video_player: self.video_player.media_player.set_time( self.video_player.media_player.get_time() + offset) elif self.sock: self.sock.send_message_to_all(f'offset:{offset/1000}') def filter_changed(self): self.guide.filter = self.controls.filter_box.text() self.controls.series_box.clear() self.controls.series_box.addItems(self.guide.get_series()) def volume_changed(self, vol): if self.video_player: self.video_player.media_player.audio_set_volume(vol) elif self.sock: self.sock.send_message_to_all(f'vol:{vol/100}') def speed_changed(self, speed): speed = (speed / 100) * 2 self.controls.speed_label.setText(str(int(speed * 100)) + '%') if self.video_player: self.video_player.media_player.set_rate(speed) elif self.sock: self.sock.send_message_to_all(f'speed:{speed}') def toggle_fullscreen(self): if self.video_player: win = self.video_player.videoframe.window() win.setWindowState(win.windowState() ^ QtCore.Qt.WindowFullScreen) def play_episode_clicked(self): url = self.guide.get_selected_url() if url: self.play(url) if self.video_player: self.video_player.pause(False) def host_box_changed(self, index): if index == 0: return self.guide.selected_plugin = index self.controls.type_box.clear() self.controls.type_box.addItems(self.guide.get_categories()) self.controls.series_box.clear() self.controls.series_box.addItems(self.guide.get_series()) def series_box_changed(self, series): self.guide.selected_series = series self.controls.episode_box.clear() self.controls.episode_box.addItems(self.guide.get_episodes()) def episode_box_changed(self, episode): self.guide.selected_episode = episode def type_box_changed(self, cat): if cat != '': self.guide.selected_category = cat self.controls.series_box.clear() self.controls.series_box.addItems(self.guide.get_series()) def time_slider_pressed(self): if self.video_player: self.video_player.pause(True) elif self.sock: self.sock.send_message_to_all('pause') def time_slider_released(self): if self.video_player: self.video_player.media_player.set_position( self.controls.time_slider.value() / 10000) self.video_player.pause(False) elif self.sock: pos = self.controls.time_slider.value() / 10000 self.sock.send_message_to_all(f'time:{pos}') def update_time_label(self, value, length): percent = (value / 10000) pos = length * percent total_min = int(length / 60000.0) total_sec = int(length / 1000.0 % 60.0) cur_min = int(pos / 60000.0) cur_sec = int(pos / 1000.0 % 60.0) time = '{:02}:{:02} / {:02}:{:02}'.format(cur_min, cur_sec, total_min, total_sec) self.controls.time_label.setText(time) def time_slider_moved(self, value): if self.video_player: self.update_time_label(value, self.video_player.media_player.get_length()) def play(self, url): print(f'Playing {url}') if self.video_player: self.video_player.media = self.video_player.instance.media_new( url, 'network-cache=1500000', 'file-cache=1500000') self.video_player.media_player.set_media(self.video_player.media) self.video_player.videoframe.window().setWindowTitle( self.guide.selected_episode) self.video_player.media_player.play() self.video_player.current_url = url if sys.platform == "linux2": self.video_player.media_player.set_xwindow( self.video_player.videoframe.winId()) elif sys.platform == "win32": self.video_player.media_player.set_hwnd( self.video_player.videoframe.winId()) elif sys.platform == "darwin": self.video_player.media_player.set_agl( self.video_player.videoframe.windId()) elif self.sock: self.sock.send_message_to_all(f'play:{url}') def update_ui(self): if self.video_player: if not self.video_player.paused and self.video_player.media_player.is_playing( ): val = self.video_player.media_player.get_position() * 10000 self.controls.time_slider.setValue(val) self.update_time_label( val, self.video_player.media_player.get_length()) if self.video_player.media_player.get_state() == vlc.State.Ended: cur = self.video_player.media_player.get_position() if cur < .99: print(f'Error at {cur*100}%, replaying', file=sys.stderr) self.replay_button_clicked() self.video_player.media_player.set_position(cur) else: self.next_episode_button_clicked() self.config['PyWatch']['type'] = self.controls.type_box.currentText() self.config['PyWatch']['host'] = self.controls.host_box.currentText() self.config['PyWatch'][ 'series'] = self.controls.series_box.currentText() self.config['PyWatch'][ 'episode'] = self.controls.episode_box.currentText() self.config['PyWatch'][ 'remote'] = self.controls.remote_box.currentText() self.config['PyWatch']['volume'] = str( self.controls.volume_slider.value()) self.config['PyWatch']['speed'] = str( (self.controls.speed_slider.value() * 2) / 100)
def __init__(self, conf): self.gb = GeneralBase(conf) self.app = App(conf) self.vod = Vod(conf) self.guide = Guide(conf) self.cat = Cat(conf)
class TvGuideParser(sgmllib.SGMLParser): def __init__(self, verbose=VERBOSE, checker=None): self.myverbose = verbose # now unused self.checker = checker self.base = None self.links = {} self.runtime = None self.channel = None self.title = None self.titleid = None self.svcid = None self.start_time=None self.starting_time = None self.event_time=None self.event_hour = None self.event_date = None self.starting_point = 973728000.0 self.starting_point = 973728000.0 + (4 * 60 * 60) self.prime_start_time = 0; self.guide = Guide(); sgmllib.SGMLParser.__init__(self) # self.zone_offset = time.timezone def translate(self, translate_data): self.translate_data = translate_data def filter(self, filter_data): self.filter_data = filter_data def set_event_time(self, event_time): self.event_time = event_time self.starting_time = None # # convert tvguide time to unix time # def tvguide_seconds(self, start_time): # 86400 = 1800 * 48 time_sec = start_time - 36839.2083333333 temp = self.starting_point + time_sec * 86400 + 290 temp = temp - (temp % 300) return temp # # convret unix time to tvguide time # def seconds_tvguide(self, start_time): start_time = (start_time - self.starting_point) / 86400 start_time = start_time + 36839.2083333333333 return start_time def start_td(self, attributes): for name, value in attributes: if name == 'colspan': self.runtime = atoi(value) * 5 def start_tr(self, attributes): self.start_time = self.event_time self.channel = None def start_a(self, attributes): self.svcid = None self.titleid = None # self.print_attrib("start_a", attributes) for name, value in attributes: if (name == 'href'): start = find(value, "cl(") if start < 0: return start = start + 3 end = find(value, ",") if end < 0: return self.svcid = value[start:end] start = end + 1 end = find(value, ')'); if end < 0: self.svcid = None reutrn self.titleid = value[start:end] def start_b(self, attributes): if self.starting_time == None: self.prime_start_time = 1; def end_b(self): self.prime_start_time = 0; def end_a(self): if self.svcid != None and self.titleid != None and self.title != None: if self.translate_data.has_key(self.channel): self.channel = self.translate_data[self.channel] if self.filter_data.has_key(self.channel): if VERBOSE: print "found titleid=",self.titleid, "title=",self.title, "runtime=",self.runtime, "time=",self.start_time, "channel=",self.channel curr_time = self.tvguide_seconds(self.start_time) self.guide.append([curr_time, self.channel, self.runtime, self.title, self.svcid +','+self.titleid]) self.start_time = self.start_time + float(self.runtime)/(24.0 * 60.0) self.svcid = None self.titleid = None self.title = None self.runtime = None def handle_data(self, data): if self.starting_time == None: if self.prime_start_time == 1: # print "start time: ", data, "starting_time=", self.starting_time self.prime_start_time = 0 if self.channel == None: self.channel = data self.start_time = self.event_time return if self.svcid != None and self.titleid != None: if self.title == None: self.title = data else: self.title = self.title + data def print_attrib(self, msg, attributes): print print print msg for name, value in attributes: print name, "->",value