-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsearch.py
executable file
·56 lines (40 loc) · 1.35 KB
/
search.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
50
51
52
53
54
55
56
#!../bin/python
import os, sys, argparse
from pyradios import RadioBrowser
rb = RadioBrowser()
#help(RadioBrowser)
def main():
global args
parser = argparse.ArgumentParser()
parser.add_argument('--keyword', type=str)
parser.add_argument('--exact', type=str)
parser.add_argument('--type', type=str)
args = parser.parse_args()
if str(args.exact).lower() == "false":
result = rb.search(name=str(args.keyword), name_exact=False)
else:
result = rb.search(name=str(args.keyword), name_exact=True)
playlist(result, args.type)
def playlist(list, type = "m3u"):
m3u = "#EXTM3U"
pls = "[playlist]"
if type.lower() == "m3u":
for idx, item in enumerate(list):
m3u += '\n#EXTINF:-1, ' + str(item["name"]) + ' \n'+ str(item["url_resolved"])
file_out = "export_rb.m3u"
with open(file_out, "w") as o:
o.write(m3u)
print("[i] Search results written to export_rb.m3u")
return m3u
elif type.lower() == "pls":
pls += f"NumberOfEntries={len(list)}"
for idx, item in enumerate(list):
pls += '\nFile' + str(int(idx)+1) + '=' + str(item["url_resolved"]) + '\nTitle' + str(int(idx)+1) + '=' + str(item["name"]) + '\nLength' + str(int(idx+1)) + '=-1'
file_out = "export_rb.pls"
with open(file_out, "w") as o:
o.write(pls)
print("[i] Search results written to export_rb.pls")
return pls
else:
return pls
main()