### SCANING AND CONNECT WIFI ADB # import qrcode # qr = qrcode.QRCode(border=1, box_size=10, version=1) # qr.add_data("WIFI:T:ADB;S:ADB_WIFI_songrecproject;P:songrec;;") # qr.print_ascii(invert=True) from subprocess import run as sbprun from time import sleep as time_sleep from _thread import interrupt_main from zeroconf import IPVersion, ServiceBrowser, ServiceStateChange, Zeroconf device_ports = [] def on_service_state_change(zeroconf: Zeroconf,service_type: str,name: str,state_change: ServiceStateChange): if state_change is ServiceStateChange.Added: info = zeroconf.get_service_info(service_type, name) addr = info.parsed_addresses()[0] if service_type == "_adb-tls-pairing._tcp.local.": sbprun(["adb", "pair", f"{addr}:{info.port or 5555}", "songrec"]) sbprun(["adb", "connect", f"{addr}:{device_ports[0]}"]) interrupt_main() elif service_type == "_adb-tls-connect._tcp.local.": device_ports.append(info.port) print(open("qr.txt",encoding='utf-8').read()) zc = Zeroconf(ip_version=IPVersion.V4Only) ServiceBrowser(zc,["_adb-tls-connect._tcp.local.", "_adb-tls-pairing._tcp.local."],[on_service_state_change]) try: while True: time_sleep(0.1) except KeyboardInterrupt: pass zc.close() from pytubefix import Search from os import remove as os_remove from lxml.etree import fromstring as xmlfromstr from ppadb.client import Client as AdbClient from ppadb.device import Device def exist(src,xpath:str): return len(src.xpath(xpath)) > 0 def get_text(src,xpath:str): return src.xpath(xpath)[0].attrib.get("text") time_sleep(1) # for refresing adb client = AdbClient() device:Device = client.devices()[0] wm = device.wm_size() conf = {"start_x":wm.width // 2,"start_y":int(wm.height * 0.9),"end_x":wm.width // 2,"end_y":int(wm.height * 0.2),"duration":1000} resulttrack = '//*[@resource-id="com.google.android.googlequicksearchbox:id/soundsearch_track_name"]' resultartist = '//*[@resource-id="com.google.android.googlequicksearchbox:id/soundsearch_artist"]' def mobile_off(): device.shell("rm /sdcard/ui_layout.xml") os_remove("ui_layout.xml") device.shell("svc power stayon false") device.input_keyevent("SLEEP") def searchmusic(): device.input_keyevent("WAKEUP") device.input_swipe(**conf) device.shell("svc power stayon true") device.shell("am start -a com.google.android.googlequicksearchbox.MUSIC_SEARCH") while True: try: device.shell("uiautomator dump /sdcard/ui_layout.xml") device.pull("/sdcard/ui_layout.xml","ui_layout.xml") ui = xmlfromstr(open("ui_layout.xml", "rb").read()) if exist(ui,'//*[@text="Try again"]') and exist(ui,'//*[@text="Results from Google Search"]'): mobile_off() Search(get_text(ui,resulttrack) +" by "+ get_text(ui,resultartist)).videos[0].streams.filter(only_audio=True).first().download(filename="Temp",mp3=True) sbprun("vlc -f --audio-visual=goom --no-video-title-show --no-qt-fs-controller Temp.mp3") os_remove("Temp.mp3") break elif exist(ui,'//*[@text="Try again"]') and not exist(ui,'//*[@text="Results from Google Search"]'): mobile_off() print("no song found") break time_sleep(4) except KeyboardInterrupt: mobile_off() break except: break while True: searchmusic() if input("Do You Want Search Again ('Enter' for yes/'N' for No)").strip().upper() == "N": client.kill() break