working album fetching
This commit is contained in:
parent
dafaeb32a2
commit
0f77e6a69a
|
@ -2,3 +2,4 @@ env/
|
||||||
files/
|
files/
|
||||||
__pycache__/
|
__pycache__/
|
||||||
*.tar.gz
|
*.tar.gz
|
||||||
|
*.log
|
||||||
|
|
Binary file not shown.
5
main.py
5
main.py
|
@ -1,4 +1,3 @@
|
||||||
import pir_connector
|
from pir_connector import *
|
||||||
|
|
||||||
|
getCollection("https://www.partnersinrhyme.com/royaltyfreemusic/Corporate-Music-and-Motivational-Music/happymusic")
|
||||||
pir_connector.downloadSong("https://www.partnersinrhyme.com/files/Happy_Carefree_Music/samples/files/Carefree_Bluegrass.mp3", "Carefree_Bluegrass.mp3", "Happy_Carefree_Music")
|
|
||||||
|
|
|
@ -1,15 +1,45 @@
|
||||||
import requests
|
import requests
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
|
import time
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
|
from selenium import webdriver
|
||||||
|
from selenium.webdriver.common.by import By
|
||||||
|
from selenium.webdriver.common.keys import Keys
|
||||||
|
from selenium.webdriver.support.ui import WebDriverWait
|
||||||
|
from selenium.webdriver.support.expected_conditions import presence_of_element_located
|
||||||
|
from selenium.webdriver.firefox.options import Options
|
||||||
|
|
||||||
|
options = Options()
|
||||||
|
options.headless = True
|
||||||
|
|
||||||
base_url = "https://www.partnersinrhyme.com/royaltyfreemusic"
|
base_url = "https://www.partnersinrhyme.com/royaltyfreemusic"
|
||||||
base_files_url = "https://www.partnersinrhyme.com/files"
|
base_files_url = "https://www.partnersinrhyme.com/files/"
|
||||||
base_out_url = "files/"
|
base_out_url = "files/"
|
||||||
|
|
||||||
def downloadSong(song_url, song_file, collection_name):
|
def getCollection(collection_url):
|
||||||
|
r = requests.get(collection_url)
|
||||||
|
soup = BeautifulSoup(r.text, 'html.parser')
|
||||||
|
player = soup.iframe["src"];
|
||||||
|
|
||||||
|
p = requests.get("http:" + player);
|
||||||
|
|
||||||
|
with webdriver.Firefox(options=options) as driver:
|
||||||
|
driver.get("http:" + player)
|
||||||
|
el = WebDriverWait(driver, 60).until(f)
|
||||||
|
|
||||||
|
time.sleep(1)
|
||||||
|
psoup = BeautifulSoup(driver.page_source, 'html.parser')
|
||||||
|
|
||||||
|
driver.quit()
|
||||||
|
|
||||||
|
for li in psoup.find_all("li"):
|
||||||
|
print("downloading...", li.attrs['data-mp3'])
|
||||||
|
downloadSong(base_files_url + li.attrs['data-mp3'])
|
||||||
|
|
||||||
|
def downloadSong(song_url):
|
||||||
|
(collection_name, outFile) = getSongFromURL(song_url);
|
||||||
outDir = base_out_url + collection_name
|
outDir = base_out_url + collection_name
|
||||||
outFile = song_file;
|
|
||||||
|
|
||||||
if not os.path.exists(outDir):
|
if not os.path.exists(outDir):
|
||||||
os.makedirs(outDir)
|
os.makedirs(outDir)
|
||||||
|
@ -19,4 +49,10 @@ def downloadSong(song_url, song_file, collection_name):
|
||||||
with open(os.path.join(outDir, outFile), 'wb') as tempFile:
|
with open(os.path.join(outDir, outFile), 'wb') as tempFile:
|
||||||
tempFile.write(i.content)
|
tempFile.write(i.content)
|
||||||
|
|
||||||
# def getCollection(collection_name):
|
def getSongFromURL(song_url):
|
||||||
|
list = song_url.split("/")
|
||||||
|
print(list)
|
||||||
|
return (list[4], list[-1])
|
||||||
|
|
||||||
|
def f(d):
|
||||||
|
return d.find_element_by_class_name("listContainer")
|
||||||
|
|
Loading…
Reference in New Issue