-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRickRollDetector.py
More file actions
111 lines (88 loc) · 2.73 KB
/
RickRollDetector.py
File metadata and controls
111 lines (88 loc) · 2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
from ShazamAPI import Shazam
import youtube_dl
import os
import PythonYoutube
from pydub import AudioSegment
import math
import sys
class Rick():
def __init__(self,url,file_way,temp_file_way,char1):
self.url = url
self.file_way = file_way
self.temp_file_way = temp_file_way
self.char1= char1
def RickRollChecker(self):
file156 = open(self.file_way+self.char1+"rickrollpast.txt", "r+", encoding="utf-8")
ExRicks = [i for i in file156.readlines()]
url=self.url
if url in ExRicks:
return True
os.chdir(self.file_way)
song_there = os.path.isfile('control.mp3')
try:
if song_there:
os.remove('control.mp3')
except PermissionError:
print("Wait for the current playing music to end or use the 'stop' command")
ydl_opts = {
'format': 'bestaudio/best',
'postprocessors': [{
'key': 'FFmpegExtractAudio',
'preferredcodec': 'mp3',
'preferredquality': '192',
}],
}
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
ydl.download([url])
for file in os.listdir("./"):
if file.endswith(".mp3"):
os.rename(file, "control.mp3")
self.audio_download()
os.chdir(self.temp_file_way)
for file in os.listdir("./"):
if file.endswith(".mp3"):
value = self.ShazamRick(ExRicks=ExRicks,file156=file156,rick_file_nm=file)
if value == True:
print("Bu rickroll")
sys.exit()
youtube_link = PythonYoutube.YoutubeCommentFounder(url)
isThisRick = youtube_link.CommentGetter()
if isThisRick:
print("RickRoll detected")
return True
else:
print("No Rickroll")
return False
def audio_download(self):
sFile = AudioSegment.from_mp3(file="control.mp3")
total_minute = math.ceil(sFile.duration_seconds/60)
for i in range(0,total_minute,1):
split_fl = str(i)+"_"+"control.mp3"
self.audio_split(sFile,i,i+1,split_fl)
if i == total_minute-1:
pass
def audio_split(self,audio_name,start_min,end_min,new_filename):
st = start_min*60000
et = end_min*60000
splt_aud = audio_name[st:et]
splt_aud.export(self.temp_file_way+"\\"+new_filename,format="mp3")
def delete_audio(self):
os.chdir(self.temp_file_way)
for file in os.listdir("./"):
if file.endswith(".mp3"):
os.remove(file)
def ShazamRick(self, ExRicks : list,file156,rick_file_nm):
url = self.url
mp3_file_content_to_recognize = open(rick_file_nm, 'rb').read()
shazam = Shazam(mp3_file_content_to_recognize)
recognize_generator = shazam.recognizeSong()
while True:
asas = str(next(recognize_generator))
if 'Rick' in asas or 'Astley' in asas :
ExRicks.append(url)
for i in ExRicks:
file156.write(i)
file156.close()
return True
else:
return False