forked from freshremix/spotBot-OSS
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbot.py
More file actions
228 lines (213 loc) · 8.24 KB
/
bot.py
File metadata and controls
228 lines (213 loc) · 8.24 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
#!/usr/bin/env .venv/bin/python
import os
import telebot
import fnmatch
import asyncio
import glob
from telebot.async_telebot import AsyncTeleBot
botToken = os.environ['token']
bot = AsyncTeleBot(botToken, parse_mode=None)
print("spotBot is up and running.")
@bot.message_handler(commands=['help'])
async def send_welcome(message):
await bot.reply_to(message, """\
This bot can download songs / albums / playlists from Spotify (FLAC, MP3, M4A) & Soundcloud (MP3).
Send a spotify song link to see the magic.
Use /flac for FLACs.
Use /mp3 for MP3s.
Use /m4a for M4As.
Use /sc to download songs from SoundCloud (Only LINKS are supported).
For example: /flac https://open.spotify.com/track/2iUXsYOEPhVqEBwsqP70rE?si=833f974040c341d0
OR: /flac rewrite the stars anne marie
This bot uses spotDL (https://github.com/spotDL). Hats off to their work.
This bot uses scdl (https://github.com/flyingrub/scdl). Hats off to their work.
This bot uses pyTelegramBotAPI (https://github.com/eternnoir/pyTelegramBotAPI).
This bot forked from https://github.com/rain2wood/spotBot-OSS.
Bot source code is available at https://github.com/Diaz1401/SpotifyTeleBot.
\
""")
@bot.message_handler(commands=['faq'])
async def faq(message):
await bot.reply_to(message, """ \
Q: My song isn't right! What Can I do?
A: Try to use another Spotify link.
Q: My lyrics aren't right! What can I do?
A: I don't know either. Just don't read lyrics.
Note that the tool fetches results from YouTube Music and it isn't 100 percent accurate.
\
""")
@bot.message_handler(commands=['up'])
async def up_check(message):
await bot.reply_to(message, "Bot is up and running.")
@bot.message_handler(commands=['flac'])
async def download_flac(message):
chat_id = message.chat.id
songLink = message.text
str = songLink
if str.find("track")!=-1:
print("is track")
realSong = songLink.replace("/flac", "")
await bot.reply_to(message, "Fetching song...")
DownloadSong = "bash magic.sh '{}' flac -t".format(realSong)
os.system(DownloadSong)
f = open("link.txt", "r")
text = f.read()
await bot.send_message(chat_id, text)
for file in glob.glob("*.flac"):
print(file)
audio = open(file, 'rb')
await bot.send_audio(chat_id, audio)
cleansong = "rm -rf *.flac"
os.system(cleansong)
elif str.find("album")!=-1 or str.find("playlist")!=-1:
print("is album or playlist")
realSong = songLink.replace("/flac", "")
await bot.reply_to(message, "Fetching album / playlist. This will take a while.")
DownloadSong = "bash magic.sh '{}' flac -a".format(realSong)
os.system(DownloadSong)
f = open("link.txt", "r")
text = f.read()
await bot.send_message(chat_id, text)
for file in glob.glob("*.flac"):
print(file)
audio = open(file, 'rb')
await bot.send_audio(chat_id, audio)
cleansong = "rm -rf *.flac"
os.system(cleansong)
else:
print("is maybe query")
realSong = songLink.replace("/flac", "")
tryQuery = "Trying to search for '{}' on Spotify...".format(realSong)
await bot.reply_to(message, tryQuery)
DownloadSong = "bash magic.sh '{}' flac -t".format(realSong)
os.system(DownloadSong)
f = open("link.txt", "r")
text = f.read()
await bot.send_message(chat_id, text)
for file in glob.glob("*.flac"):
print(file)
audio = open(file, 'rb')
await bot.send_audio(chat_id, audio)
cleansong = "rm -rf *.flac"
os.system(cleansong)
@bot.message_handler(commands=['mp3'])
async def download_mp3(message):
chat_id = message.chat.id
songLink = message.text
str = songLink
if str.find("track")!=-1:
print("is track")
realSong = songLink.replace("/mp3", "")
await bot.reply_to(message, "Fetching song...")
DownloadSong = "bash magic.sh '{}' mp3 -t".format(realSong)
os.system(DownloadSong)
f = open("link.txt", "r")
text = f.read()
await bot.send_message(chat_id, text)
for file in glob.glob("*.mp3"):
print(file)
audio = open(file, 'rb')
await bot.send_audio(chat_id, audio)
cleansong = "rm -rf *.mp3"
os.system(cleansong)
elif str.find("album")!=-1 or str.find("playlist")!=-1:
print("is album or playlist")
realSong = songLink.replace("/mp3", "")
await bot.reply_to(message, "Fetching album / playlist. This will take a while.")
DownloadSong = "bash magic.sh '{}' mp3 -a".format(realSong)
os.system(DownloadSong)
f = open("link.txt", "r")
text = f.read()
await bot.send_message(chat_id, text)
for file in glob.glob("*.mp3"):
print(file)
audio = open(file, 'rb')
await bot.send_audio(chat_id, audio)
cleansong = "rm -rf *.mp3"
os.system(cleansong)
else:
print("is maybe query")
realSong = songLink.replace("/mp3", "")
tryQuery = "Trying to search for '{}' on Spotify...".format(realSong)
await bot.reply_to(message, tryQuery)
DownloadSong = "bash magic.sh '{}' mp3 -t".format(realSong)
os.system(DownloadSong)
f = open("link.txt", "r")
text = f.read()
await bot.send_message(chat_id, text)
for file in glob.glob("*.mp3"):
print(file)
audio = open(file, 'rb')
await bot.send_audio(chat_id, audio)
cleansong = "rm -rf *.mp3"
os.system(cleansong)
@bot.message_handler(commands=['m4a'])
async def download_mp3(message):
chat_id = message.chat.id
songLink = message.text
str = songLink
if str.find("track")!=-1:
print("is track")
realSong = songLink.replace("/m4a", "")
await bot.reply_to(message, "Fetching song...")
DownloadSong = "bash magic.sh '{}' m4a -t".format(realSong)
os.system(DownloadSong)
f = open("link.txt", "r")
text = f.read()
await bot.send_message(chat_id, text)
for file in glob.glob("*.m4a"):
print(file)
audio = open(file, 'rb')
await bot.send_audio(chat_id, audio)
cleansong = "rm -rf *.m4a"
os.system(cleansong)
elif str.find("album")!=-1 or str.find("playlist")!=-1:
print("is album or playlist")
realSong = songLink.replace("/m4a", "")
await bot.reply_to(message, "Fetching album / playlist. This will take a while.")
DownloadSong = "bash magic.sh '{}' m4a -a".format(realSong)
os.system(DownloadSong)
f = open("link.txt", "r")
text = f.read()
await bot.send_message(chat_id, text)
for file in glob.glob("*.m4a"):
print(file)
audio = open(file, 'rb')
await bot.send_audio(chat_id, audio)
cleansong = "rm -rf *.m4a"
os.system(cleansong)
else:
print("is maybe query")
realSong = songLink.replace("/m4a", "")
tryQuery = "Trying to search for '{}' on Spotify...".format(realSong)
await bot.reply_to(message, tryQuery)
DownloadSong = "bash magic.sh '{}' m4a -t".format(realSong)
os.system(DownloadSong)
f = open("link.txt", "r")
text = f.read()
await bot.send_message(chat_id, text)
for file in glob.glob("*.m4a"):
print(file)
audio = open(file, 'rb')
await bot.send_audio(chat_id, audio)
cleansong = "rm -rf *.m4a"
os.system(cleansong)
@bot.message_handler(commands=['sc'])
async def download_soundcloud(message):
chat_id = message.chat.id
songLink = message.text
realSong = songLink.replace("/sc", "")
print("attempt to download track from soundcloud")
await bot.reply_to(message, "Fetching song from link...")
DownloadSong = "bash magic.sh {} -sc -x".format(realSong)
os.system(DownloadSong)
f = open("link.txt", "r")
text = f.read()
await bot.send_message(chat_id, text)
for file in glob.glob("*.mp3"):
print(file)
audio = open(file, 'rb')
await bot.send_audio(chat_id, audio)
cleansong = "rm -rf *.mp3"
os.system(cleansong)
asyncio.run(bot.infinity_polling())