-
Notifications
You must be signed in to change notification settings - Fork 1
/
beemp3.py
49 lines (34 loc) · 1.12 KB
/
beemp3.py
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
import requests
from lxml import etree
from util import hook
def get_mp3(inp):
""" search beemp3.com """
session = requests.Session()
search_url = "http://beemp3.com/index.php"
base_url = "http://beemp3.com/"
params = {
"q": inp,
"st": "all"
}
html = etree.HTML(session.get(search_url, params=params).text)
try:
title = ""
for part in html.xpath(
"//ol/li[1]/div/div[@class='song-name']/a/font/strong/text()"):
title = title + part + " "
url = base_url + html.xpath(
"//ol/li[1]/div/div[@class='song-name']/a/@href")[0]
url = session.get(
"http://tinyurl.com/api-create.php?", params={"url": url}).text
return "%s: %s" % (title, url)
except IndexError:
return "No results"
@hook.command('mp3')
@hook.command
def beemp3(inp):
".beemp3 <song title> -- gets the top result from beemp3.com. However, "\
"the HTML rendering on that site is bananas, so the titles may display "\
"funky."
return get_mp3(inp)
if __name__ == "__main__":
print get_mp3("Greyhound")