shethjenil commited on
Commit
e20d978
1 Parent(s): 6b7720a

Delete SONG_RECOGNIZER.py

Browse files
Files changed (1) hide show
  1. SONG_RECOGNIZER.py +0 -181
SONG_RECOGNIZER.py DELETED
@@ -1,181 +0,0 @@
1
- # from cv2 import imdecode,IMREAD_GRAYSCALE ,TM_CCOEFF_NORMED , matchTemplate
2
- # from numpy import frombuffer,uint8,where
3
- # from io import BytesIO
4
- # from requests import get
5
- # def find_element_coordinatesofmic():
6
- # template = imdecode(frombuffer(BytesIO(get("https://shethjenil-automatic-song-rec.static.hf.space/voiceelement.jpg").content).read(), uint8), IMREAD_GRAYSCALE)
7
- # screen_image = imdecode(frombuffer(device.screencap(), uint8), IMREAD_GRAYSCALE)
8
- # w, h = template.shape[::-1]
9
- # loc = where(matchTemplate(screen_image, template, TM_CCOEFF_NORMED) >= 0.8)
10
- # return [loc[1][0] + w // 2, loc[0][0] + h // 2]
11
- from os import getenv, path, remove, makedirs
12
- import winshell
13
- import sys
14
- from shutil import copyfile , rmtree
15
-
16
- def add_to_startmenu(target, shortcut_name):
17
- shortcut = winshell.shortcut(path.join(winshell.start_menu(), f"{shortcut_name}.lnk"))
18
- shortcut.path = target
19
- print(shortcut.show_cmd)
20
- shortcut.write()
21
-
22
- def remove_from_startmenu(shortcut_name):
23
- remove(path.join(winshell.start_menu(), f"{shortcut_name}.lnk"))
24
- if len(sys.argv) == 2:
25
- if sys.argv[1] == "--uninstall":
26
- if path.exists(path.join(getenv("LOCALAPPDATA"), "JENILSOFTWARESONGREC")):
27
- rmtree(path.join(getenv("LOCALAPPDATA"), "JENILSOFTWARESONGREC"))
28
- remove_from_startmenu("Song Recognizer")
29
- sys.exit()
30
- if not path.exists(path.join(getenv("LOCALAPPDATA"), "JENILSOFTWARESONGREC")) or (len(sys.argv) == 2 and sys.argv[1] == "--install"):
31
- try:
32
- # Create directory if it doesn't exist
33
- makedirs(path.join(getenv("LOCALAPPDATA"), "JENILSOFTWARESONGREC"))
34
- except OSError as e:
35
- print("Error creating directory:", e)
36
- sys.exit(1)
37
-
38
- try:
39
- # Copy file to the created directory
40
- copyfile(sys.argv[0], path.join(getenv("LOCALAPPDATA"), "JENILSOFTWARESONGREC", sys.argv[0].split("\\")[-1]))
41
- add_to_startmenu(path.join(getenv("LOCALAPPDATA"), "JENILSOFTWARESONGREC", sys.argv[0].split("\\")[-1]), "Song Recognizer")
42
- except IOError as e:
43
- print("Error copying file:", e)
44
- sys.exit(1)
45
-
46
- sys.exit()
47
-
48
-
49
-
50
- from subprocess import Popen , DEVNULL
51
- from time import sleep
52
- from ppadb.client import Client
53
- from os import remove,chdir
54
- from pytube import Search
55
- from xml.etree.ElementTree import parse
56
- from json import dump ,load
57
- from tkinter import messagebox
58
- from tkinter.simpledialog import askstring
59
- chdir(getattr(sys, '_MEIPASS', path.abspath(path.dirname(__file__))))
60
- #change a path to your project folder
61
- try:
62
- messagebox.showinfo(message="this program is made by Vicky,varshil,jeet(leader),preet to dedicating SCIENCE FEST 2024")
63
- messagebox.showinfo(message="in mobile in setting in system build number tap 7 times to open developer options Enable USB debugging and then connect your mobile to pc and tap ok")
64
- Popen(r"data\adb kill-server", shell=True, stdout=DEVNULL, stderr=DEVNULL)
65
- Popen(r"data\adb start-server", shell=True, stdout=DEVNULL, stderr=DEVNULL)
66
- while True:
67
- global device
68
- try:
69
- device = Client(host="127.0.0.1", port=5037).devices()[0]
70
- break
71
- except:
72
- messagebox.showwarning(message="waiting for device")
73
- pass
74
- messagebox.showwarning(message="please unlock and open your mobile during project")
75
- global screentimeout
76
-
77
- while True:
78
- password = askstring("password","enter password")
79
- if password.strip() != "":
80
- if device.shell(f"locksettings clear --old {password}").strip() == "Lock credential cleared":
81
- device.shell(f"#locksettings set-disabled 1")
82
- break
83
- else:
84
- messagebox.showwarning(message="wrong password")
85
- messagebox.showwarning(message="""IF YOU HAVE A PATTERN LOCK THEN ENTER A POINT NUMBER INSTEAD OF PASSWORD LIKE FOR
86
- UPPER LEFT POINT IS 1 AND LAST BOTTOM RIGHT IS 9 MIDDLE POINT IS 5 AND LAST BOTTOM LEFT IS 7""")
87
-
88
- else:
89
- if device.shell("locksettings clear").strip() == "Lock credential cleared":
90
- device.shell(f"#locksettings set-disabled 1")
91
- break
92
- else:
93
- messagebox.showwarning(message="wrong password")
94
- messagebox.showwarning(message="""IF YOU HAVE A PATTERN LOCK THEN ENTER A POINT NUMBER INSTEAD OF PASSWORD LIKE FOR
95
- UPPER LEFT POINT IS 1 AND LAST BOTTOM RIGHT IS 9 MIDDLE POINT IS 5 AND LAST BOTTOM LEFT IS 7""")
96
- device.shell("input keyevent KEYCODE_POWER")
97
- screentimeout=device.shell("settings get system screen_off_timeout")
98
- device.shell("settings put system screen_off_timeout 1800000")
99
- if device.shell(f"ls /sdcard/cfg.json").strip() != "/sdcard/cfg.json":
100
- device.shell("am start -n com.google.android.googlequicksearchbox/com.google.android.apps.search.googleapp.activity.GoogleAppActivity")
101
- device.shell("uiautomator dump")
102
- device.pull("/sdcard/window_dump.xml", "window_dump.xml")
103
- a = [node.attrib['bounds'] for node in parse('window_dump.xml').getroot().iter() if "text" in node.attrib and node.attrib["content-desc"] == "Voice search"][0].split("][")[0].replace("[","").split(",")
104
- mic = [int(a[0]), int(a[1])]
105
- device.input_tap(mic[0], mic[1])
106
- sleep(1)
107
- device.shell("uiautomator dump")
108
- device.pull("/sdcard/window_dump.xml", "window_dump.xml")
109
- a = [node.attrib['bounds'] for node in parse('window_dump.xml').getroot().iter() if "text" in node.attrib and node.attrib["text"] == "Search for a song"][0].split("][")[0].replace("[","").split(",")
110
- songbutton=[int(a[0]), int(a[1])]
111
- dump({"mic": mic, "songbutton": songbutton}, open("cfg.json", "w+"))
112
-
113
- device.push("cfg.json", "/sdcard/cfg.json")
114
- device.shell("am force-stop com.google.android.googlequicksearchbox")
115
- device.shell("rm /sdcard/window_dump.xml")
116
- remove("cfg.json")
117
- remove("window_dump.xml")
118
- else:
119
- device.pull("/sdcard/cfg.json", "cfg.json")
120
- cfg = load(open("cfg.json", "r"))
121
- cfg = load(open("cfg.json", "r"))
122
- mic = cfg["mic"]
123
- songbutton = cfg["songbutton"]
124
-
125
- def get_song_artist():
126
- device.shell("svc data enable")
127
- device.shell("input keyevent KEYCODE_POWER")
128
- global mic , songbutton
129
- device.shell("am start -n com.google.android.googlequicksearchbox/com.google.android.apps.search.googleapp.activity.GoogleAppActivity")
130
- sleep(2)
131
- device.input_tap(mic[0],mic[1]) #mic
132
- device.input_tap(songbutton[0],songbutton[1]) #songbutton
133
- sleep(20)
134
- device.shell("uiautomator dump")
135
- device.pull("/sdcard/window_dump.xml", "window_dump.xml")
136
- song, artist = [node.attrib["text"] for node in parse('window_dump.xml').getroot().iter() if "text" in node.attrib and (text := node.attrib["text"].strip()) != ""][1:3]
137
- remove("window_dump.xml")
138
- device.shell("am force-stop com.google.android.googlequicksearchbox")
139
- device.shell("input keyevent KEYCODE_HOME")
140
- device.shell("svc data disable")
141
- device.shell("input keyevent KEYCODE_POWER")
142
- Popen(rf'data\vlc -f --audio-visual=goom --no-video-title-show --no-qt-fs-controller "{list(filter(lambda x: x.itag == 251, Search(f"{song} by {artist}").results[0].streams))[0].url}"', shell=True, stdout=DEVNULL, stderr=DEVNULL).communicate()
143
- while messagebox.askretrycancel(message="RECORD START"):
144
- get_song_artist()
145
- device.shell("settings put system screen_off_timeout " + screentimeout)
146
- Popen(r"data\adb kill-server", shell=True)
147
- except Exception as e:
148
- device.shell("settings put system screen_off_timeout " + screentimeout)
149
- Popen(r"data\adb kill-server", shell=True)
150
-
151
-
152
-
153
- # C:\Users\Admin\Documents\data>adb shell locksettings
154
- # usage: locksettings set-pattern [--old OLD_CREDENTIAL] NEW_PATTERN
155
- # locksettings set-pin [--old OLD_CREDENTIAL] NEW_PIN
156
- # locksettings set-password [--old OLD_CREDENTIAL] NEW_PASSWORD
157
- # locksettings clear [--old OLD_CREDENTIAL]
158
- # locksettings verify [--old OLD_CREDENTIAL]
159
- # locksettings set-disabled DISABLED
160
- # locksettings get-disabled
161
-
162
- # flags:
163
- # --user USER_ID: specify the user, default value is current user
164
-
165
- # locksettings set-pattern: sets a pattern
166
- # A pattern is specified by a non-separated list of numbers that index the cell
167
- # on the pattern in a 1-based manner in left to right and top to bottom order,
168
- # i.e. the top-left cell is indexed with 1, whereas the bottom-right cell
169
- # is indexed with 9. Example: 1234
170
-
171
- # locksettings set-pin: sets a PIN
172
-
173
- # locksettings set-password: sets a password
174
-
175
- # locksettings clear: clears the unlock credential
176
-
177
- # locksettings verify: verifies the credential and unlocks the user
178
-
179
- # locksettings set-disabled: sets whether the lock screen should be disabled
180
-
181
- # locksettings get-disabled: retrieves whether the lock screen is disabled