def run(self): try: self.worker_result = self.worker_fun(self.ctrl_obj, *self.worker_fun_args) except Exception as e: printError("worker thread", "run", str(e)) self.stop()
def getConfigSerialPort(self, notify, output): if config.cur_serial_port == -1: misc.printError(None, output, \ _("Serial port not configured!\nUse Tools->Serial Port to configure port.")) return -1 else: return config.cur_serial_port
def getConfigSerialPort(self, notify, output): if config.cur_serial_port == -1: misc.printError(None, output, \ _("Serial port not configured!\nUse Tools->Serial Port to configure port.")) return -1 else: return config.cur_serial_port
def load_utxos_thread(self, ctrl): with self.Lock: # clear rewards DB printDbg("Updating rewards...") self.caller.parent.db.clearTable('REWARDS') self.caller.parent.db.clearTable('MY_VOTES') # If rpc is not connected and hw device is Ledger, warn and return. if not self.caller.rpcConnected and self.caller.hwModel == 0: printError(getCallerName(), getFunctionName(), 'PIVX daemon not connected - Unable to update UTXO list') return total_num_of_utxos = 0 mn_rewards = {} for mn in self.caller.masternode_list: # Load UTXOs from API client rewards = self.caller.apiClient.getAddressUtxos(mn['collateral'].get('address')) if rewards is None: printError(getCallerName(), getFunctionName(), 'API client not responding.') return mn_rewards[mn['name']] = rewards total_num_of_utxos += len(rewards) printDbg("Number of UTXOs to load: %d" % total_num_of_utxos) curr_utxo = 0 for mn in mn_rewards: for utxo in mn_rewards[mn]: # Add mn_name to UTXO utxo['mn_name'] = mn # Get raw tx rawtx = TxCache(self.caller)[utxo['txid']] if rawtx is None: printDbg("Unable to get raw TX with hash=%s from RPC server." % utxo['txid']) # Don't save UTXO if raw TX is unavailable mn_rewards[mn].remove(utxo) continue utxo['raw_tx'] = rawtx utxo['staker'] = "" p2cs, utxo['coinstake'] = IsPayToColdStaking(rawtx, utxo['vout']) if p2cs: utxo['staker'] = GetDelegatedStaker(rawtx, utxo['vout'], self.caller.isTestnetRPC) # Add utxo to database self.caller.parent.db.addReward(utxo) # emit percent percent = int(100 * curr_utxo / total_num_of_utxos) self.caller.sig_UTXOsLoading.emit(percent) curr_utxo += 1 printDbg("--# REWARDS table updated") self.caller.sig_UTXOsLoading.emit(100)
def load_utxos_thread(self, ctrl): with self.Lock: # clear utxos DB printDbg("Updating UTXOs...") self.caller.parent.db.clearTable('UTXOS') self.utxoLoaded = False if not self.caller.rpcConnected: printError( getCallerName(), getFunctionName(), 'PIVX daemon not connected - Unable to update UTXO list') return utxos = self.caller.apiClient.getAddressUtxos(self.curr_addr) total_num_of_utxos = len(utxos) # Get raw transactions curr_utxo = 0 percent = 0 for u in utxos: percent = int(100 * curr_utxo / total_num_of_utxos) # get raw TX from RPC client (only for ledger / trezor has own api) if self.caller.hwModel == 0: # double check that the rpc connection is still active, else reconnect if self.caller.rpcClient is None: self.caller.updateRPCstatus(None) rawtx = self.caller.rpcClient.getRawTransaction(u['txid']) if rawtx is None: printDbg( "Unable to get raw TX with hash=%s from RPC server." % u['txid']) # Don't save UTXO if raw TX is unavailable continue else: rawtx = "" # Save utxo to db u['receiver'] = self.curr_addr u['raw_tx'] = rawtx u['staker'] = "" p2cs, u['coinstake'] = IsPayToColdStaking(rawtx, u['vout']) if p2cs: u['staker'] = GetDelegatedStaker(rawtx, u['vout'], self.caller.isTestnetRPC) self.caller.parent.db.addReward(u) # emit percent self.caller.sig_UTXOsLoading.emit(percent) curr_utxo += 1 self.caller.sig_UTXOsLoading.emit(100) printDbg("--# REWARDS table updated") self.utxoLoaded = True self.caller.sig_UTXOsLoaded.emit()
def process_api_exceptions_int(*args, **kwargs): client = args[0] try: return func(*args, **kwargs) except Exception as e: message = "Primary API source not responding. Trying secondary" printException(getCallerName(True), getFunctionName(True), message, str(e)) try: client.api = CryptoIDClient(client.isTestnet) return func(*args, **kwargs) except Exception as e: printError(getCallerName(True), getFunctionName(True), str(e)) return None
def load_utxos_thread(self, ctrl): with self.Lock: # clear rewards DB printDbg("Updating rewards...") self.caller.parent.db.clearTable('REWARDS') self.caller.parent.db.clearTable('MY_VOTES') self.utxoLoaded = False # If rpc is not connected and hw device is Ledger, warn and return. if not self.caller.rpcConnected and self.caller.hwModel == 0: printError(getCallerName(), getFunctionName(), 'PIVX daemon not connected - Unable to update UTXO list') return total_num_of_utxos = 0 mn_rewards = {} for mn in self.caller.masternode_list: # Load UTXOs from API client rewards = self.caller.apiClient.getAddressUtxos(mn['collateral'].get('address')) if rewards is None: printError(getCallerName(), getFunctionName(), 'API client not responding.') return mn_rewards[mn['name']] = rewards total_num_of_utxos += len(rewards) printDbg("Number of UTXOs to load: %d" % total_num_of_utxos) curr_utxo = 0 percent = 0 for mn in mn_rewards: # for each UTXO for utxo in mn_rewards[mn]: rawtx = None percent = int(100*curr_utxo / total_num_of_utxos) # get raw TX from RPC client (only for ledger / trezor has own api) if self.caller.hwModel == 0: rawtx = self.caller.rpcClient.getRawTransaction(utxo['txid']) else: rawtx = "" # Don't save UTXO if raw TX is unavailable if rawtx is None: printError(getCallerName(), getFunctionName(), "Unable to get raw TX with hash=%s from RPC server" % utxo['txid']) continue # Add mn_name and raw_tx to UTXO and save it to DB else: utxo['mn_name'] = mn utxo['raw_tx'] = rawtx self.caller.parent.db.addReward(utxo) # emit percent self.caller.sig_UTXOsLoading.emit(percent) curr_utxo += 1 self.caller.sig_UTXOsLoading.emit(100) printDbg("--# REWARDS table updated") self.utxoLoaded = True self.caller.sig_UTXOsLoaded.emit()
def load_utxos_thread(self, ctrl): with self.Lock: # clear utxos DB printDbg("Updating UTXOs...") self.caller.parent.db.clearTable('UTXOS') self.utxoLoaded = False if not self.caller.rpcConnected: printError(getCallerName(), getFunctionName(), 'PIVX daemon not connected - Unable to update UTXO list') return utxos = self.caller.apiClient.getAddressUtxos(self.curr_addr) total_num_of_utxos = len(utxos) # Get raw transactions curr_utxo = 0 percent = 0 for u in utxos: rawtx = None percent = int(100 * curr_utxo / total_num_of_utxos) rawtx = self.caller.rpcClient.getRawTransaction(u['txid']) # break if raw TX is unavailable if rawtx is None: return # Save utxo to db u['receiver'] = self.curr_addr u['raw_tx'] = rawtx self.caller.parent.db.addReward(u) # emit percent self.caller.sig_UTXOsLoading.emit(percent) curr_utxo += 1 self.caller.sig_UTXOsLoading.emit(100) printDbg("--# REWARDS table updated") self.utxoLoaded = True self.caller.sig_UTXOsLoaded.emit()
def load_utxos_thread(self, ctrl): try: if not self.mainTab.caller.rpcClient.getStatus(): printDbg('PIVX daemon not connected') else: try: self.blockCount = self.mainTab.caller.rpcClient.getBlockCount( ) utxos = self.mainTab.caller.apiClient.getAddressUtxos( self.pivx_addr) self.utxos = [ utxo for utxo in utxos if round(int(utxo.get('satoshis', 0)) / 1e8, 8) == 10000.00000000 ] except Exception as e: errorMsg = 'Error occurred while calling getaddressutxos method: ' + str( e) printError(getCallerName(), getFunctionName(), errorMsg) except Exception as e: pass
def load_utxos_thread(self, ctrl): with self.Lock: # clear utxos DB printDbg("Updating UTXOs...") self.caller.parent.db.clearTable('UTXOS') if not self.caller.rpcConnected: printError(getCallerName(), getFunctionName(), 'PIVX daemon not connected - Unable to update UTXO list') return utxos = self.caller.apiClient.getAddressUtxos(self.curr_addr) total_num_of_utxos = len(utxos) curr_utxo = 0 for u in utxos: u['receiver'] = self.curr_addr # Get raw tx u['rawtx'] = TxCache(self.caller)[u['txid']] if u['rawtx'] is None: printDbg("Unable to get raw TX with hash=%s from RPC server." % u['txid']) # Don't save UTXO if raw TX is unavailable utxos.remove(u) u['staker'] = "" p2cs, u['coinstake'] = IsPayToColdStaking(u['rawtx'], u['vout']) if p2cs: u['staker'] = GetDelegatedStaker(u['rawtx'], u['vout'], self.caller.isTestnetRPC) # Save utxo to db self.caller.parent.db.addReward(u) # emit percent percent = int(100 * curr_utxo / total_num_of_utxos) self.caller.sig_UTXOsLoading.emit(percent) curr_utxo += 1 printDbg("--# REWARDS table updated") self.caller.sig_UTXOsLoading.emit(100)
def finish(downloads, keepOld, reDownload, checkDuration, listOnly, convertTo, bashOutFile, verbose): shouldBeDeleted = [] if not listOnly: if downloads: infoDownloaded = getVideos(downloads, keepOld, reDownload, checkDuration, verbose) if convertTo: if verbose: printInfo2("Converting downloads...") convertDownloads(downloads, convertTo, verbose) else: infoDownloaded = "" onError(17, "Could not find any streams to download") else: infoDownloaded = "" printInfo1("\nListing only") printScores() if bashOutFile: if continueWithProcess(bashOutFile, bashSuffix, True, False, "Will redownload\n", "Keeping old file. No download\n", verbose): bashFile = open("%s.%s" % (bashOutFile, bashSuffix), "w") bashFile.write("#!/bin/bash\n\n") if downloads: printInfo1("These files would have been downloaded:") for line in downloads: # print line printInfo1("\nVideo name: %s.%s" % (line['name'].rstrip(), line['suffix'])) printInfo1("Video quality: %s" % line['quality']) printInfo1("Video address: %s" % line['address']) if line['subs']: printInfo1("Subtitles name: %s.srt" % line['name'].rstrip()) printInfo1("Subtitles address: %s" % line['subs']) else: printInfo1("No subtitles found") print "Duration: %s s" % line['duration'] if bashOutFile: if line['address'].startswith("http"): cmd = ffmpegDownloadCommand(line, verbose) bashFile.write("%s\n\n" % cmd) elif line['address'].startswith("rtmp"): cmd = rtmpdumpDownloadCommand(line, verbose) bashFile.write("%s\n\n" % cmd) if line['subs']: cmd = wgetDownloadCommand(line, verbose) bashFile.write("%s\n\n" % cmd) if bashOutFile: bashFile.close() st = os.stat("%s.sh" % bashOutFile) os.chmod("%s.sh" % bashOutFile, st.st_mode | stat.S_IEXEC) else: printWarning("Could not find anything that would have been downloaded") for line in infoDownloaded: printInfo1("\nVideo: %s" % line['videoName']) printScores() if line['expectedDuration'] != "0.000": printInfo1("Expected duration: %s" % (str(datetime.timedelta(seconds=round(float(line['expectedDuration']), 2))))) if verbose: printInfo1("Duration: %s ms" % line['duration']) printInfo1("Duration: %s" % line['durationFormatted']) if line['videoDlComment'] == dlCommentError: printError(line['videoDlComment']) shouldBeDeleted.append(line['videoName']) else: printInfo2(line['videoDlComment']) if verbose: printInfo1("Expected duration: %s s" % line['expectedDuration']) printInfo1("Actual duration: %s s" % line['duration']) if not compareDurations(float(line['expectedDuration']), float(line['duration']) / 1000, verbose): printError("Durations does not match") shouldBeDeleted.append(line['videoName']) if verbose: printInfo1("File size: %s b" % line['fileSize']) printInfo1("File size: %s" % line['fileSizeMeasure']) if verbose: printInfo1("Overall bit rate: %s bps" % line['overallBitRate']) printInfo1("Overall bit rate: %s" % line['overallBitRateMeasure']) print if verbose: printInfo1("Video format: %s" % line['videoFormat']) printInfo1("Video codec ID: %s" % line['videoCodecId']) printInfo1("Video bit rate: %s bps" % line['videoBitRate']) printInfo1("Video bit rate: %s" % line['videoBitRateMeasure']) printInfo1("Width: %s px" % line['width']) printInfo1("Height: %s px" % line['height']) printInfo1("Frame rate: %s fps" % line['frameRate']) if verbose: printInfo1("Frame count: %s" % line['frameCount']) print printInfo1("Audio format: %s" % line['audioFormat']) printInfo1("Audio codec ID: %s" % line['audioCodecId']) printInfo1("Audio bit rate: %s bps" % line['audioBitRate']) printInfo1("Audio bit rate: %s" % line['audioBitRateMeasure']) if line['subLines'] != 'na': printInfo1("\nSubtitles: %s" % line['subName']) printScores() if line['subDlComment'] == dlCommentError: printError(line['subDlComment']) shouldBeDeleted.append(line['subName']) else: printInfo2(line['subDlComment']) if line['expectedSubSize'] != "0": printInfo1("Expected file size: %s B" % line['expectedSubSize']) printInfo1("File size: %s B" % line['subSize']) printInfo1("Number of lines: %s" % line['subLines']) else: printWarning("\nNo subtitles downloaded") if shouldBeDeleted: print printError("\nThese files should be deleted and re downloaded") printScores() for line in shouldBeDeleted: printWarning(line) print
def checkSecondSvtPage(url, verbose): secondTag = "" secondPage = getWebPage(url, verbose) if verbose: printInfo2("Parsing page...") else: sys.stdout.write(".") sys.stdout.flush() soup = BeautifulSoup(secondPage) items = soup.findAll("embed", attrs={'attr' : True}) secondTag = items[0]['attr'] if secondTag: if verbose: printInfo1("Found second tag:") print secondTag printInfo2("Decoding...") else: sys.stdout.write(".") sys.stdout.flush() secondTag = urllib.unquote(secondTag.encode('utf8')).decode('utf8') if verbose: printInfo1("Decoded tag:") print secondTag secondTag = secondTag.split('=', 1)[-1] else: printError("Did not find second tag") if verbose: printInfo2("Converting to json...") else: sys.stdout.write(".") sys.stdout.flush() jsonString = json.loads(secondTag) if verbose: printInfo1("JSON string:") print json.dumps(jsonString['video'], sort_keys=True, indent=2) printInfo2("Extracting video link...") else: sys.stdout.write(".") sys.stdout.flush() videoLink = jsonString['video']['videoReferences'][0]['url'] if verbose: printInfo1("Found video link:") print videoLink else: sys.stdout.write(".") sys.stdout.flush() videos = checkVideoLink(videoLink, verbose) if verbose: printInfo2("Extracting subtitle link...") else: sys.stdout.write(".") sys.stdout.flush() if "url" in jsonString['video']['subtitleReferences'][0]: subtitleLink = jsonString['video']['subtitleReferences'][0]['url'] checkSubtitleLink(subtitleLink, verbose) if verbose: printInfo1("Found subtitle link:") print subtitleLink else: sys.stdout.write(".") sys.stdout.flush() else: if verbose: printWarning("No subtitles found") else: sys.stdout.write(".") sys.stdout.flush() subtitleLink = "" if verbose: printInfo1("Found videos:") for video in videos: print video else: sys.stdout.write(".") sys.stdout.flush() xmlCode = composeXML(videos, subtitleLink, verbose) return xmlCode
def load_utxos_thread(self, ctrl): with self.Lock: self.apiConnected = False # clear rewards DB printDbg("Updating rewards...") self.caller.parent.db.clearTable('REWARDS') self.caller.parent.db.clearTable('MY_VOTES') self.utxoLoaded = False # If rpc is not connected warn and return. if not self.caller.rpcConnected: printError( 'PIVX daemon not connected - Unable to update UTXO list') return api_status = self.caller.apiClient.getStatus() if api_status != 200: printError("Wrong response from API client. Status: %s" % api_status) return self.apiConnected = True total_num_of_utxos = 0 mn_rewards = {} for mn in self.caller.masternode_list: # Load UTXOs from API client rewards = self.caller.apiClient.getAddressUtxos( mn['collateral'].get('address'))['unspent_outputs'] if rewards is None: printError('API client not responding.') return mn_rewards[mn['name']] = rewards total_num_of_utxos += len(rewards) printDbg("Number of UTXOs to load: %d" % total_num_of_utxos) curr_utxo = 0 percent = 0 for mn in mn_rewards: # for each UTXO for utxo in mn_rewards[mn]: percent = int(100 * curr_utxo / total_num_of_utxos) # get raw TX from RPC client rawtx = self.caller.rpcClient.getRawTransaction( utxo['tx_hash']) # Don't save UTXO if raw TX is unavailable if rawtx is None: printError( "Unable to get raw TX with hash=%s from RPC server" % utxo['tx_hash']) continue # Add mn_name and raw_tx to UTXO and save it to DB else: utxo['mn_name'] = mn utxo['raw_tx'] = rawtx self.caller.parent.db.addReward(utxo) # emit percent self.caller.sig_UTXOsLoading.emit(percent) curr_utxo += 1 self.caller.sig_UTXOsLoading.emit(100) printDbg("--# REWARDS table updated") self.utxoLoaded = True self.caller.sig_UTXOsLoaded.emit()