don't download if file is already there

This commit is contained in:
Alexander Matson 2019-01-14 12:47:03 -05:00
parent 0f77e6a69a
commit e45f0129c3
2 changed files with 9 additions and 7 deletions

View File

@ -15,7 +15,7 @@ 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/PartnersInRhyme/"
def getCollection(collection_url): def getCollection(collection_url):
r = requests.get(collection_url) r = requests.get(collection_url)
@ -28,7 +28,7 @@ def getCollection(collection_url):
driver.get("http:" + player) driver.get("http:" + player)
el = WebDriverWait(driver, 60).until(f) el = WebDriverWait(driver, 60).until(f)
time.sleep(1) time.sleep(2)
psoup = BeautifulSoup(driver.page_source, 'html.parser') psoup = BeautifulSoup(driver.page_source, 'html.parser')
driver.quit() driver.quit()
@ -44,14 +44,16 @@ def downloadSong(song_url):
if not os.path.exists(outDir): if not os.path.exists(outDir):
os.makedirs(outDir) os.makedirs(outDir)
if not os.path.isfile(os.path.join(outDir, outFile)):
i = requests.get(song_url) i = requests.get(song_url)
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)
else:
print("File", outFile, "already exists... skipping")
def getSongFromURL(song_url): def getSongFromURL(song_url):
list = song_url.split("/") list = song_url.split("/")
print(list)
return (list[4], list[-1]) return (list[4], list[-1])
def f(d): def f(d):