-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadvanced.py
109 lines (100 loc) · 3.02 KB
/
advanced.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
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
import feedparser
from bs4 import BeautifulSoup
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.options import Options
import youtube_dl
from youtubesearchpython import SearchVideos
import json
from concurrent.futures import ThreadPoolExecutor
import time
from test import download_audio,search_youtube
from datetime import datetime
# Setup webdriver
now = datetime.now()
import os
# Specify the name of the directory to be created
directory = str(now.strftime("%d %b %y"))
if not os.path.exists(directory):
os.mkdir(directory)
s=Service(ChromeDriverManager().install())
options = Options()
options.add_argument("--blink-settings=imagesEnabled=false") # Disable images
driver = webdriver.Chrome(service=s, options=options)
# Get the RSS feed data
rss_url ="https://newalbumreleases.net/feed/"
feed = feedparser.parse(rss_url)
entries=feed['entries']
a=entries[0]['links'][0]['href']
print(a)
driver.get(a)
html_content = driver.page_source
soup = BeautifulSoup(html_content, 'html.parser')
details=[]
songs=[]
paragraphs = soup.find_all('p')
det=str(paragraphs[1])
details.append(det.split("<b>"))
tracks=str(paragraphs[2]).split("\n")
dets=details[0]
nodets=list(dets[1].split("<br>"))[0]
new=[]
valli=nodets.split('\n')
aname=valli[0][:-5]
print(aname)
#print(aname)
tracks.pop(0)
newtracks=[]
for i in tracks:
#break
newtracks.append(i[:-5])
x=newtracks[-1].split('"')[0]
url=f"{x}"
print(newtracks)
def process_track(track):
x = track[5:]
y = x.split("(")[0]
string=y.split(" ")
link=""
for i in string:
link=link+i+"+"
driver.get(f"https://musicstax.com/search?q={aname}+{link}")
html_content = driver.page_source
soup = BeautifulSoup(html_content, 'html.parser')
site = str(soup.find(class_='song-image search-image'))
if site=="None":
print("not found")
return
match = site.split('"')[5]
newlink="https://musicstax.com" + match
print(newlink)
driver.get(newlink)
html_content = driver.page_source
soup = BeautifulSoup(html_content, 'html.parser')
site = soup.find_all(class_='song-bar-statistic-number')
dance=str(site[2])
splited=dance.split("%")[0]
siter=int(splited.split("\n")[1])
match = siter
if match>=80:
print(f"Success, Energy={match}")
query=f"{aname} - {y}"
print(query)
file=open(f'{directory}/songs.txt', 'w')
file.write(f"{query} link: {a}\n")
file.close()
vidurl=search_youtube(query)
print(vidurl)
if vidurl!="No results found.":
download_audio(str(vidurl),f'{directory}')
time.sleep(3)
else:
print("Video not found :(")
else:
print(f"Failed test, Energy={match}")
time.sleep(3)
# Cooldown to avoid potential DoS attack
with ThreadPoolExecutor(max_workers=5) as executor:
futures = [executor.submit(process_track, track) for track in newtracks[:-3]]
driver.close()