def generate_pairing_code(): monitor = Monitor() progress = DialogProgress() progress.create(get_string(32000), get_string(32001)) chromecast = YoutubeCastV1() pairing_code = chromecast.pair() i = 0 if PY3: progress.update(i, message="{} {}".format(get_string(32002), pairing_code)) else: progress.update(i, get_string(32002), pairing_code) start_time = time.time() while not monitor.abortRequested( ) and not chromecast.has_client and not progress.iscanceled() and not ( time.time() - start_time) > (60 * 1): i += 10 if i > 100: i = 0 if PY3: progress.update(i, message="{} {}".format(get_string(32002), pairing_code)) else: progress.update(i, get_string(32002), pairing_code) monitor.waitForAbort(2) progress.close()
def login(plugin): method = Dialog().yesno("Login", "Select Login Method", yeslabel="Keyboard", nolabel="WEB") if method == 1: login_type = Dialog().yesno("Login", "Select Login Type", yeslabel="OTP", nolabel="Password") if login_type == 1: mobile = keyboard("Enter your Jio mobile number") error = sendOTP(mobile) if error: Script.notify("Login Error", error) return otp = keyboard("Enter OTP", hidden=True) ULogin(mobile, otp, mode="otp") elif login_type == 0: username = keyboard("Enter your Jio mobile number or email") password = keyboard("Enter your password", hidden=True) ULogin(username, password) elif method == 0: pDialog = DialogProgress() pDialog.create( 'JioTV', 'Visit [B]http://%s:48996/[/B] to login' % socket.gethostbyname(socket.gethostname())) for i in range(120): sleep(1) with PersistentDict("headers") as db: headers = db.get("headers") if headers or pDialog.iscanceled(): break pDialog.update(i) pDialog.close()
def wait_for_metadata(info_hash): close_busy_dialog() percent = 0 timeout = get_metadata_timeout() start_time = time.time() monitor = Monitor() progress = DialogProgress() progress.create(ADDON_NAME, translate(30237)) try: while not api.torrent_status(info_hash).has_metadata: if monitor.waitForAbort(0.5): raise PlayError("Abort requested") passed_time = time.time() - start_time if 0 < timeout: if timeout < passed_time: notification(translate(30238)) raise PlayError("No metadata after timeout") percent = int(100 * passed_time / timeout) else: percent = 0 if percent == 100 else (percent + 5) progress.update(percent) if progress.iscanceled(): raise CanceledError("User canceled metadata", info_hash) finally: progress.close()
def _http_download(self, url, message=None): """Makes HTTP request and displays a progress dialog on download.""" req = self._http_request(url) if req is None: return None filename = url.split('/')[-1] if not message: # display "downloading [filename]" message = localize(30015, filename=filename) # Downloading file self._download_path = os.path.join(self._temp_path(), filename) total_length = float(req.info().get('content-length')) progress_dialog = DialogProgress() progress_dialog.create(localize(30014), message) # Download in progress chunk_size = 32 * 1024 with open(self._download_path, 'wb') as image: size = 0 while True: chunk = req.read(chunk_size) if not chunk: break image.write(chunk) size += len(chunk) percent = int(size * 100 / total_length) if progress_dialog.iscanceled(): progress_dialog.close() req.close() return False progress_dialog.update(percent) progress_dialog.close() return True
def login(plugin): pdialog = DialogProgress() pdialog.create("Login", "1. Go to [B]hotstar.com/in/activate[/B]", line2="2. Login with your hotstar account[CR]3. Enter the 4 digit code", line3="Loading...") for code, i in api.doLogin(): if pdialog.iscanceled() or i == 100: break else: time.sleep(1) pdialog.update(i, line3="[B][UPPERCASE]%s[/UPPERCASE][/B]" % code) pdialog.close()
def login(plugin): msg = "1. Go to [B]https://tv.hotstar.com[/B]\n2. Login with your hotstar account[CR]3. Enter the 4 digit code : " pdialog = DialogProgress() pdialog.create("Login", msg + "Loading...") for code, i in api.doLogin(): if pdialog.iscanceled() or i == 100: break else: time.sleep(1) pdialog.update(i, msg + "[B][UPPERCASE]%s[/UPPERCASE][/B]" % code) pdialog.close()
def play_info_hash(info_hash, timeout=30, buffer=True): start_time = time.time() monitor = Monitor() progress = DialogProgress() progress.create(ADDON_NAME, translate(30237)) try: while not api.torrent_status(info_hash).has_metadata: if monitor.waitForAbort(0.5): raise PlayError("Abort requested") passed_time = time.time() - start_time if 0 < timeout < passed_time: notification(translate(30238)) raise PlayError("No metadata after timeout") progress.update(int(100 * passed_time / timeout)) if progress.iscanceled(): raise PlayError("User canceled metadata") finally: progress.close() files = api.files(info_hash, status=False) min_candidate_size = get_min_candidate_size() * 1024 * 1024 candidate_files = [ f for f in files if is_video(f.path) and f.length >= min_candidate_size ] if not candidate_files: notification(translate(30239)) raise PlayError("No candidate files found for {}".format(info_hash)) elif len(candidate_files) == 1: chosen_file = candidate_files[0] else: sort_files(candidate_files) chosen_index = Dialog().select(translate(30240), [f.name for f in candidate_files]) if chosen_index < 0: raise PlayError("User canceled dialog select") chosen_file = candidate_files[chosen_index] if buffer: buffer_and_play(info_hash, chosen_file.id) else: play(info_hash, chosen_file.id)
def buffer_and_play(info_hash, file_id): api.download_file(info_hash, file_id, buffer=True) monitor = Monitor() progress = DialogProgress() progress.create(ADDON_NAME) try: timeout = get_buffering_timeout() start_time = time.time() last_time = 0 last_done = 0 while True: current_time = time.time() status = api.file_status(info_hash, file_id) if status.buffering_progress >= 100: break total_done = status.buffering_total * status.buffering_progress / 100 speed = float(total_done - last_done) / (current_time - last_time) last_time = current_time last_done = total_done progress.update( int(status.buffering_progress), "{} - {:.2f}%\n{} {} {} - {}/s\n\n".format( get_state_string(status.state), status.buffering_progress, sizeof_fmt(total_done), translate(30244), sizeof_fmt(status.buffering_total), sizeof_fmt(speed))) if progress.iscanceled(): raise PlayError("User canceled buffering") if 0 < timeout < current_time - start_time: notification(translate(30236)) raise PlayError("Buffering timeout reached") if monitor.waitForAbort(1): raise PlayError("Abort requested") finally: progress.close() play(info_hash, file_id)
def wait_for_buffering_completion(info_hash, file_id): close_busy_dialog() info = api.file_info(info_hash, file_id) of = translate(30244) timeout = get_buffering_timeout() last_time = last_done = 0 start_time = time.time() monitor = Monitor() progress = DialogProgress() progress.create(ADDON_NAME) try: while True: current_time = time.time() status = api.file_status(info_hash, file_id) if status.buffering_progress >= 100: break total_done = status.buffering_total * status.buffering_progress / 100 speed = float(total_done - last_done) / (current_time - last_time) last_time = current_time last_done = total_done progress.update( int(status.buffering_progress), "{} - {:.2f}%\n{} {} {} - {}/s\n{}\n".format( get_state_string(status.state), status.buffering_progress, sizeof_fmt(total_done), of, sizeof_fmt(status.buffering_total), sizeof_fmt(speed), info.name)) if progress.iscanceled(): raise CanceledError("User canceled buffering", info_hash) if 0 < timeout < current_time - start_time: notification(translate(30236)) raise PlayError("Buffering timeout reached") if monitor.waitForAbort(1): raise PlayError("Abort requested") finally: progress.close()
def login(plugin): isKeyboard = Dialog().yesno("Login", "Select Login Type", yeslabel="Keyboard", nolabel="WEB") if isKeyboard: username = keyboard("Enter your Jio mobile number or email") password = keyboard("Enter your password", hidden=True) ULogin(username, password) else: pDialog = DialogProgress() pDialog.create( 'JioTV', 'Visit [B]http://%s:48996/web/login[/B] to login' % socket.gethostbyname(socket.gethostname())) for i in range(120): sleep(1) with PersistentDict("headers") as db: headers = db.get("headers") if headers or pDialog.iscanceled(): break pDialog.update(i) pDialog.close()