def run(self): self.running = True match_ids = set() for details in self.highlights.values(): match_id = details['match_id'] if match_id is not None: region = details['region'] match_ids.add((region, match_id)) no_of_ids = len(match_ids) retrieved = {} for x, (region, match_id) in enumerate(match_ids, 1): if not self.running: break url = f'https://slick.co.ke/v1/match/{region}/{match_id}' match_details = requests.get(url).json() retrieved[match_id] = match_details self.status.emit( f'Retrieving match details: {round((x/no_of_ids) * 100, 1)}%') no_of_highlights = len(self.highlights) summoner_name = DataStore.get_preferences()['user_name'] index = 1 for name, details in self.highlights.items(): match_id = details['match_id'] if match_id in retrieved: full_details = retrieved[match_id] game_mode = full_details['gameMode'] queue_id = full_details['queueId'] mode = utils.get_mode(game_mode, queue_id) self.highlights[name]['game_mode'] = mode for participant in full_details['participantIdentities']: if participant['player']['summonerName'] == summoner_name: participant_id = participant['participantId'] for participant in full_details['participants']: if participant['participantId'] == participant_id: champion_id = participant['championId'] champion_name = DataStore.get_champion_by_id( champion_id) self.highlights[name]['played_as'] = champion_name self.highlights[name]['win'] = \ participant['stats']['win'] percentage = round((index/no_of_highlights) * 100) self.status.emit( f'Processing highlights: {percentage}%') index += 1 DataStore.save_partial_highlights(self.highlights, to_file=True) self.status.emit('Done') self.done_status.emit()
def handle_upload_url(self, result): highlight_name, video_url = result self.window.status.showMessage( f'Uploaded {highlight_name} as {video_url}') if 'gfycat' in video_url: service = 'gfycat' elif 'streamable' in video_url: service = 'streamable' highlight = DataStore.get_highlight(highlight_name) highlight[service] = video_url DataStore.save_highlight(highlight_name, highlight) self.window.refresh()
def item_clicked(self, item): highlight_name = item.text() self.selected = highlight_name highlight_details = DataStore.get_highlight(highlight_name) self.widgets['name'].setText(highlight_details['name']) self.widgets['patch'].setText(highlight_details['patch_version']) size_in_bytes = highlight_details['fileSizeBytes'] self.widgets['size'].setText(utils.get_appropriate_size(size_in_bytes)) self.widgets['played_as'].setText( highlight_details.get('played_as', 'Not available')) self.widgets['game_mode'].setText( highlight_details.get('game_mode', 'Not available')) win_condition = highlight_details.get('win') if win_condition is None: outcome = 'Not available' elif win_condition: outcome = 'Won' else: outcome = 'Lost' self.widgets['win'].setText(outcome) self.set_button('gfycat', highlight_details['gfycat']) self.set_button('streamable', highlight_details['streamable']) self.set_button('gfycat_alternate', '')
def process_status(self, status): self.preferences = DataStore.get_preferences() is_first_time = self.preferences['first_time'] if status == 'not_running': if is_first_time and not self.notification_shown: msg = 'The League of Legends Client is not running.' self.show_notification(msg) self.window.status.showMessage(msg) self.notification_shown = True elif status == 'running' and not self.ws_is_running: self.websocket_thread = ws.WebSocketThread() self.websocket_thread.start() self.websocket_thread.api_event.connect(self.handle_api_events) self.threads.append(self.websocket_thread) self.ws_is_running = True self.setup_thread = setup_thread.Thread(is_first_time) self.setup_thread.start() self.setup_thread.done_setup.connect(self.window.init_UI) self.setup_thread.done_setup.connect(self.get_match_details) self.setup_thread.login_status.connect( self.window.status.showMessage) self.threads.append(self.setup_thread)
def run(self): self.running = True self.is_paused = False self.skip = False while self.running: try: highlight_name, platform = self.q.get(timeout=1) while self.is_paused: time.sleep(1) if self.skip: break highlight = DataStore.get_highlight(highlight_name) file_path = highlight['filepath'] if platform == 'gfycat': video_url = gfycat.upload(file_path) elif platform == 'streamable': video_url = streamable.upload(file_path) self.uploaded.emit((highlight_name, video_url)) except queue.Empty: continue
def upload(file_path): """Uploads a video to gfycat Args: file_path (string): Path to the video to be uploaded. Returns: A string representing the url to the uploaded video. """ filename = utils.get_filename(file_path) body = { 'title': filename, 'tags': ['leagueoflegends', 'League of Legends'], 'noMd5': True } token = DataStore.get_gfycat_token() auth_header = {'Authorization': f'Bearer {token}'} url = f'{BASE_URL}/gfycats' response = requests.post(url, json=body, headers=auth_header) gfyname = response.json()['gfyname'] upload_url = f'https://filedrop.gfycat.com/{gfyname}' with open(file_path, 'rb') as video: response = requests.put(upload_url, video) video_url = f'https://gfycat.com/{gfyname}' return video_url
def upload(file_path): """Upload a file to Streamable.com Args: file_path (string): Path to the video to be uploaded. Returns: A string that represents the url to the uploaded video """ with open(file_path, 'rb') as file: filename = utils.get_filename(file_path) content = {'file': (filename, file)} auth = DataStore.get_streamable_secrets() headers = { 'user-agent': 'lol-highlights-enhancer/1.0.0 ([email protected])', 'Authorization': f'Basic {auth}' } api_url = 'https://api.streamable.com/upload' response = requests.post(api_url, files=content, headers=headers) shortcode = response.json()['shortcode'] video_url = f'https://streamable.com/{shortcode}' return video_url
def get_match_details(self): processor_thread = process_highlights.Thread( DataStore.get_highlights()) processor_thread.start() processor_thread.status.connect(self.window.status.showMessage) processor_thread.done_status.connect(self.window.refresh) self.threads.append(processor_thread)
def run(self): self.running = True while self.running: login_status = network.get('/lol-summoner/v1/current-summoner') if login_status.get('httpStatus') is not None: self.login_status.emit( 'Not logged in. Please Log in to the client') time.sleep(2) continue else: self.login_status.emit('Logged in.') if self.is_first_time: DataStore.setup() self.done_setup.emit() self.running = False
def handle_new_highlights(self, highlights): DataStore.refresh_highlights() upload_preferences = DataStore.get_preference('upload_new_highlights') new_highlights = {} for highlight_name in highlights: new_highlights[highlight_name] = DataStore.get_highlight( highlight_name) if upload_preferences['gfycat']: self.queue.put((highlight_name, 'gfycat')) if upload_preferences['streamable']: self.queue.put((highlight_name, 'streamable')) processor_thread = process_highlights.Thread(new_highlights) processor_thread.start() processor_thread.status.connect(self.window.status.showMessage) processor_thread.done_status.connect(self.window.refresh) self.threads.append(processor_thread)
def refresh(self): self.highlights_list.clear() self.highlights_list.addItems(DataStore.get_highlight_names()) self.highlights_list.sortItems(QtCore.Qt.DescendingOrder) if self.selected is not None: items = self.highlights_list.findItems(self.selected, QtCore.Qt.MatchExactly) if items: for item in items: self.item_clicked(item)
def init_UI(self): hbox = QtWidgets.QHBoxLayout() self.highlights_list = QtWidgets.QListWidget() self.highlights_list.addItems(DataStore.get_highlight_names()) self.highlights_list.sortItems(QtCore.Qt.DescendingOrder) self.highlights_list.itemClicked.connect(self.item_clicked) hbox.addWidget(self.highlights_list) hbox.addLayout(self.setup_details_layout(), 1) self.centralWidget().setLayout(hbox)
def run(self): token, port = DataStore.get_connection_details() time.sleep(5) self.ws = websocket.WebSocketApp( f"wss://127.0.0.1:{port}/", header={'Authorization': network.get_auth_header(token)}, on_open=self.on_open, on_message=self.on_message, on_error=self.on_error, on_close=self.on_close) self.ws.run_forever( sslopt={'cert_reqs': ssl.CERT_NONE}, suppress_origin=True)
def handle_buttons(self, service, highlight_name): highlight = DataStore.get_highlight(highlight_name) if service != 'gfycat_alternate': url = highlight[service] if url is None: self.window.status.showMessage( f'Added {highlight_name} to upload queue') self.queue.put((highlight_name, service)) else: webbrowser.open(url, new=2) else: url = highlight['gfycat'] gfyname = utils.get_filename(url) webbrowser.open(f'https://giant.gfycat.com/{gfyname}.mp4', new=2)
def init_settings(self): preferences = DataStore.get_preferences() gfycat_action = QtWidgets.QAction('Gfycat', self, checkable=True) gfycat_action.setChecked( preferences['upload_new_highlights']['gfycat']) gfycat_action.triggered.connect(self.gfyat_setting_changed) streamable_action = QtWidgets.QAction('Streamable', self, checkable=True) streamable_action.setChecked( preferences['upload_new_highlights']['streamable']) streamable_action.triggered.connect(self.streamable_setting_changed) upload_menu = QtWidgets.QMenu('Upload new highlights', self) upload_menu.addAction(gfycat_action) upload_menu.addAction(streamable_action) self.settings_menu.addMenu(upload_menu)
def init(self): self.setToolTip('Lol-highlights-enhancer') self.activated.connect(self.icon_activated) self.checker_thread = league.ProcessCheckerThread() self.checker_thread.start() self.checker_thread.status.connect(self.process_status) self.threads.append(self.checker_thread) self.setup_thread_pool() self.setup_context_menu() self.window = window.MainWindow() self.window.show() self.window.closing_event.connect(self.handle_exit) self.window.action.connect(self.handle_buttons) self.window.minimise.connect(self.hide_window) self.preferences = DataStore.get_preferences() is_first_time = self.preferences['first_time'] if not is_first_time: self.window.init_UI()
def streamable_setting_changed(self, state): preference = DataStore.get_preference('upload_new_highlights') preference['streamable'] = state DataStore.save_preference('upload_new_highlights', preference)
def gfyat_setting_changed(self, state): preference = DataStore.get_preference('upload_new_highlights') preference['gfycat'] = state DataStore.save_preference('upload_new_highlights', preference)