def play(url, name, iconimage=None, ref=None, site=None): xbmc.executebuiltin("ActivateWindow(busydialog)") if not site: if 'site=' in url: url, site = url.split('site=') else: site = 'Unknown' if not name: name = 'Unknown' if not iconimage: iconimage = kodi.addonicon name = re.sub(r'(\[.+?\])', '', name) name = name.lstrip() if '] - ' in name: name = name.split('] - ')[-1] chatur = False if ref: if 'chaturbate.com' in ref: chatur = True else: ref = '' if 'chaturbate.com' in url: chatur = True ref = url url = adultresolver.resolve(url) if (not isinstance(url, str)): url = multilinkselector(url) history_on_off = kodi.get_setting("history_setting") if history_on_off == "true": web_checks = ['http:', 'https:', 'rtmp:'] locak_checks = ['.mp4'] if any(f for f in web_checks if f in url): site = site.title() elif any(f for f in locak_checks if f in url): site = 'Local File' else: site = 'Unknown' if chatur: history.delEntry(ref) history.addHistory(name, ref, site.title(), iconimage) else: history.delEntry(url) history.addHistory(name, url, site.title(), iconimage) if 'chaturbate.com' in ref: if kodi.get_setting("mobile_mode") == 'true': url = url.replace('_fast_aac', '_aac') else: bandwidth = kodi.get_setting("chaturbate_band") if bandwidth == '0': url = url.replace('_fast_aac', '_aac') elif bandwidth == '2': choice = kodi.dialog.select( "[COLOR white][B]" + name + "[/B][/COLOR]", [ '[COLOR white]Play High Bandwidth Stream[/COLOR]', '[COLOR white]Play Low Bandwidth Stream[/COLOR]' ]) if choice == 1: url = url.replace('_fast_aac', '_aac') elif choice == 0: pass else: quit() liz = xbmcgui.ListItem(name, iconImage=iconimage, thumbnailImage=iconimage) xbmc.executebuiltin("Dialog.Close(busydialog)") xbmc.Player().play(url, liz, False) if kodi.get_setting("chaturbate_subject") == "true": sleeper = kodi.get_setting("chaturbate_subject_refresh") i = 0 while not xbmc.Player().isPlayingVideo(): time.sleep(1) i += 1 if i == 30: quit() while xbmc.Player().isPlayingVideo(): try: r = client.request(ref) subject = re.compile( 'default_subject:\s\"([^,]+)",').findall(r)[0] subject = urllib.unquote_plus(subject) kodi.notify(msg=subject, duration=8500, sound=True, icon_path=iconimage) except: pass time.sleep(int(sleeper)) else: import urlresolver if urlresolver.HostedMediaFile(url).valid_url(): try: url = urlresolver.HostedMediaFile(url).resolve() except: kodi.notify(msg='Failed to play link.', duration=4000, sound=True) quit() liz = xbmcgui.ListItem(name, iconImage=iconimage, thumbnailImage=iconimage) xbmc.executebuiltin("Dialog.Close(busydialog)") xbmc.Player().play(url, liz, False)
def bubblesort_run(speed, length, replay): global heightList_orginal, heightList, xList, w, listLength, titleHeight, maxHeight, spacing, numOfSwaps, runTime, swap, runSpeed, sort_done # Change accordance to length and speed input listLength = length w = (window_size[0] - spacing * 2) // listLength spacing = (window_size[0] - w * listLength) // 2 numOfSwaps = 0 runSpeed = speed if replay: # Get previous heightList heightList = heightList_orginal.copy() else: # Reset variables xList = [] heightList = [] # Creating all the random numbers for i in range(listLength): heightList.append(randint(10, maxHeight)) xList.append(spacing + w * i) heightList_orginal = heightList.copy() # Start sort # animate_fadein() # Start timing runTime = time.time() # Algorithm for i in range(listLength - 1, -1, -1): for j in range(i): draw() # Draw fundamental bars first if swap: rect_draw(green, xList[j], maxHeight + titleHeight - heightList[j], w, heightList[j]) swap = False else: rect_draw(red, xList[j], maxHeight + titleHeight - heightList[j], w, heightList[j]) update_draw() if heightList[j] > heightList[j + 1]: heightList[j], heightList[j + 1] = heightList[j + 1], heightList[j] swap = True numOfSwaps += 1 # Play sound Note(heightList[j] * 5 + 400).play(1) if btn_click(): return True # Sort ended # Get total runTime runTime = time.time() - runTime sort_done = True draw() update_draw() if btn_click(): return True # Print sorted list to console print(heightList) print("Swaps: {}".format(numOfSwaps)) print(runTime) # Save to history addHistory("bubblesort", length, speed, runTime, numOfSwaps) # Ending animation # green going up for i in range(listLength): draw() rect_draw(green, xList[i], maxHeight + titleHeight - heightList[i], w, heightList[i]) # Play sound Note(heightList[i] * 5 + 400).play(1) update_draw() if btn_click(): return True # green going down for i in range(listLength - 1, -1, -1): draw() rect_draw(green, xList[i], maxHeight + titleHeight - heightList[i], w, heightList[i]) # Play sound Note(heightList[i] * 5 + 400).play(1) update_draw() if btn_click(): return True # Drawn replay_btn draw() window.blit(replay_btn, (791, 454)) update_draw() while True: action = click_action(True) if action == 'back' or action == 'end': return True
def quicksort_run(speed, length, replay): global heightList_orginal, heightList, xList, w, listLength, titleHeight, maxHeight, spacing, runSpeed, numOfSwaps, runTime, swap, backSelected_drawn, backBtn_click, window_size, event, sort_done # Change accordance to length and speed input listLength = length runSpeed = speed w = (window_size[0] - spacing * 2) // listLength spacing = (window_size[0] - w * listLength) // 2 numOfSwaps = 0 backBtn_click = False if replay: # Get previous heightList heightList = heightList_orginal.copy() print(heightList_orginal) else: # Reset variables xList = [] heightList = [] # Creating all the random numbers for i in range(listLength): heightList.append(randint(10, maxHeight)) xList.append(spacing + w * i) heightList_orginal = heightList.copy() print(heightList_orginal) # Start sort # Start timing runTime = time.time() # Algorithm def quickSort(heightList): global backBtn_click if backBtn_click: return True quickSortHelper(heightList, 0, len(heightList) - 1) def quickSortHelper(heightList, first, last): global backBtn_click if backBtn_click: return True if first < last: #Its going to Partiition splitpoint = partition(heightList, first, last) #Basically, per iteration you are running it split into 2. So it does it for the #beofre and after the Partition quickSortHelper(heightList, first, splitpoint - 1) quickSortHelper(heightList, splitpoint + 1, last) def partition(heightList, first, last): global backBtn_click, numOfSwaps, event if backBtn_click: return True #set a pivot value, in our case at the start pivotvalue = heightList[first] pivotindex = first #ensure that the border when swapping heightListound stuff, is right of the border = first + 1 end = last isCompleted = False swap = False while not isCompleted: draw() rect_draw(blue, xList[pivotindex], maxHeight + titleHeight - heightList[pivotindex], w, heightList[pivotindex]) if swap: rect_draw(green, xList[border], maxHeight + titleHeight - heightList[border], w, heightList[border]) rect_draw(green, xList[end], maxHeight + titleHeight - heightList[end], w, heightList[end]) swap = False # Play sound Note(heightList[border] * 5 + 400).play(1) update_draw() btn_click() if backBtn_click: return True #Basically this is once everythin is sorted and checks if its more while border <= end and heightList[border] <= pivotvalue: border = border + 1 #Same thing as above but opposite and in this cfase its less while heightList[end] >= pivotvalue and end >= border: end = end - 1 #this is bascially once everything after the border, which in the end gos to the end, is smaller if end < border: isCompleted = True #if not it swaps else: #Before swaps rect_draw(red, xList[border], maxHeight + titleHeight - heightList[border], w, heightList[border]) rect_draw(red, xList[end], maxHeight + titleHeight - heightList[end], w, heightList[end]) update_draw() # Play sound Note(heightList[border] * 5 + 400).play(1) btn_click() if backBtn_click: return True heightList[border], heightList[end] = heightList[ end], heightList[border] #After swaps draw() rect_draw(blue, xList[pivotindex], maxHeight + titleHeight - heightList[pivotindex], w, heightList[pivotindex]) rect_draw(green, xList[border], maxHeight + titleHeight - heightList[border], w, heightList[border]) rect_draw(green, xList[end], maxHeight + titleHeight - heightList[end], w, heightList[end]) update_draw() # Play sound Note(heightList[border] * 5 + 400).play(1) btn_click() if backBtn_click: return True numOfSwaps += 1 #it swaps again rect_draw(red, xList[first], maxHeight + titleHeight - heightList[first], w, heightList[first]) rect_draw(red, xList[end], maxHeight + titleHeight - heightList[end], w, heightList[end]) update_draw() # Play sound Note(heightList[first] * 5 + 400).play(1) btn_click() if backBtn_click: return True heightList[first], heightList[end] = heightList[end], heightList[first] draw() rect_draw(blue, xList[pivotindex], maxHeight + titleHeight - heightList[pivotindex], w, heightList[pivotindex]) rect_draw(green, xList[first], maxHeight + titleHeight - heightList[first], w, heightList[first]) rect_draw(green, xList[end], maxHeight + titleHeight - heightList[end], w, heightList[end]) update_draw() # Play sound Note(heightList[first] * 5 + 400).play(1) btn_click() if backBtn_click: return True numOfSwaps += 1 return end quickSort(heightList) #Sort Ended # Get total runTime runTime = time.time() - runTime sort_done = True #Show results print(heightList) # Last animation draw() update_draw() btn_click() if backBtn_click: return True # Save to history addHistory("quicksort", length, speed, runTime, numOfSwaps) # Ending animation runSpeed = 400.0 # green going up for i in range(listLength): draw() rect_draw(green, xList[i], maxHeight + titleHeight - heightList[i], w, heightList[i]) # Play sound Note(heightList[i] * 5 + 400).play(1) update_draw() if btn_click(): return True # green going down for i in range(listLength - 1, -1, -1): draw() rect_draw(green, xList[i], maxHeight + titleHeight - heightList[i], w, heightList[i]) # Play sound Note(heightList[i] * 5 + 400).play(1) update_draw() if btn_click(): return True # Drawn replay_btn draw() window.blit(replay_btn, (791, 454)) update_draw() while True: action = click_action(True) if action == 'back' or action == 'end': return True
def radixsort_run(speed, length, replay): global heightList_orginal, heightList, xList, w, listLength, titleHeight, maxHeight, spacing, numOfSwaps, runTime, swap, runSpeed, sort_done # Change accordance to length and speed input listLength = length runSpeed = speed w = (window_size[0] - spacing * 2) // listLength spacing = (window_size[0] - w * listLength) // 2 numOfSwaps = 0 if replay: # Get previous heightList heightList = heightList_orginal.copy() print(heightList_orginal) else: # Reset variables xList = [] heightList = [] # Creating all the random numbers for i in range(listLength): heightList.append((i + 1) * maxHeight // length) xList.append(spacing + w * i) shuffle(heightList) heightList_orginal = heightList.copy() print(heightList_orginal) # Start sort # Start timing runTime = time.time() draw() update_draw() if btn_click(): return True # Algorithm radixList = [[ int(heightList[x] / 100), int(heightList[x] % 100 / 10), heightList[x] % 10 ] for x in range(length)] for m in range(-1, -4, -1): hSort = [[] for x in range(10)] rSort = [[] for x in range(10)] for c in range(length): draw() rect_draw(green, xList[c], maxHeight + titleHeight - heightList[c], w, heightList[c]) update_draw() # Play sound Note(heightList[c] * 5 + 400).play(1) if btn_click(): return True for i in range(10): if radixList[c][m] == i: hSort[i] += [heightList[c]] rSort[i] += [radixList[c]] for i in range(9, -1, -1): for j in range(len(hSort[i])): if hSort[i] != []: numOfSwaps += 1 draw() for y in [ d for d, x in enumerate(heightList) if x == hSort[i][-1] ]: rect_draw(red, xList[y], maxHeight + titleHeight - heightList[y], w, heightList[y]) # Play sound Note(heightList[y] * 5 + 400).play(1) update_draw() if btn_click(): return True for t in range(int(400 / speed)): time.sleep(0.0005) print(i) print(hSort) heightList.remove(hSort[i][-1]) heightList = [hSort[i][-1]] + heightList hSort[i].remove(hSort[i][-1]) radixList.remove(rSort[i][-1]) radixList = [rSort[i][-1]] + radixList rSort[i].remove(rSort[i][-1]) draw() rect_draw(red, xList[0], maxHeight + titleHeight - heightList[0], w, heightList[0]) update_draw() # Play sound Note(heightList[0] * 5 + 400).play(1) if btn_click(): return True for t in range(int(400 / speed)): time.sleep(0.0005) draw() # Sort ended # Get total runTime runTime = time.time() - runTime sort_done = True # Print sorted list to console print(heightList) print("Swaps: {}".format(numOfSwaps)) print(runTime) # Save to history addHistory("radixsort", length, speed, runTime, numOfSwaps) # Ending animation runSpeed = 400.0 # green going up for i in range(listLength): draw() rect_draw(green, xList[i], maxHeight + titleHeight - heightList[i], w, heightList[i]) # Play sound Note(heightList[i] * 5 + 400).play(1) update_draw() if btn_click(): return True # green going down for i in range(listLength - 1, -1, -1): draw() rect_draw(green, xList[i], maxHeight + titleHeight - heightList[i], w, heightList[i]) # Play sound Note(heightList[i] * 5 + 400).play(1) update_draw() if btn_click(): return True # Drawn replay_btn draw() window.blit(replay_btn, (791, 454)) update_draw() while True: action = click_action(True) if action == 'back' or action == 'end': return True
def mergesort_run(speed, length, replay): global heightList_orginal, heightList, xList, w, listLength, titleHeight, maxHeight, spacing, runSpeed, numOfSwaps, runTime, backBtn_click, swap, backSelected_drawn, window_size, event, sort_done # Change accordance to length and speed input listLength = length runSpeed = speed w = (window_size[0]-spacing*2)//listLength spacing = (window_size[0]-w*listLength)//2 numOfSwaps = 0 backBtn_click = False if replay: # Get previous heightList heightList = heightList_orginal.copy() print(heightList_orginal) else: # Reset variables xList = [] heightList = [] # Creating all the random numbers for i in range(listLength): heightList.append(randint(10, maxHeight)) xList.append(spacing + w*i) heightList_orginal = heightList.copy() print(heightList_orginal) # Start sort # Start timing runTime = time.time() # Algorithm def mergesort_algo(arrList, start, end): global backBtn_click if backBtn_click: return True n = int(len(arrList)) if (n <= 1): return arrList m = int(n//2) first = arrList[:m] second = arrList[m:] # print('---------') # print(first, second) mergesort_algo(first, start, m+start-1) mergesort_algo(second, m+start, end) heightList_before = heightList.copy() # print(heightList_before) i, j, k = 0, 0, 0 while i < len(first) and j < len(second): if first[i] < second[j]: arrList[k] = first[i] i += 1 else: arrList[k] = second[j] j += 1 k += 1 while i < len(first): arrList[k] = first[i] i += 1 k += 1 while j < len(second): arrList[k] = second[j] j += 1 k += 1 if heightList == arrList: return heightList_before draw(arrList, start, end) if backBtn_click: return True # Run sort heightList_before = mergesort_algo(heightList, 0, listLength-1) # Sort ended # Get total runTime runTime = time.time() - runTime sort_done = True # Completed List heightList, heightList_After = heightList_before.copy(), heightList.copy() draw(heightList_After, 0, listLength-1) if backBtn_click: return True # Show results print(heightList) # Save to history addHistory("mergesort", length, speed, runTime, numOfSwaps) # Ending animation runSpeed = 400.0 # green going up for i in range(listLength): drawPage() rect_draw(green, xList[i], maxHeight + titleHeight-heightList[i], w, heightList[i]) # Play sound Note(heightList[i]*5+400).play(1) update_draw() if btn_click(): return True # green going down for i in range(listLength-1, -1, -1): drawPage() rect_draw(green, xList[i], maxHeight + titleHeight-heightList[i], w, heightList[i]) # Play sound Note(heightList[i]*5+400).play(1) update_draw() if btn_click(): return True # Drawn replay_btn drawPage() window.blit(replay_btn, (791, 454)) update_draw() while True: action = click_action(True) if action == 'back' or action == 'end': return True if action == 'next': drawPage() update_draw()