Skip to content

Commit 8dd327d

Browse files
committed
fix logging and action
1 parent 4094fe8 commit 8dd327d

File tree

6 files changed

+47
-51
lines changed

6 files changed

+47
-51
lines changed

.github/workflows/download.yml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,16 @@ on:
66
playlist_url:
77
description: 'SoundCloud Playlist URL'
88
required: true
9-
zip_files:
10-
description: 'Zip the downloaded files?'
11-
required: true
12-
default: 'true'
139
output_folder:
1410
description: 'Output folder name'
1511
required: false
1612
default: 'output'
1713

1814
jobs:
1915
run:
16+
permissions:
17+
contents: read
18+
actions: write
2019
runs-on: ubuntu-latest
2120

2221
steps:
@@ -43,8 +42,7 @@ jobs:
4342
run: |
4443
poetry run python -m soundclouddownloader.cli_entry \
4544
--url "${{ github.event.inputs.playlist_url }}" \
46-
--output "${{ github.event.inputs.output_folder }}" \
47-
$([[ "${{ github.event.inputs.zip_files }}" == "true" ]] && echo "--zip")
45+
--output "${{ github.event.inputs.output_folder }}"
4846
4947
- name: Upload output files
5048
uses: actions/upload-artifact@v4

.github/workflows/python-tests.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ on:
88

99
jobs:
1010
test:
11+
permissions:
12+
contents: read
1113
runs-on: ubuntu-latest
1214

1315
steps:
@@ -29,4 +31,4 @@ jobs:
2931
3032
- name: Run tests
3133
run: |
32-
poetry run python -m unittest discover
34+
poetry run python -m unittest discover

README.md

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## Description
44

5+
The easiest way to run this is to fork and run via github actions.
6+
57
This project provides a Python script for downloading entire playlists from SoundCloud. It uses [yt-dlp](https://github.com/yt-dlp/yt-dlp) to handle the downloading process, making it robust against changes in SoundCloud's website structure. The script downloads each track in the playlist, converts them to MP3 format, and optionally packages them into a zip file.
68

79
This project uses Poetry for dependency management and packaging. If you haven't installed Poetry yet, you can do so by following the [official installation guide](https://python-poetry.org/docs/#installation).
@@ -13,12 +15,19 @@ This project uses Poetry for dependency management and packaging. If you haven't
1315
- FFmpeg
1416
- Poetry
1517

16-
## Installation
18+
19+
## Running the program
20+
You have 2 options:
21+
### 1. Github Actions
22+
23+
- The simplest and fastest way to get your own hosted version
24+
- Simply fork this repo and run via Github action
25+
26+
### 2. Local Installation
1727

1828
1. Clone this repository:
1929
```python
2030
git clone https://github.com/cainky/soundclouddownloader.git
21-
cd soundclouddownloader
2231
```
2332

2433
2. Install the required Python packages:
@@ -36,10 +45,11 @@ poetry install
3645
1. Run the script:
3746

3847
```python
48+
cd soundclouddownloader
3949
poetry run python main.py
4050
```
4151

42-
2. When prompted, enter the URL of the SoundCloud playlist you want to download. Paste the entire url including the `?si=` part. Playlist can be private.
52+
2. When prompted, enter the URL of the SoundCloud playlist you want to download. Paste the entire url including the `?si=` part. Playlist can be private, just use the Share button to get the private link.
4353

4454
3. Enter Y/n if you want the script to create a zip file of all the tracks.
4555

poetry.lock

Lines changed: 10 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

soundclouddownloader/cli_entry.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,9 @@ def run(playlist_url: str, output_dir: Path, should_zip: bool = False):
1818
parser = argparse.ArgumentParser(description="CLI for SoundCloud Downloader")
1919
parser.add_argument("--url", required=True, help="SoundCloud playlist URL")
2020
parser.add_argument("--output", default="output", help="Output directory")
21-
parser.add_argument("--zip", action="store_true", help="Zip downloaded files")
2221
args = parser.parse_args()
2322

2423
output_path = Path(args.output).resolve()
2524
output_path.mkdir(parents=True, exist_ok=True)
2625

27-
run(args.url, output_path, args.zip)
26+
run(args.url, output_path, False)

soundclouddownloader/main.py

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -69,24 +69,26 @@ def download_track(self, track: Track, output_dir: Path) -> Optional[Path]:
6969
else:
7070
filepath = None
7171

72-
if filepath:
73-
logger.info(f"Successfully downloaded: {filepath}")
74-
return filepath
75-
else:
76-
logger.info(f"File not found after download: {filepath_without_ext}")
72+
if not filepath:
7773
dir_contents = list(Path(output_dir).iterdir())
78-
logger.debug(f"Directory contents: {[str(f) for f in dir_contents]}")
7974

8075
# Try to find a file with a similar name
8176
similar_files = [
8277
f for f in dir_contents if f.stem.startswith(clean_name)
8378
]
8479
if similar_files:
85-
similar_file = similar_files[0]
86-
logger.info(f"Found similar file: {similar_file}")
87-
return similar_file
88-
89-
return None
80+
filepath = similar_files[0]
81+
if not filepath:
82+
logger.info(
83+
f"File not found after download: {filepath_without_ext}"
84+
)
85+
logger.debug(
86+
f"Directory contents: {[str(f) for f in dir_contents]}"
87+
)
88+
return None
89+
90+
logger.info(f"Successfully downloaded: {filepath}")
91+
return filepath
9092

9193
def get_playlist_info(self, playlist_url: str) -> Playlist:
9294
"""
@@ -207,14 +209,11 @@ def main() -> None:
207209

208210
downloader = SoundCloudDownloader()
209211
logger.info("Downloading now please wait...")
210-
zip_file = downloader.download_playlist(
212+
download = downloader.download_playlist(
211213
playlist_url, output_dir, max_workers=3, should_zip=should_zip
212214
)
213-
if zip_file:
214-
if should_zip:
215-
logger.success(f"Playlist downloaded and zipped: {zip_file}")
216-
else:
217-
logger.success(f"Playlist downloaded to directory: {zip_file}")
215+
if download:
216+
logger.success(f"Playlist downloaded: {download}")
218217
else:
219218
logger.error("Failed to download playlist.")
220219
sys.stdout.flush()

0 commit comments

Comments
 (0)