-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathbot.py
More file actions
142 lines (129 loc) · 5.15 KB
/
Copy pathbot.py
File metadata and controls
142 lines (129 loc) · 5.15 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
import os
import telebot
import fnmatch
import asyncio
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 & Soundcloud as FLAC (spotify only) and MP3.
Send a spotify song link to see the magic.
Use /flac for FLACs and use /mp3 for MP3s.
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).
Bot source code is available at https://github.com/rain2wood/spotBot-OSS.
\
""")
@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 '{}' -f -t".format(realSong)
os.system(DownloadSong)
f = open("link.txt", "r")
text = f.read()
await bot.send_message(chat_id, text)
cleansong = "rm -rf link.txt"
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 '{}' -f -a".format(realSong)
os.system(DownloadSong)
f = open("link.txt", "r")
text = f.read()
await bot.send_message(chat_id, text)
cleansong = "rm -rf link.txt"
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 '{}' -f -t".format(realSong)
os.system(DownloadSong)
f = open("link.txt", "r")
text = f.read()
await bot.send_message(chat_id, text)
cleansong = "rm -rf link.txt"
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 '{}' -m -t".format(realSong)
os.system(DownloadSong)
f = open("link.txt", "r")
text = f.read()
await bot.send_message(chat_id, text)
cleansong = "rm -rf link.txt"
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 '{}' -m -a".format(realSong)
os.system(DownloadSong)
f = open("link.txt", "r")
text = f.read()
await bot.send_message(chat_id, text)
cleansong = "rm -rf link.txt"
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 '{}' -m -t".format(realSong)
os.system(DownloadSong)
f = open("link.txt", "r")
text = f.read()
await bot.send_message(chat_id, text)
cleansong = "rm -rf link.txt"
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)
cleansong = "rm -rf link.txt"
os.system(cleansong)
asyncio.run(bot.infinity_polling())