Skip to content

Commit

Permalink
tqdm support
Browse files Browse the repository at this point in the history
  • Loading branch information
xxruyle committed Jul 14, 2022
1 parent 4d649ab commit 66eb37c
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 30 deletions.
9 changes: 7 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
# Change Log

## v2.0.0 - July 13, 2022
#### tqdm
- Contains all changes and bugfixes from 1.0.1-1.0.3
- tqdm support

## v1.0.3
#### Unicode
- Fixed problem where extra whitespaces would appear in folder names
-

## v1.0.2
#### Argparse

Expand All @@ -20,7 +25,7 @@
- upload_songs() method in youtube_music.py


## v1.0.0 - April 23, 2022
# v1.0.0 - April 23, 2022
#### Initial release

- Added ability to download the album cover to directory folder alongside the MP3s
Expand Down
25 changes: 5 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,19 @@ Simple python script which downloads Bandcamp albums and songs in mp3 format. MP

# The Script in Action
### Running the script
```powershell
C:\bandcampdownload> python main.py -u https://wolfgang-amadeus-mozart.bandcamp.com/album/mozarts-piano-sonatas-vol-1
```bash
$ bcdl https://wolfgang-amadeus-mozart.bandcamp.com/album/mozarts-requiem-instrumental
Getting MP3 links...
Getting album cover from: https://f4.bcbits.com/img/a3050325896_16.jpg
Downloading...
Downloading... Piano Sonata No.1 in C-Major, K. 279- I. Allegro
Downloading... Piano Sonata No.1 in C-Major, K. 279- II. Andante
Downloading... Piano Sonata No.1 in C-Major, K. 279- III. Allegro
Downloading... Piano Sonata No.2 in F-Major, K. 280- I. Allegro Assai
Downloading... Piano Sonata No.2 in F-Major, K. 280- II. Adagio
Downloading... Piano Sonata No.2 in F-Major, K. 280- III. Presto
Success!
...
Getting album cover from: https://f4.bcbits.com/img/a2608013838_16.jpg
Downloading Album: Mozarts Requiem Instrumental: 100%|██████████████████████████████████████████| 12/12 [00:05<00:00, 2.06it/s] 100%|████████████████████████████████████████████████████████████████████████████████████████████| 12/12 [00:05<00:00, 2.06it/s] Download Success!
```

### The mp3 files and album cover downloaded with correct metadata
<img src='images\album.png'></img>



### Example of uploading to YoutTube Music using <a href="https://github.com/sigma67/ytmusicapi">ytmusicapi</a>
```powershell
Seed AI.mp3 Upload Result: STATUS_SUCCEEDED
Simulation Hypothesis.mp3 Upload Result: STATUS_SUCCEEDED
Technological Singularity.mp3 Upload Result: STATUS_SUCCEEDED
Turing Machine.mp3 Upload Result: <Response [503]>
Waiting 10 seconds...
Turing Machine.mp3 Upload Result: STATUS_SUCCEEDED
Folder C:/Music/Mozarts Requiem Instrumnetal: 100%|██████████████████████████████████████████████████████| 13/13 [00:21<00:00, 1.68s/it]
Upload Success!
```

Expand Down
9 changes: 6 additions & 3 deletions bandcampdl/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import requests
import os
import sys
from tqdm.auto import tqdm, trange


class linkfinder:
Expand Down Expand Up @@ -170,13 +171,15 @@ def download(self):
f.write(cover_response.content)


print(f"Downloading Album: {meta_info.get_title(self)}")
for i in range(len(self.download_list)):

downloadRange = trange(len(self.download_list))
for i in tqdm(downloadRange, position=0, leave=True):
downloadRange.set_description(f"Downloading Album: {meta_info.get_title(self)}")
filepath = f"{self.directory}/{list(meta_info.get_trackname(self))[i]}"
filename = f"{filepath}.mp3"
track = self.download_list[i].strip('"')
response = requests.get(track)
print(f"Downloading... {list(meta_info.get_trackname(self))[i]} ")
#tqdm.write(f"Downloading... {list(meta_info.get_trackname(self))[i]} ")

# installing the song to the intended directory
with open(filename, 'wb') as f:
Expand Down
9 changes: 4 additions & 5 deletions bandcampdl/youtube_music.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from ytmusicapi import YTMusic

from os import listdir

from tqdm import tqdm
import time

class YTM_upload():
Expand All @@ -22,10 +21,10 @@ def upload_songs(self, album_folder):
:returns: Song1.mp3 Upload Result: STATUS_SUCCEED
...
'''
for song in listdir(album_folder):
for song in tqdm(listdir(album_folder), desc=f"Uploading Folder {album_folder}", position=0, leave=True):
if ".mp3" in song: # Makes sure non mp3 files do not get uploaded
upload_status = str(self.ytmusic.upload_song(f"{album_folder}/{song}"))
print(song + " Upload Result: " + upload_status)
#print(song + " Upload Result: " + upload_status)

#If a response error occurs, the script will wait 20 seconds
if upload_status == "<Response [503]>" or upload_status == "<Response [409]>":
Expand All @@ -34,7 +33,7 @@ def upload_songs(self, album_folder):
print("Waiting 20 seconds due to rate limit...")
time.sleep(20)
upload_status = self.ytmusic.upload_song(f"{album_folder}/{song}")
print(song + " Post Wait Result: " + str(upload_status))
#print(song + " Post Wait Result: " + str(upload_status))
if str(upload_status) == "STATUS_SUCCEEDED":
upload_error = False

Expand Down
Binary file modified requirements.txt
Binary file not shown.

0 comments on commit 66eb37c

Please sign in to comment.