From 76cae141c62f5b2e5cb43e4fb71b94b7cdd57b4b Mon Sep 17 00:00:00 2001 From: Randall Winkhart Date: Thu, 29 Dec 2022 01:36:17 -0500 Subject: [PATCH] Add track name to file name --- scrape.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/scrape.py b/scrape.py index 910c570..67b6285 100755 --- a/scrape.py +++ b/scrape.py @@ -2,6 +2,8 @@ from os import name from os.path import expanduser from pathlib import Path + +# external dependencies from requests import get download_dir = input('download location (full path): ').rstrip('\\').rstrip('/') @@ -34,11 +36,17 @@ Path(download_dir).mkdir(mode=0o700, parents=True, exist_ok=True) # track download loop download_id = start while download_id < stop + 1: + skip = False print(f"\rprogress: {str('{:04d}'.format(download_id))}/{str('{:04d}'.format(stop))}", end='') if not Path(download_dir + divider + str('{:04d}'.format(download_id))).is_file(): response = get(f"https://reflex-central.com/download.php?track_id={str(download_id)}", cookies=cookies) - with open(download_dir + divider + str('{:04d}'.format(download_id)), "wb") as f: - f.write(response.content) + try: + track_name = get(f"https://reflex-central.com/track_profile.php?track_id={str(download_id)}").text.split('\n')[71].split('b>')[1][:-3] + except IndexError: + track_name, skip = '', True + if not skip: + with open(f"{download_dir}{divider}{str('{:04d}'.format(download_id))} - {track_name}", "wb") as f: + f.write(response.content) download_id += 1 print('\ntrack download complete')