-
Notifications
You must be signed in to change notification settings - Fork 0
initial soulseek dl #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
4www
wants to merge
8
commits into
main
Choose a base branch
from
feat/soulseek
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
1814b0c
initial soulseek dl
4www 26a1a35
improve soulseek
4www 9cf8066
fix soulseek base dir
4www 6fb8140
improve soulseek downloads
4www 2aaec1f
improve soulseek load config
4www 93e2471
change arg to `r4 download <channel_slug> --soulseek`
4www 0f98d78
improve soulseek dl fn names and cleantitle for file name
4www fe037cc
improve soulseek results matching to title
4www File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,14 @@ | ||
| import {resolve} from 'node:path' | ||
| import {mkdir} from 'node:fs/promises' | ||
| import {join, resolve} from 'node:path' | ||
| import {load as loadConfig} from '../lib/config.js' | ||
| import {getChannel, listTracks} from '../lib/data.js' | ||
| import { | ||
| downloadChannel, | ||
| writeChannelAbout, | ||
| writeChannelImageUrl, | ||
| writeTracksPlaylist | ||
| } from '../lib/download.js' | ||
| import {downloadChannel as downloadChannelSoulseek} from '../lib/soulseek.js' | ||
| import {parse} from '../utils.js' | ||
|
|
||
| export default { | ||
|
|
@@ -14,7 +17,13 @@ export default { | |
| options: { | ||
| output: { | ||
| type: 'string', | ||
| description: 'Output folder path (defaults to ./<slug>)' | ||
| description: 'Output folder path (defaults to config.downloadsDir/<slug>)' | ||
| }, | ||
| soulseek: { | ||
| type: 'boolean', | ||
| default: false, | ||
| description: | ||
| 'Download from Soulseek instead of track URLs (requires slskd)' | ||
| }, | ||
| limit: { | ||
| type: 'number', | ||
|
|
@@ -48,19 +57,33 @@ export default { | |
| concurrency: { | ||
| type: 'number', | ||
| default: 3, | ||
| description: 'Number of concurrent downloads' | ||
| description: 'Number of concurrent downloads (max 3 for soulseek)' | ||
| }, | ||
| // Soulseek-specific options | ||
| 'slskd-host': {type: 'string', description: 'slskd host'}, | ||
| 'slskd-port': {type: 'number', description: 'slskd port'}, | ||
| 'min-bitrate': { | ||
| type: 'number', | ||
| description: 'Minimum bitrate for lossy formats (default: 320)' | ||
| }, | ||
| 'slskd-downloads-dir': { | ||
| type: 'string', | ||
| description: | ||
| 'Temp folder where slskd saves files before moving to channel (default: /tmp/radio4000/slskd)' | ||
| } | ||
oskarrough marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }, | ||
|
|
||
| async run(argv) { | ||
| const {values, positionals} = parse(argv, this.options) | ||
|
|
||
| const slug = positionals[0] | ||
| if (!slug) { | ||
| throw new Error('Missing channel slug') | ||
| } | ||
| if (!slug) throw new Error('Missing channel slug') | ||
|
|
||
| // Resolve output path from config | ||
| const config = await loadConfig() | ||
| const baseDir = values.output || config.downloadsDir || '.' | ||
| const folderPath = resolve(join(baseDir, slug)) | ||
|
|
||
| const folderPath = resolve(values.output || `./${slug}`) | ||
| const dryRun = values['dry-run'] | ||
| const verbose = values.verbose | ||
| const noMetadata = values['no-metadata'] | ||
|
|
@@ -70,27 +93,49 @@ export default { | |
| const tracks = await listTracks({channelSlugs: [slug], limit: values.limit}) | ||
|
|
||
| console.log(`${channel.name} (@${channel.slug})`) | ||
| if (dryRun) { | ||
| console.log(folderPath) | ||
| } | ||
| if (values.soulseek) console.log('Source: Soulseek') | ||
| if (dryRun) console.log(folderPath) | ||
| console.log() | ||
|
|
||
| // Write channel context files (unless dry run) | ||
| // Write metadata files | ||
| if (!dryRun) { | ||
| const {mkdir} = await import('node:fs/promises') | ||
| await mkdir(folderPath, {recursive: true}) | ||
| if (!noMetadata) { | ||
| console.log(`${folderPath}/`) | ||
| await writeChannelAbout(channel, tracks, folderPath, {verbose}) | ||
| console.log(`├── ${channel.slug}.txt`) | ||
| await writeChannelImageUrl(channel, folderPath, {verbose}) | ||
| console.log('├── image.url') | ||
| await writeTracksPlaylist(tracks, folderPath, {verbose}) | ||
| console.log(`└── tracks.m3u (try: mpv ${folderPath}/tracks.m3u)`) | ||
| console.log() | ||
| } | ||
| } | ||
|
|
||
| console.log(`${folderPath}/`) | ||
| await writeChannelAbout(channel, tracks, folderPath, {verbose}) | ||
| console.log(`├── ${channel.slug}.txt`) | ||
| await writeChannelImageUrl(channel, folderPath, {verbose}) | ||
| console.log('├── image.url') | ||
| await writeTracksPlaylist(tracks, folderPath, {verbose}) | ||
| console.log(`└── tracks.m3u (try: mpv ${folderPath}/tracks.m3u)`) | ||
| console.log() | ||
| // Download via source | ||
| if (values.soulseek) { | ||
| // Build slskdConfig by merging CLI options with config.soulseek | ||
| const slskdDownloadsDir = | ||
| values['slskd-downloads-dir'] ?? '/tmp/radio4000/slskd' | ||
| const slskdConfig = { | ||
| ...config.soulseek, | ||
| host: values['slskd-host'] ?? config.soulseek.host, | ||
| port: values['slskd-port'] ?? config.soulseek.port, | ||
| downloadsDir: slskdDownloadsDir | ||
| } | ||
| await downloadChannelSoulseek(tracks, folderPath, { | ||
| dryRun, | ||
| verbose, | ||
| force: values.force, | ||
| retryFailed: values['retry-failed'], | ||
| concurrency: Math.min(values.concurrency, 3), | ||
| minBitrate: values['min-bitrate'], | ||
| slskdConfig | ||
| }) | ||
| return '' | ||
| } | ||
|
|
||
| // Download | ||
| // Default: yt-dlp (supports YouTube, SoundCloud, Bandcamp, etc.) | ||
| const result = await downloadChannel(tracks, folderPath, { | ||
| force: values.force, | ||
| retryFailed: values['retry-failed'], | ||
|
|
@@ -100,7 +145,6 @@ export default { | |
| concurrency: values.concurrency | ||
| }) | ||
|
|
||
| // Only show summary and failures for actual downloads, not dry runs | ||
| if (!dryRun) { | ||
| console.log() | ||
| console.log('Summary:') | ||
|
|
@@ -120,19 +164,17 @@ export default { | |
| } | ||
| } | ||
|
|
||
| // Don't return data - all output already printed above | ||
| return '' | ||
| }, | ||
|
|
||
| examples: [ | ||
| 'r4 download ko002', | ||
| 'r4 download ko002 --limit 10', | ||
| 'r4 download ko002 --output ./my-music', | ||
| 'r4 download ko002 --dry-run', | ||
| 'r4 download ko002 --force', | ||
| 'r4 download ko002 --retry-failed', | ||
| 'r4 download ko002 --no-metadata', | ||
| 'r4 download ko002 --concurrency 5', | ||
| 'mpv ko002/tracks.m3u' | ||
|
Comment on lines
-129
to
-136
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why remove these examples? seems nice to have them |
||
| 'r4 download ko002 --limit 10 --dry-run', | ||
| '', | ||
| '# Soulseek (requires slskd)', | ||
| '# docker run -d --network host -v /tmp/radio4000/slskd:/app/downloads slskd/slskd', | ||
| 'r4 download ko002 --soulseek', | ||
| '', | ||
| '# Output: ko002/tracks/ (yt-dlp), ko002/soulseek/ (soulseek)' | ||
| ] | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.