mirror of
https://github.com/GuillemCastro/spotify-dl.git
synced 2025-04-11 11:53:58 +02:00
Compare commits
31 commits
Author | SHA1 | Date | |
---|---|---|---|
|
afafa36263 | ||
|
9728a6457d | ||
|
feed60534a | ||
|
a5c3225ea3 | ||
|
7c7870c044 | ||
|
7fb4073633 | ||
|
455437ad04 | ||
|
e4807e6834 | ||
|
3325ec3ccd | ||
|
ab33af0e99 | ||
|
4bcf2ed11a | ||
|
8db671bae0 | ||
|
6b592c559a | ||
|
0ec9b9eb72 | ||
|
64cb5ef64a | ||
|
5806b26baf | ||
|
fd95b5a0a9 | ||
|
9be6396112 | ||
|
61d6268524 | ||
|
211fe59beb | ||
|
b16ff85449 | ||
|
db6f2ce59e | ||
|
18194228a5 | ||
|
d56e5c6c78 | ||
|
ad9288d243 | ||
|
a041136986 | ||
|
d33cc37050 | ||
|
a7adb7b8eb | ||
|
5373f95a19 | ||
|
302367232e | ||
|
72e27605c5 |
21 changed files with 1514 additions and 1006 deletions
53
.github/workflows/build-latest.yml
vendored
Normal file
53
.github/workflows/build-latest.yml
vendored
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
name: Build latest
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- '*'
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- '*'
|
||||||
|
|
||||||
|
env:
|
||||||
|
CARGO_TERM_COLOR: always
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
|
||||||
|
linux:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- name: install Rust stable
|
||||||
|
uses: dtolnay/rust-toolchain@stable
|
||||||
|
- name: Build
|
||||||
|
run: |
|
||||||
|
cargo build --verbose --release
|
||||||
|
|
||||||
|
macos:
|
||||||
|
runs-on: macos-latest
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- name: install Rust stable
|
||||||
|
uses: dtolnay/rust-toolchain@stable
|
||||||
|
- name: Build
|
||||||
|
run: |
|
||||||
|
cargo build --verbose --release
|
||||||
|
|
||||||
|
windows:
|
||||||
|
runs-on: windows-latest
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- name: install Rust stable
|
||||||
|
uses: dtolnay/rust-toolchain@stable
|
||||||
|
- name: Build
|
||||||
|
run: |
|
||||||
|
cargo build --verbose --release
|
227
.github/workflows/create-release.yml
vendored
Normal file
227
.github/workflows/create-release.yml
vendored
Normal file
|
@ -0,0 +1,227 @@
|
||||||
|
name: Create Release
|
||||||
|
|
||||||
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
|
inputs:
|
||||||
|
release_type:
|
||||||
|
description: 'Type of release to create'
|
||||||
|
required: true
|
||||||
|
default: 'minor'
|
||||||
|
type: choice
|
||||||
|
options:
|
||||||
|
- patch
|
||||||
|
- minor
|
||||||
|
- major
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
|
||||||
|
bump-version:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
outputs:
|
||||||
|
new_version: ${{ steps.cargo-bump.outputs.new_version }}
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- name: Run semver-diff
|
||||||
|
if: inputs.release_type == ''
|
||||||
|
id: semver-diff
|
||||||
|
uses: tj-actions/semver-diff@v3
|
||||||
|
with:
|
||||||
|
initial_release_type: ${{ inputs.release_type }}
|
||||||
|
- name: Install stable toolchain
|
||||||
|
if: steps.semver-diff.outputs.release_type != '' || inputs.release_type != ''
|
||||||
|
uses: actions-rs/toolchain@v1
|
||||||
|
with:
|
||||||
|
profile: minimal
|
||||||
|
toolchain: stable
|
||||||
|
override: true
|
||||||
|
- uses: actions/cache@v4
|
||||||
|
if: steps.semver-diff.outputs.release_type != '' || inputs.release_type != ''
|
||||||
|
with:
|
||||||
|
path: |
|
||||||
|
~/.cargo/bin/
|
||||||
|
~/.cargo/registry/index/
|
||||||
|
~/.cargo/registry/cache/
|
||||||
|
~/.cargo/git/db/
|
||||||
|
key: ${{ runner.os }}-cargo-cargo-bump
|
||||||
|
- name: Bump Cargo.toml version
|
||||||
|
id: cargo-bump
|
||||||
|
shell: bash
|
||||||
|
if: steps.semver-diff.outputs.release_type != '' || inputs.release_type != ''
|
||||||
|
working-directory: '.'
|
||||||
|
run: |
|
||||||
|
if ! command -v cargo-bump &> /dev/null; then
|
||||||
|
cargo install cargo-bump --force
|
||||||
|
fi
|
||||||
|
cargo bump ${{ inputs.release_type }}
|
||||||
|
cargo update --workspace
|
||||||
|
echo "new_version=$(grep -m 1 -oP '(?<=version = ")[^"]+' Cargo.toml)" >> "$GITHUB_OUTPUT"
|
||||||
|
- name: Commit changes
|
||||||
|
uses: stefanzweifel/git-auto-commit-action@v4
|
||||||
|
with:
|
||||||
|
commit_message: "Bump version to v${{ steps.cargo-bump.outputs.new_version }}"
|
||||||
|
commit_user_name: "github-actions[bot]"
|
||||||
|
commit_user_email: "github-actions[bot]@users.noreply.github.com"
|
||||||
|
commit_author: "github-actions[bot] <github-actions[bot]@users.noreply.github.com>"
|
||||||
|
branch: master
|
||||||
|
tagging_message: v${{ steps.cargo-bump.outputs.new_version }}
|
||||||
|
|
||||||
|
release:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
needs: bump-version
|
||||||
|
steps:
|
||||||
|
- name: Checkout Code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
ref: v${{ needs.bump-version.outputs.new_version }}
|
||||||
|
- name: Update CHANGELOG
|
||||||
|
id: changelog
|
||||||
|
uses: requarks/changelog-action@v1
|
||||||
|
with:
|
||||||
|
token: ${{ github.token }}
|
||||||
|
tag: v${{ needs.bump-version.outputs.new_version }}
|
||||||
|
includeInvalidCommits: true
|
||||||
|
- name: Create Release
|
||||||
|
uses: ncipollo/release-action@v1
|
||||||
|
with:
|
||||||
|
allowUpdates: true
|
||||||
|
draft: false
|
||||||
|
makeLatest: true
|
||||||
|
name: v${{ needs.bump-version.outputs.new_version }}
|
||||||
|
body: ${{ steps.changelog.outputs.changes }}
|
||||||
|
token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
tag: v${{ needs.bump-version.outputs.new_version }}
|
||||||
|
- name: Commit CHANGELOG.md
|
||||||
|
uses: stefanzweifel/git-auto-commit-action@v4
|
||||||
|
with:
|
||||||
|
branch: master
|
||||||
|
commit_message: 'docs: update CHANGELOG.md for v${{ needs.bump-version.outputs.new_version }} [skip ci]'
|
||||||
|
file_pattern: CHANGELOG.md
|
||||||
|
|
||||||
|
linux:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
needs:
|
||||||
|
- release
|
||||||
|
- bump-version
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
with:
|
||||||
|
ref: v${{ needs.bump-version.outputs.new_version }}
|
||||||
|
- name: install Rust stable
|
||||||
|
uses: dtolnay/rust-toolchain@stable
|
||||||
|
- name: Build
|
||||||
|
run: |
|
||||||
|
cargo build --verbose --release
|
||||||
|
- name: Rename binary
|
||||||
|
run: |
|
||||||
|
mv target/release/spotify-dl target/release/spotify-dl.linux-x86_64
|
||||||
|
- name: Upload Linux Artifact
|
||||||
|
uses: ncipollo/release-action@v1
|
||||||
|
with:
|
||||||
|
allowUpdates: True
|
||||||
|
makeLatest: True
|
||||||
|
omitBody: True
|
||||||
|
omitBodyDuringUpdate: True
|
||||||
|
omitNameDuringUpdate: True
|
||||||
|
artifacts: target/release/spotify-dl.linux-x86_64
|
||||||
|
token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
tag: v${{ needs.bump-version.outputs.new_version }}
|
||||||
|
|
||||||
|
macos:
|
||||||
|
runs-on: macos-latest
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
needs:
|
||||||
|
- release
|
||||||
|
- bump-version
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
with:
|
||||||
|
ref: v${{ needs.bump-version.outputs.new_version }}
|
||||||
|
- name: install Rust stable
|
||||||
|
uses: dtolnay/rust-toolchain@stable
|
||||||
|
- name: Build
|
||||||
|
run: |
|
||||||
|
cargo build --verbose --release
|
||||||
|
- name: Rename binary
|
||||||
|
run: |
|
||||||
|
mv target/release/spotify-dl target/release/spotify-dl.macos-aarch64
|
||||||
|
- name: Upload MacOS Artifact
|
||||||
|
uses: ncipollo/release-action@v1
|
||||||
|
with:
|
||||||
|
allowUpdates: True
|
||||||
|
makeLatest: True
|
||||||
|
omitBody: True
|
||||||
|
omitBodyDuringUpdate: True
|
||||||
|
omitNameDuringUpdate: True
|
||||||
|
artifacts: target/release/spotify-dl.macos-aarch64
|
||||||
|
token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
tag: v${{ needs.bump-version.outputs.new_version }}
|
||||||
|
|
||||||
|
windows:
|
||||||
|
runs-on: windows-latest
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
needs:
|
||||||
|
- release
|
||||||
|
- bump-version
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
with:
|
||||||
|
ref: v${{ needs.bump-version.outputs.new_version }}
|
||||||
|
- name: install Rust stable
|
||||||
|
uses: dtolnay/rust-toolchain@stable
|
||||||
|
- name: Build
|
||||||
|
run: |
|
||||||
|
cargo build --verbose --release
|
||||||
|
- name: Rename binary
|
||||||
|
run: |
|
||||||
|
mv target/release/spotify-dl.exe target/release/spotify-dl.windows-x86_64
|
||||||
|
- name: Upload Windows Artifact
|
||||||
|
uses: ncipollo/release-action@v1
|
||||||
|
with:
|
||||||
|
allowUpdates: True
|
||||||
|
makeLatest: True
|
||||||
|
omitBody: True
|
||||||
|
omitBodyDuringUpdate: True
|
||||||
|
omitNameDuringUpdate: True
|
||||||
|
artifacts: target/release/spotify-dl.windows-x86_64
|
||||||
|
token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
tag: v${{ needs.bump-version.outputs.new_version }}
|
||||||
|
|
||||||
|
cargo:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
needs:
|
||||||
|
- bump-version
|
||||||
|
- release
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
with:
|
||||||
|
ref: v${{ needs.bump-version.outputs.new_version }}
|
||||||
|
- name: install Rust stable
|
||||||
|
uses: dtolnay/rust-toolchain@stable
|
||||||
|
- name: Build
|
||||||
|
run: |
|
||||||
|
cargo build --verbose --release
|
||||||
|
- name: Run cargo publish
|
||||||
|
run: |
|
||||||
|
cargo publish --token ${{ secrets.CARGO_TOKEN }}
|
||||||
|
|
||||||
|
homebrew:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
needs:
|
||||||
|
- bump-version
|
||||||
|
- release
|
||||||
|
steps:
|
||||||
|
- name: Update Hombrew formula
|
||||||
|
uses: dawidd6/action-homebrew-bump-formula@v3
|
||||||
|
with:
|
||||||
|
tap: guillemcastro/spotify-dl
|
||||||
|
formula: spotify-dl
|
||||||
|
token: ${{ secrets.HOMEBREW_TOKEN }}
|
||||||
|
tag: v${{ needs.bump-version.outputs.new_version }}
|
||||||
|
no_fork: true
|
||||||
|
|
46
.github/workflows/linux.yml
vendored
46
.github/workflows/linux.yml
vendored
|
@ -1,46 +0,0 @@
|
||||||
name: Build latest - Linux
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
tags:
|
|
||||||
- '*'
|
|
||||||
|
|
||||||
env:
|
|
||||||
CARGO_TERM_COLOR: always
|
|
||||||
|
|
||||||
permissions:
|
|
||||||
contents: write
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
|
|
||||||
build:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
strategy:
|
|
||||||
fail-fast: false
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v3
|
|
||||||
- name: Setup cmake
|
|
||||||
uses: jwlawson/actions-setup-cmake@v1.13
|
|
||||||
- name: install Rust stable
|
|
||||||
uses: dtolnay/rust-toolchain@stable
|
|
||||||
- name: Setup alsa
|
|
||||||
run: |
|
|
||||||
sudo apt-get update
|
|
||||||
sudo apt-get install -y libasound2-dev gcc alsa
|
|
||||||
- name: Build
|
|
||||||
run: |
|
|
||||||
cargo build --verbose --release
|
|
||||||
- name: Rename binary
|
|
||||||
run: |
|
|
||||||
mv target/release/spotify-dl target/release/spotify-dl.linux-x86_64
|
|
||||||
- name: Upload Linux Artifact
|
|
||||||
uses: ncipollo/release-action@v1
|
|
||||||
with:
|
|
||||||
allowUpdates: True
|
|
||||||
makeLatest: True
|
|
||||||
omitBody: True
|
|
||||||
omitBodyDuringUpdate: True
|
|
||||||
omitNameDuringUpdate: True
|
|
||||||
artifacts: target/release/spotify-dl.linux-x86_64
|
|
||||||
token: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
|
|
41
.github/workflows/macos.yml
vendored
41
.github/workflows/macos.yml
vendored
|
@ -1,41 +0,0 @@
|
||||||
name: Build latest - MacOS
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
tags:
|
|
||||||
- '*'
|
|
||||||
|
|
||||||
env:
|
|
||||||
CARGO_TERM_COLOR: always
|
|
||||||
|
|
||||||
permissions:
|
|
||||||
contents: write
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
|
|
||||||
build:
|
|
||||||
runs-on: macos-latest
|
|
||||||
strategy:
|
|
||||||
fail-fast: false
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v3
|
|
||||||
- name: Setup cmake
|
|
||||||
uses: jwlawson/actions-setup-cmake@v1.13
|
|
||||||
- name: install Rust stable
|
|
||||||
uses: dtolnay/rust-toolchain@stable
|
|
||||||
- name: Build
|
|
||||||
run: |
|
|
||||||
cargo build --verbose --release
|
|
||||||
- name: Rename binary
|
|
||||||
run: |
|
|
||||||
mv target/release/spotify-dl target/release/spotify-dl.macos-x86_64
|
|
||||||
- name: Upload MacOS Artifact
|
|
||||||
uses: ncipollo/release-action@v1
|
|
||||||
with:
|
|
||||||
allowUpdates: True
|
|
||||||
makeLatest: True
|
|
||||||
omitBody: True
|
|
||||||
omitBodyDuringUpdate: True
|
|
||||||
omitNameDuringUpdate: True
|
|
||||||
artifacts: target/release/spotify-dl.macos-x86_64
|
|
||||||
token: ${{ secrets.GITHUB_TOKEN }}
|
|
147
.github/workflows/release.yml
vendored
Normal file
147
.github/workflows/release.yml
vendored
Normal file
|
@ -0,0 +1,147 @@
|
||||||
|
name: Release
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
- '*'
|
||||||
|
|
||||||
|
env:
|
||||||
|
CARGO_TERM_COLOR: always
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
|
||||||
|
release:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
steps:
|
||||||
|
- name: Checkout Code
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
- name: Update CHANGELOG
|
||||||
|
id: changelog
|
||||||
|
uses: requarks/changelog-action@v1
|
||||||
|
with:
|
||||||
|
token: ${{ github.token }}
|
||||||
|
tag: ${{ github.ref_name }}
|
||||||
|
- name: Create Release
|
||||||
|
uses: ncipollo/release-action@v1
|
||||||
|
with:
|
||||||
|
allowUpdates: true
|
||||||
|
draft: false
|
||||||
|
makeLatest: true
|
||||||
|
name: ${{ github.ref_name }}
|
||||||
|
body: ${{ steps.changelog.outputs.changes }}
|
||||||
|
token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
tag: ${{ github.ref_name }}
|
||||||
|
- name: Commit CHANGELOG.md
|
||||||
|
uses: stefanzweifel/git-auto-commit-action@v4
|
||||||
|
with:
|
||||||
|
branch: master
|
||||||
|
commit_message: 'docs: update CHANGELOG.md for ${{ github.ref_name }} [skip ci]'
|
||||||
|
file_pattern: CHANGELOG.md
|
||||||
|
|
||||||
|
linux:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
needs: release
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- name: install Rust stable
|
||||||
|
uses: dtolnay/rust-toolchain@stable
|
||||||
|
- name: Build
|
||||||
|
run: |
|
||||||
|
cargo build --verbose --release
|
||||||
|
- name: Rename binary
|
||||||
|
run: |
|
||||||
|
mv target/release/spotify-dl target/release/spotify-dl.linux-x86_64
|
||||||
|
- name: Upload Linux Artifact
|
||||||
|
uses: ncipollo/release-action@v1
|
||||||
|
with:
|
||||||
|
allowUpdates: True
|
||||||
|
makeLatest: True
|
||||||
|
omitBody: True
|
||||||
|
omitBodyDuringUpdate: True
|
||||||
|
omitNameDuringUpdate: True
|
||||||
|
artifacts: target/release/spotify-dl.linux-x86_64
|
||||||
|
token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
|
macos:
|
||||||
|
runs-on: macos-latest
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
needs: release
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- name: install Rust stable
|
||||||
|
uses: dtolnay/rust-toolchain@stable
|
||||||
|
- name: Build
|
||||||
|
run: |
|
||||||
|
cargo build --verbose --release
|
||||||
|
- name: Rename binary
|
||||||
|
run: |
|
||||||
|
mv target/release/spotify-dl target/release/spotify-dl.macos-aarch64
|
||||||
|
- name: Upload MacOS Artifact
|
||||||
|
uses: ncipollo/release-action@v1
|
||||||
|
with:
|
||||||
|
allowUpdates: True
|
||||||
|
makeLatest: True
|
||||||
|
omitBody: True
|
||||||
|
omitBodyDuringUpdate: True
|
||||||
|
omitNameDuringUpdate: True
|
||||||
|
artifacts: target/release/spotify-dl.macos-aarch64
|
||||||
|
token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
|
windows:
|
||||||
|
runs-on: windows-latest
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
needs: release
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- name: install Rust stable
|
||||||
|
uses: dtolnay/rust-toolchain@stable
|
||||||
|
- name: Build
|
||||||
|
run: |
|
||||||
|
cargo build --verbose --release
|
||||||
|
- name: Rename binary
|
||||||
|
run: |
|
||||||
|
mv target/release/spotify-dl.exe target/release/spotify-dl.windows-x86_64
|
||||||
|
- name: Upload Windows Artifact
|
||||||
|
uses: ncipollo/release-action@v1
|
||||||
|
with:
|
||||||
|
allowUpdates: True
|
||||||
|
makeLatest: True
|
||||||
|
omitBody: True
|
||||||
|
omitBodyDuringUpdate: True
|
||||||
|
omitNameDuringUpdate: True
|
||||||
|
artifacts: target/release/spotify-dl.windows-x86_64
|
||||||
|
token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
|
cargo:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- name: install Rust stable
|
||||||
|
uses: dtolnay/rust-toolchain@stable
|
||||||
|
- name: Build
|
||||||
|
run: |
|
||||||
|
cargo build --verbose --release
|
||||||
|
- name: Run cargo publish
|
||||||
|
run: |
|
||||||
|
cargo publish --token ${{ secrets.CARGO_TOKEN }}
|
||||||
|
|
||||||
|
homebrew:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Update Hombrew formula
|
||||||
|
uses: dawidd6/action-homebrew-bump-formula@v3
|
||||||
|
with:
|
||||||
|
tap: guillemcastro/spotify-dl
|
||||||
|
formula: spotify-dl
|
||||||
|
token: ${{ secrets.HOMEBREW_TOKEN }}
|
||||||
|
tag: ${{ github.ref }}
|
||||||
|
no_fork: true
|
53
.github/workflows/rust-clippy.yml
vendored
Normal file
53
.github/workflows/rust-clippy.yml
vendored
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
# This workflow uses actions that are not certified by GitHub.
|
||||||
|
# They are provided by a third-party and are governed by
|
||||||
|
# separate terms of service, privacy policy, and support
|
||||||
|
# documentation.
|
||||||
|
# rust-clippy is a tool that runs a bunch of lints to catch common
|
||||||
|
# mistakes in your Rust code and help improve your Rust code.
|
||||||
|
# More details at https://github.com/rust-lang/rust-clippy
|
||||||
|
# and https://rust-lang.github.io/rust-clippy/
|
||||||
|
|
||||||
|
name: rust-clippy analyze
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [ "master" ]
|
||||||
|
pull_request:
|
||||||
|
# The branches below must be a subset of the branches above
|
||||||
|
branches: [ "master" ]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
rust-clippy-analyze:
|
||||||
|
name: Run rust-clippy analyzing
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
security-events: write
|
||||||
|
actions: read # only required for a private repository by github/codeql-action/upload-sarif to get the Action run status
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Install Rust toolchain
|
||||||
|
uses: actions-rs/toolchain@16499b5e05bf2e26879000db0c1d13f7e13fa3af #@v1
|
||||||
|
with:
|
||||||
|
profile: minimal
|
||||||
|
toolchain: stable
|
||||||
|
components: clippy
|
||||||
|
override: true
|
||||||
|
|
||||||
|
- name: Install required cargo
|
||||||
|
run: cargo install clippy-sarif sarif-fmt
|
||||||
|
|
||||||
|
- name: Run rust-clippy
|
||||||
|
run:
|
||||||
|
cargo clippy
|
||||||
|
--all-features
|
||||||
|
--message-format=json | clippy-sarif | tee rust-clippy-results.sarif | sarif-fmt
|
||||||
|
continue-on-error: true
|
||||||
|
|
||||||
|
- name: Upload analysis results to GitHub
|
||||||
|
uses: github/codeql-action/upload-sarif@v1
|
||||||
|
with:
|
||||||
|
sarif_file: rust-clippy-results.sarif
|
||||||
|
wait-for-processing: true
|
41
.github/workflows/windows.yml
vendored
41
.github/workflows/windows.yml
vendored
|
@ -1,41 +0,0 @@
|
||||||
name: Build latest - Windows
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
tags:
|
|
||||||
- '*'
|
|
||||||
|
|
||||||
env:
|
|
||||||
CARGO_TERM_COLOR: always
|
|
||||||
|
|
||||||
permissions:
|
|
||||||
contents: write
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
|
|
||||||
build:
|
|
||||||
runs-on: windows-latest
|
|
||||||
strategy:
|
|
||||||
fail-fast: false
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v3
|
|
||||||
- name: Setup cmake
|
|
||||||
uses: jwlawson/actions-setup-cmake@v1.13
|
|
||||||
- name: install Rust stable
|
|
||||||
uses: dtolnay/rust-toolchain@stable
|
|
||||||
- name: Build
|
|
||||||
run: |
|
|
||||||
cargo build --verbose --release
|
|
||||||
- name: Rename binary
|
|
||||||
run: |
|
|
||||||
mv target/release/spotify-dl.exe target/release/spotify-dl.windows-x86_64
|
|
||||||
- name: Upload Windows Artifact
|
|
||||||
uses: ncipollo/release-action@v1
|
|
||||||
with:
|
|
||||||
allowUpdates: True
|
|
||||||
makeLatest: True
|
|
||||||
omitBody: True
|
|
||||||
omitBodyDuringUpdate: True
|
|
||||||
omitNameDuringUpdate: True
|
|
||||||
artifacts: target/release/spotify-dl.windows-x86_64
|
|
||||||
token: ${{ secrets.GITHUB_TOKEN }}
|
|
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,6 +1,7 @@
|
||||||
/target
|
/target
|
||||||
.vscode
|
.vscode
|
||||||
*.flac
|
*.flac
|
||||||
|
*.mp3
|
||||||
bin
|
bin
|
||||||
|
|
||||||
debug/
|
debug/
|
||||||
|
|
11
CHANGELOG.md
Normal file
11
CHANGELOG.md
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
# Changelog
|
||||||
|
All notable changes to this project will be documented in this file.
|
||||||
|
|
||||||
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||||
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||||
|
|
||||||
|
## [v0.5.0] - 2024-05-17
|
||||||
|
### :sparkles: New Features
|
||||||
|
- [`ad9288d`](https://github.com/GuillemCastro/spotify-dl/commit/ad9288d243c393ea6c5b283de9c8ccd53de8ee0c) - No native dependencies *(commit by [@GuillemCastro](https://github.com/GuillemCastro))*
|
||||||
|
|
||||||
|
[v0.5.0]: https://github.com/GuillemCastro/spotify-dl/compare/v0.2.1...v0.5.0
|
1353
Cargo.lock
generated
1353
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
17
Cargo.toml
17
Cargo.toml
|
@ -1,18 +1,21 @@
|
||||||
[package]
|
[package]
|
||||||
name = "spotify-dl"
|
name = "spotify-dl"
|
||||||
version = "0.2.0"
|
version = "0.5.4"
|
||||||
authors = ["Guillem Castro <guillemcastro4@gmail.com>"]
|
authors = ["Guillem Castro <guillemcastro4@gmail.com>"]
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
|
homepage = "https://github.com/GuillemCastro/spotify-dl"
|
||||||
|
repository = "https://github.com/GuillemCastro/spotify-dl"
|
||||||
|
description = "A command-line utility to download songs and playlists from Spotify"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
structopt = { version = "0.3", default-features = false }
|
structopt = { version = "0.3", default-features = false }
|
||||||
rpassword = "7.0"
|
rpassword = "7.0"
|
||||||
indicatif = "0.17"
|
indicatif = "0.17"
|
||||||
librespot = "0.4.2"
|
librespot = { version = "0.4.2", default-features = false }
|
||||||
tokio = { version = "1", features = ["full", "tracing"] }
|
tokio = { version = "1", features = ["full", "tracing"] }
|
||||||
flac-bound = { version = "0.3.0", default-features = false, features = ["libflac-noogg"] }
|
flacenc = { version = "0.4" }
|
||||||
audiotags = "0.5"
|
audiotags = "0.5"
|
||||||
regex = "1.7.1"
|
regex = "1.7.1"
|
||||||
machine-uid = "0.5.1"
|
machine-uid = "0.5.1"
|
||||||
|
@ -22,6 +25,10 @@ tracing-subscriber = { version = "0.3", features = ["env-filter", "registry"] }
|
||||||
lazy_static = "1.4"
|
lazy_static = "1.4"
|
||||||
async-trait = "0.1"
|
async-trait = "0.1"
|
||||||
dirs = "5.0"
|
dirs = "5.0"
|
||||||
|
mp3lame-encoder = { version = "0.1.5", optional = true }
|
||||||
|
futures = "0.3"
|
||||||
|
rayon = "1.10"
|
||||||
|
|
||||||
[package.metadata.deb]
|
[features]
|
||||||
depends="libflac-dev"
|
default = ["mp3"]
|
||||||
|
mp3 = ["dep:mp3lame-encoder"]
|
||||||
|
|
40
README.md
40
README.md
|
@ -4,51 +4,57 @@ A command line utility to download songs, podcasts, playlists and albums directl
|
||||||
|
|
||||||
You need a Spotify Premium account.
|
You need a Spotify Premium account.
|
||||||
|
|
||||||
## Dependencies
|
## Installation
|
||||||
|
|
||||||
spotify-dl depends on libflac
|
You can install it using `cargo`, `homebrew` or from source.
|
||||||
|
|
||||||
### Debian-based distros
|
### Using `cargo`
|
||||||
|
|
||||||
```
|
```
|
||||||
sudo apt install libflac-dev libasound2-dev
|
cargo install spotify-dl
|
||||||
```
|
|
||||||
### Red Hat-based distros
|
|
||||||
|
|
||||||
```
|
|
||||||
sudo dnf install flac-devel alsa-lib-devel
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### MacOSX
|
### Using homebrew
|
||||||
|
|
||||||
```
|
```
|
||||||
brew install flac
|
brew tap guillemcastro/spotify-dl
|
||||||
|
brew install spotify-dl
|
||||||
|
```
|
||||||
|
|
||||||
|
### From source
|
||||||
|
|
||||||
|
```
|
||||||
|
git clone https://github.com/GuillemCastro/spotify-dl.git
|
||||||
|
cd spotify-dl
|
||||||
|
cargo build --release
|
||||||
|
cargo install --path .
|
||||||
```
|
```
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
```
|
```
|
||||||
spotify-dl 0.1.1
|
spotify-dl 0.2.0
|
||||||
A commandline utility to download music directly from Spotify
|
A commandline utility to download music directly from Spotify
|
||||||
|
|
||||||
USAGE:
|
USAGE:
|
||||||
spotify-dl [FLAGS] [OPTIONS] --username <username> [tracks]...
|
spotify-dl [OPTIONS] <tracks>... --username <username>
|
||||||
|
|
||||||
FLAGS:
|
FLAGS:
|
||||||
-h, --help Prints help information
|
-h, --help Prints help information
|
||||||
-o, --ordered Prefixing the filename with its index in the playlist
|
|
||||||
-V, --version Prints version information
|
-V, --version Prints version information
|
||||||
|
|
||||||
OPTIONS:
|
OPTIONS:
|
||||||
-c, --compression <compression> Setting the flac compression level from 0 (fastest, least compression) to
|
-c, --compression <compression> Setting the flac compression level from 0 (fastest, least compression) to
|
||||||
8 (slowest, most compression). A value larger than 8 will be Treated as 8.
|
8 (slowest, most compression). A value larger than 8 will be Treated as 8.
|
||||||
Default is 4.
|
Default is 4.
|
||||||
-d, --destination <destination> The directory where the songs will be downloaded [default: .]
|
-d, --destination <destination> The directory where the songs will be downloaded
|
||||||
|
-t, --parallel <parallel> Number of parallel downloads. Default is 5. [default: 5]
|
||||||
-p, --password <password> Your Spotify password
|
-p, --password <password> Your Spotify password
|
||||||
-u, --username <username> Your Spotify username
|
-u, --username <username> Your Spotify username
|
||||||
|
|
||||||
ARGS:
|
ARGS:
|
||||||
<tracks>... A list of Spotify URIs (songs, podcasts or playlists)```
|
<tracks>... A list of Spotify URIs or URLs (songs, podcasts, playlists or albums)
|
||||||
|
```
|
||||||
|
|
||||||
Songs, playlists and albums must be passed as Spotify URIs or URLs (e.g. `spotify:track:123456789abcdefghABCDEF` for songs and `spotify:playlist:123456789abcdefghABCDEF` for playlists or `https://open.spotify.com/playlist/123456789abcdefghABCDEF?si=1234567890`).
|
Songs, playlists and albums must be passed as Spotify URIs or URLs (e.g. `spotify:track:123456789abcdefghABCDEF` for songs and `spotify:playlist:123456789abcdefghABCDEF` for playlists or `https://open.spotify.com/playlist/123456789abcdefghABCDEF?si=1234567890`).
|
||||||
|
|
||||||
|
@ -58,4 +64,4 @@ The usage of this software may infringe Spotify's ToS and/or your local legislat
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
spotify-dl is lic:ewensed under the MIT license. See [LICENSE](LICENSE).
|
spotify-dl is licensed under the MIT license. See [LICENSE](LICENSE).
|
||||||
|
|
82
src/channel_sink.rs
Normal file
82
src/channel_sink.rs
Normal file
|
@ -0,0 +1,82 @@
|
||||||
|
use librespot::playback::audio_backend::Sink;
|
||||||
|
use librespot::playback::audio_backend::SinkError;
|
||||||
|
use librespot::playback::convert::Converter;
|
||||||
|
use librespot::playback::decoder::AudioPacket;
|
||||||
|
|
||||||
|
use crate::track::TrackMetadata;
|
||||||
|
|
||||||
|
pub enum SinkEvent {
|
||||||
|
Write { bytes: usize, total: usize, content: Vec<i32> },
|
||||||
|
Finished,
|
||||||
|
}
|
||||||
|
pub type SinkEventChannel = tokio::sync::mpsc::UnboundedReceiver<SinkEvent>;
|
||||||
|
|
||||||
|
pub struct ChannelSink {
|
||||||
|
sender: tokio::sync::mpsc::UnboundedSender<SinkEvent>,
|
||||||
|
bytes_total: usize,
|
||||||
|
bytes_sent: usize,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ChannelSink {
|
||||||
|
|
||||||
|
pub fn new(track: TrackMetadata) -> (Self, SinkEventChannel) {
|
||||||
|
let (tx, rx) = tokio::sync::mpsc::unbounded_channel();
|
||||||
|
|
||||||
|
(
|
||||||
|
ChannelSink {
|
||||||
|
sender: tx,
|
||||||
|
bytes_sent: 0,
|
||||||
|
bytes_total: Self::convert_track_duration_to_size(&track),
|
||||||
|
},
|
||||||
|
rx,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn convert_track_duration_to_size(metadata: &TrackMetadata) -> usize {
|
||||||
|
let duration = metadata.duration / 1000;
|
||||||
|
let sample_rate = 44100;
|
||||||
|
let channels = 2;
|
||||||
|
let bits_per_sample = 16;
|
||||||
|
let bytes_per_sample = bits_per_sample / 8;
|
||||||
|
(duration as usize) * sample_rate * channels * bytes_per_sample * 2
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_approximate_size(&self) -> usize {
|
||||||
|
self.bytes_total
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Sink for ChannelSink {
|
||||||
|
fn start(&mut self) -> Result<(), SinkError> {
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn stop(&mut self) -> Result<(), SinkError> {
|
||||||
|
tracing::info!("Finished sending song");
|
||||||
|
|
||||||
|
self.sender
|
||||||
|
.send(SinkEvent::Finished)
|
||||||
|
.map_err(|_| SinkError::OnWrite("Failed to send finished event".to_string()))?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn write(&mut self, packet: AudioPacket, converter: &mut Converter) -> Result<(), SinkError> {
|
||||||
|
let data = converter.f64_to_s16(
|
||||||
|
packet
|
||||||
|
.samples()
|
||||||
|
.map_err(|_| SinkError::OnWrite("Failed to get samples".to_string()))?,
|
||||||
|
);
|
||||||
|
let data32: Vec<i32> = data.iter().map(|el| i32::from(*el)).collect();
|
||||||
|
self.bytes_sent += data32.len() * std::mem::size_of::<i32>();
|
||||||
|
|
||||||
|
self.sender
|
||||||
|
.send(SinkEvent::Write {
|
||||||
|
bytes: self.bytes_sent,
|
||||||
|
total: self.bytes_total,
|
||||||
|
content: data32,
|
||||||
|
})
|
||||||
|
.map_err(|_| SinkError::OnWrite("Failed to send event".to_string()))?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,8 +1,10 @@
|
||||||
use std::fmt::Write;
|
use std::fmt::Write;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::sync::Arc;
|
use std::time::Duration;
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
|
use futures::StreamExt;
|
||||||
|
use futures::TryStreamExt;
|
||||||
use indicatif::MultiProgress;
|
use indicatif::MultiProgress;
|
||||||
use indicatif::ProgressBar;
|
use indicatif::ProgressBar;
|
||||||
use indicatif::ProgressState;
|
use indicatif::ProgressState;
|
||||||
|
@ -13,8 +15,10 @@ use librespot::playback::mixer::NoOpVolume;
|
||||||
use librespot::playback::mixer::VolumeGetter;
|
use librespot::playback::mixer::VolumeGetter;
|
||||||
use librespot::playback::player::Player;
|
use librespot::playback::player::Player;
|
||||||
|
|
||||||
use crate::file_sink::FileSink;
|
use crate::channel_sink::ChannelSink;
|
||||||
use crate::file_sink::SinkEvent;
|
use crate::encoder::Format;
|
||||||
|
use crate::encoder::Samples;
|
||||||
|
use crate::channel_sink::SinkEvent;
|
||||||
use crate::track::Track;
|
use crate::track::Track;
|
||||||
use crate::track::TrackMetadata;
|
use crate::track::TrackMetadata;
|
||||||
|
|
||||||
|
@ -29,16 +33,18 @@ pub struct DownloadOptions {
|
||||||
pub destination: PathBuf,
|
pub destination: PathBuf,
|
||||||
pub compression: Option<u32>,
|
pub compression: Option<u32>,
|
||||||
pub parallel: usize,
|
pub parallel: usize,
|
||||||
|
pub format: Format,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DownloadOptions {
|
impl DownloadOptions {
|
||||||
pub fn new(destination: Option<String>, compression: Option<u32>, parallel: usize) -> Self {
|
pub fn new(destination: Option<String>, compression: Option<u32>, parallel: usize, format: Format) -> Self {
|
||||||
let destination =
|
let destination =
|
||||||
destination.map_or_else(|| std::env::current_dir().unwrap(), PathBuf::from);
|
destination.map_or_else(|| std::env::current_dir().unwrap(), PathBuf::from);
|
||||||
DownloadOptions {
|
DownloadOptions {
|
||||||
destination,
|
destination,
|
||||||
compression,
|
compression,
|
||||||
parallel,
|
parallel,
|
||||||
|
format
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -57,23 +63,13 @@ impl Downloader {
|
||||||
tracks: Vec<Track>,
|
tracks: Vec<Track>,
|
||||||
options: &DownloadOptions,
|
options: &DownloadOptions,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let this = Arc::new(self);
|
futures::stream::iter(tracks)
|
||||||
|
.map(|track| {
|
||||||
let chunks = tracks.chunks(options.parallel);
|
self.download_track(track, options)
|
||||||
for chunk in chunks {
|
})
|
||||||
let mut tasks = Vec::new();
|
.buffer_unordered(options.parallel)
|
||||||
for track in chunk {
|
.try_collect::<Vec<_>>()
|
||||||
let t = track.clone();
|
.await?;
|
||||||
let downloader = this.clone();
|
|
||||||
let options = options.clone();
|
|
||||||
tasks.push(tokio::spawn(async move {
|
|
||||||
downloader.download_track(t, &options).await
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
for task in tasks {
|
|
||||||
task.await??;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -87,23 +83,24 @@ impl Downloader {
|
||||||
let path = options
|
let path = options
|
||||||
.destination
|
.destination
|
||||||
.join(file_name.clone())
|
.join(file_name.clone())
|
||||||
.with_extension("flac")
|
.with_extension(options.format.extension())
|
||||||
.to_str()
|
.to_str()
|
||||||
.ok_or(anyhow::anyhow!("Could not set the output path"))?
|
.ok_or(anyhow::anyhow!("Could not set the output path"))?
|
||||||
.to_string();
|
.to_string();
|
||||||
|
|
||||||
let (file_sink, mut sink_channel) = FileSink::new(path.to_string(), metadata);
|
let (sink, mut sink_channel) = ChannelSink::new(metadata);
|
||||||
|
|
||||||
let file_size = file_sink.get_approximate_size();
|
let file_size = sink.get_approximate_size();
|
||||||
|
|
||||||
let (mut player, _) = Player::new(
|
let (mut player, _) = Player::new(
|
||||||
self.player_config.clone(),
|
self.player_config.clone(),
|
||||||
self.session.clone(),
|
self.session.clone(),
|
||||||
self.volume_getter(),
|
self.volume_getter(),
|
||||||
move || Box::new(file_sink),
|
move || Box::new(sink),
|
||||||
);
|
);
|
||||||
|
|
||||||
let pb = self.progress_bar.add(ProgressBar::new(file_size as u64));
|
let pb = self.progress_bar.add(ProgressBar::new(file_size as u64));
|
||||||
|
pb.enable_steady_tick(Duration::from_millis(100));
|
||||||
pb.set_style(ProgressStyle::with_template("{spinner:.green} {msg} [{elapsed_precise}] [{wide_bar:.cyan/blue}] {bytes}/{total_bytes} ({eta})")?
|
pb.set_style(ProgressStyle::with_template("{spinner:.green} {msg} [{elapsed_precise}] [{wide_bar:.cyan/blue}] {bytes}/{total_bytes} ({eta})")?
|
||||||
.with_key("eta", |state: &ProgressState, w: &mut dyn Write| write!(w, "{:.1}s", state.eta().as_secs_f64()).unwrap())
|
.with_key("eta", |state: &ProgressState, w: &mut dyn Write| write!(w, "{:.1}s", state.eta().as_secs_f64()).unwrap())
|
||||||
.progress_chars("#>-"));
|
.progress_chars("#>-"));
|
||||||
|
@ -111,25 +108,38 @@ impl Downloader {
|
||||||
|
|
||||||
player.load(track.id, true, 0);
|
player.load(track.id, true, 0);
|
||||||
|
|
||||||
let name = file_name.clone();
|
let mut samples = Vec::<i32>::new();
|
||||||
|
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
while let Some(event) = sink_channel.recv().await {
|
player.await_end_of_track().await;
|
||||||
match event {
|
player.stop();
|
||||||
SinkEvent::Written { bytes, total } => {
|
|
||||||
tracing::trace!("Written {} bytes out of {}", bytes, total);
|
|
||||||
pb.set_position(bytes as u64);
|
|
||||||
}
|
|
||||||
SinkEvent::Finished => {
|
|
||||||
pb.finish_with_message(format!("Downloaded {}", name));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
player.await_end_of_track().await;
|
while let Some(event) = sink_channel.recv().await {
|
||||||
player.stop();
|
match event {
|
||||||
|
SinkEvent::Write { bytes, total, mut content } => {
|
||||||
|
tracing::trace!("Written {} bytes out of {}", bytes, total);
|
||||||
|
pb.set_position(bytes as u64);
|
||||||
|
samples.append(&mut content);
|
||||||
|
}
|
||||||
|
SinkEvent::Finished => {
|
||||||
|
tracing::info!("Finished downloading track: {:?}", file_name);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
tracing::info!("Downloaded track: {:?}", file_name);
|
tracing::info!("Encoding track: {:?}", file_name);
|
||||||
|
pb.set_message(format!("Encoding {}", &file_name));
|
||||||
|
let samples = Samples::new(samples, 44100, 2, 16);
|
||||||
|
let encoder = crate::encoder::get_encoder(options.format);
|
||||||
|
let stream = encoder.encode(samples).await?;
|
||||||
|
|
||||||
|
pb.set_message(format!("Writing {}", &file_name));
|
||||||
|
tracing::info!("Writing track: {:?} to file: {}", file_name, &path);
|
||||||
|
stream.write_to_file(&path).await?;
|
||||||
|
|
||||||
|
pb.finish_with_message(format!("Downloaded {}", &file_name));
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
52
src/encoder/flac.rs
Normal file
52
src/encoder/flac.rs
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
use flacenc::bitsink::ByteSink;
|
||||||
|
use flacenc::component::BitRepr;
|
||||||
|
use flacenc::error::Verify;
|
||||||
|
|
||||||
|
use super::execute_with_result;
|
||||||
|
use super::EncodedStream;
|
||||||
|
use super::Encoder;
|
||||||
|
use super::Samples;
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct FlacEncoder;
|
||||||
|
|
||||||
|
#[async_trait::async_trait]
|
||||||
|
impl Encoder for FlacEncoder {
|
||||||
|
async fn encode(&self, samples: Samples) -> anyhow::Result<EncodedStream> {
|
||||||
|
let source = flacenc::source::MemSource::from_samples(
|
||||||
|
&samples.samples,
|
||||||
|
samples.channels as usize,
|
||||||
|
samples.bits_per_sample as usize,
|
||||||
|
samples.sample_rate as usize,
|
||||||
|
);
|
||||||
|
|
||||||
|
let config = flacenc::config::Encoder::default()
|
||||||
|
.into_verified()
|
||||||
|
.map_err(|e| anyhow::anyhow!("Failed to verify encoder config: {:?}", e))?;
|
||||||
|
|
||||||
|
let (tx, rx) = tokio::sync::oneshot::channel();
|
||||||
|
|
||||||
|
rayon::spawn(execute_with_result(
|
||||||
|
move || {
|
||||||
|
let flac_stream = flacenc::encode_with_fixed_block_size(
|
||||||
|
&config,
|
||||||
|
source,
|
||||||
|
config.block_size,
|
||||||
|
)
|
||||||
|
.map_err(|e| anyhow::anyhow!("Failed to encode flac: {:?}", e))?;
|
||||||
|
|
||||||
|
let mut byte_sink = ByteSink::new();
|
||||||
|
flac_stream
|
||||||
|
.write(&mut byte_sink)
|
||||||
|
.map_err(|e| anyhow::anyhow!("Failed to write flac stream: {:?}", e))?;
|
||||||
|
|
||||||
|
Ok(byte_sink.into_inner())
|
||||||
|
},
|
||||||
|
tx,
|
||||||
|
));
|
||||||
|
|
||||||
|
let byte_sink: Vec<u8> = rx.await??;
|
||||||
|
|
||||||
|
Ok(EncodedStream::new(byte_sink))
|
||||||
|
}
|
||||||
|
}
|
111
src/encoder/mod.rs
Normal file
111
src/encoder/mod.rs
Normal file
|
@ -0,0 +1,111 @@
|
||||||
|
mod flac;
|
||||||
|
#[cfg(feature = "mp3")]
|
||||||
|
mod mp3;
|
||||||
|
|
||||||
|
use std::{path::Path, str::FromStr};
|
||||||
|
|
||||||
|
use anyhow::Result;
|
||||||
|
use tokio::sync::oneshot::Sender;
|
||||||
|
|
||||||
|
use self::{flac::FlacEncoder, mp3::Mp3Encoder};
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)]
|
||||||
|
pub enum Format {
|
||||||
|
Flac,
|
||||||
|
#[cfg(feature = "mp3")]
|
||||||
|
Mp3,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl FromStr for Format {
|
||||||
|
type Err = anyhow::Error;
|
||||||
|
|
||||||
|
fn from_str(s: &str) -> Result<Self> {
|
||||||
|
match s {
|
||||||
|
"flac" => Ok(Format::Flac),
|
||||||
|
#[cfg(feature = "mp3")]
|
||||||
|
"mp3" => Ok(Format::Mp3),
|
||||||
|
_ => Err(anyhow::anyhow!("Unsupported format")),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Format {
|
||||||
|
|
||||||
|
pub fn extension(&self) -> &'static str {
|
||||||
|
match self {
|
||||||
|
Format::Flac => "flac",
|
||||||
|
#[cfg(feature = "mp3")]
|
||||||
|
Format::Mp3 => "mp3",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
const FLAC_ENCODER: &FlacEncoder = &FlacEncoder;
|
||||||
|
#[cfg(feature = "mp3")]
|
||||||
|
const MP3_ENCODER: &Mp3Encoder = &Mp3Encoder;
|
||||||
|
|
||||||
|
pub fn get_encoder(format: Format) -> &'static dyn Encoder {
|
||||||
|
match format {
|
||||||
|
Format::Flac => FLAC_ENCODER,
|
||||||
|
#[cfg(feature = "mp3")]
|
||||||
|
Format::Mp3 => MP3_ENCODER,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[async_trait::async_trait]
|
||||||
|
pub trait Encoder {
|
||||||
|
async fn encode(&self, samples: Samples) -> Result<EncodedStream>;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct Samples {
|
||||||
|
pub samples: Vec<i32>,
|
||||||
|
pub sample_rate: u32,
|
||||||
|
pub channels: u32,
|
||||||
|
pub bits_per_sample: u32,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Samples {
|
||||||
|
pub fn new(samples: Vec<i32>, sample_rate: u32, channels: u32, bits_per_sample: u32) -> Self {
|
||||||
|
Samples {
|
||||||
|
samples,
|
||||||
|
sample_rate,
|
||||||
|
channels,
|
||||||
|
bits_per_sample,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct EncodedStream {
|
||||||
|
pub stream: Vec<u8>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl EncodedStream {
|
||||||
|
pub fn new(stream: Vec<u8>) -> Self {
|
||||||
|
EncodedStream { stream }
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn write_to_file<P: AsRef<Path>>(&self, path: P) -> Result<()> {
|
||||||
|
if !path.as_ref().exists() {
|
||||||
|
tokio::fs::create_dir_all(
|
||||||
|
path.as_ref()
|
||||||
|
.parent()
|
||||||
|
.ok_or(anyhow::anyhow!("Could not create path"))?,
|
||||||
|
).await?;
|
||||||
|
}
|
||||||
|
tokio::fs::write(path, &self.stream).await?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn execute_with_result<F, T>(func: F, tx: Sender<anyhow::Result<T>>) -> impl FnOnce()
|
||||||
|
where
|
||||||
|
F: FnOnce() -> anyhow::Result<T> + Send + 'static,
|
||||||
|
T: Send + 'static,
|
||||||
|
{
|
||||||
|
move || {
|
||||||
|
let result = func();
|
||||||
|
// Ignore the error if the receiver has been dropped
|
||||||
|
let _ = tx.send(result);
|
||||||
|
}
|
||||||
|
}
|
72
src/encoder/mp3.rs
Normal file
72
src/encoder/mp3.rs
Normal file
|
@ -0,0 +1,72 @@
|
||||||
|
use anyhow::anyhow;
|
||||||
|
use anyhow::Ok;
|
||||||
|
use mp3lame_encoder::Builder;
|
||||||
|
use mp3lame_encoder::FlushNoGap;
|
||||||
|
use mp3lame_encoder::InterleavedPcm;
|
||||||
|
|
||||||
|
use super::execute_with_result;
|
||||||
|
use super::EncodedStream;
|
||||||
|
use super::Encoder;
|
||||||
|
use super::Samples;
|
||||||
|
|
||||||
|
pub struct Mp3Encoder;
|
||||||
|
|
||||||
|
impl Mp3Encoder {
|
||||||
|
fn build_encoder(
|
||||||
|
&self,
|
||||||
|
sample_rate: u32,
|
||||||
|
channels: u32,
|
||||||
|
) -> anyhow::Result<mp3lame_encoder::Encoder> {
|
||||||
|
let mut builder = Builder::new().ok_or(anyhow::anyhow!("Failed to create mp3 encoder"))?;
|
||||||
|
|
||||||
|
builder
|
||||||
|
.set_sample_rate(sample_rate)
|
||||||
|
.map_err(|e| anyhow::anyhow!("Failed to set sample rate for mp3 encoder: {}", e))?;
|
||||||
|
builder.set_num_channels(channels as u8).map_err(|e| {
|
||||||
|
anyhow::anyhow!("Failed to set number of channels for mp3 encoder: {}", e)
|
||||||
|
})?;
|
||||||
|
builder
|
||||||
|
.set_brate(mp3lame_encoder::Birtate::Kbps160)
|
||||||
|
.map_err(|e| anyhow::anyhow!("Failed to set bitrate for mp3 encoder: {}", e))?;
|
||||||
|
|
||||||
|
builder
|
||||||
|
.build()
|
||||||
|
.map_err(|e| anyhow::anyhow!("Failed to build mp3 encoder: {}", e))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[async_trait::async_trait]
|
||||||
|
impl Encoder for Mp3Encoder {
|
||||||
|
async fn encode(&self, samples: Samples) -> anyhow::Result<EncodedStream> {
|
||||||
|
let mut mp3_encoder = self.build_encoder(samples.sample_rate, samples.channels)?;
|
||||||
|
|
||||||
|
let (tx, rx) = tokio::sync::oneshot::channel();
|
||||||
|
|
||||||
|
rayon::spawn(execute_with_result(
|
||||||
|
move || {
|
||||||
|
let samples: Vec<i16> = samples.samples.iter().map(|&x| x as i16).collect();
|
||||||
|
let input = InterleavedPcm(samples.as_slice());
|
||||||
|
let mut mp3_out_buffer = Vec::with_capacity(mp3lame_encoder::max_required_buffer_size(samples.len()));
|
||||||
|
let encoded_size = mp3_encoder
|
||||||
|
.encode(input, mp3_out_buffer.spare_capacity_mut())
|
||||||
|
.map_err(|e| anyhow!("Failed to encode mp3: {}", e))?;
|
||||||
|
unsafe {
|
||||||
|
mp3_out_buffer.set_len(mp3_out_buffer.len().wrapping_add(encoded_size));
|
||||||
|
}
|
||||||
|
|
||||||
|
let encoded_size = mp3_encoder
|
||||||
|
.flush::<FlushNoGap>(mp3_out_buffer.spare_capacity_mut())
|
||||||
|
.map_err(|e| anyhow!("Failed to flush mp3 encoder: {}", e))?;
|
||||||
|
unsafe {
|
||||||
|
mp3_out_buffer.set_len(mp3_out_buffer.len().wrapping_add(encoded_size));
|
||||||
|
}
|
||||||
|
Ok(mp3_out_buffer)
|
||||||
|
},
|
||||||
|
tx,
|
||||||
|
));
|
||||||
|
|
||||||
|
let mp3_out_buffer = rx.await??;
|
||||||
|
|
||||||
|
Ok(EncodedStream::new(mp3_out_buffer))
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,12 +2,15 @@ use std::path::Path;
|
||||||
|
|
||||||
use audiotags::Tag;
|
use audiotags::Tag;
|
||||||
use audiotags::TagType;
|
use audiotags::TagType;
|
||||||
|
use flacenc::component::BitRepr;
|
||||||
|
use flacenc::error::Verify;
|
||||||
use librespot::playback::audio_backend::Sink;
|
use librespot::playback::audio_backend::Sink;
|
||||||
use librespot::playback::audio_backend::SinkError;
|
use librespot::playback::audio_backend::SinkError;
|
||||||
use librespot::playback::convert::Converter;
|
use librespot::playback::convert::Converter;
|
||||||
use librespot::playback::decoder::AudioPacket;
|
use librespot::playback::decoder::AudioPacket;
|
||||||
use flac_bound::FlacEncoder;
|
|
||||||
|
|
||||||
|
use crate::encoder::get_encoder;
|
||||||
|
use crate::encoder::Samples;
|
||||||
use crate::track::TrackMetadata;
|
use crate::track::TrackMetadata;
|
||||||
|
|
||||||
pub enum SinkEvent {
|
pub enum SinkEvent {
|
||||||
|
@ -65,23 +68,43 @@ impl Sink for FileSink {
|
||||||
|
|
||||||
fn stop(&mut self) -> Result<(), SinkError> {
|
fn stop(&mut self) -> Result<(), SinkError> {
|
||||||
tracing::info!("Writing to file: {:?}", &self.sink);
|
tracing::info!("Writing to file: {:?}", &self.sink);
|
||||||
let mut encoder = FlacEncoder::new()
|
|
||||||
.ok_or(SinkError::OnWrite(
|
// let config = flacenc::config::Encoder::default()
|
||||||
"Failed to create flac encoder".to_string(),
|
// .into_verified()
|
||||||
))?
|
// .map_err(|_| SinkError::OnWrite("Failed to create flac encoder".to_string()))?;
|
||||||
.channels(2)
|
// let source = flacenc::source::MemSource::from_samples(&self.content, 2, 16, 44100);
|
||||||
.bits_per_sample(16)
|
// let flac_stream = flacenc::encode_with_fixed_block_size(&config, source, config.block_size)
|
||||||
.compression_level(self.compression)
|
// .map_err(|_| SinkError::OnWrite("Failed to encode flac".to_string()))?;
|
||||||
.init_file(&self.sink)
|
// let mut sink = flacenc::bitsink::ByteSink::new();
|
||||||
.map_err(|e| {
|
// flac_stream
|
||||||
SinkError::OnWrite(format!("Failed to init flac encoder: {:?}", e).to_string())
|
// .write(&mut sink)
|
||||||
})?;
|
// .map_err(|_| SinkError::OnWrite("Failed to write flac to sink".to_string()))?;
|
||||||
encoder
|
// std::fs::write(&self.sink, sink.as_slice())
|
||||||
.process_interleaved(self.content.as_slice(), (self.content.len() / 2) as u32)
|
// .map_err(|_| SinkError::OnWrite("Failed to write flac to file".to_string()))?;
|
||||||
.map_err(|_| SinkError::OnWrite("Failed to write flac".to_string()))?;
|
let flac_enc = get_encoder(crate::encoder::Format::Flac)
|
||||||
encoder
|
.map_err(|_| SinkError::OnWrite("Failed to get flac encoder".to_string()))?;
|
||||||
.finish()
|
let mp3_enc = get_encoder(crate::encoder::Format::Mp3)
|
||||||
.map_err(|_| SinkError::OnWrite("Failed to finish encondig".to_string()))?;
|
.map_err(|_| SinkError::OnWrite("Failed to get mp3 encoder".to_string()))?;
|
||||||
|
|
||||||
|
let flac_stream = flac_enc.encode(Samples::new(
|
||||||
|
self.content.clone(),
|
||||||
|
44100,
|
||||||
|
2,
|
||||||
|
16,
|
||||||
|
))
|
||||||
|
.map_err(|_| SinkError::OnWrite("Failed to encode flac".to_string()))?;
|
||||||
|
let mp3_stream = mp3_enc.encode(Samples::new(
|
||||||
|
self.content.clone(),
|
||||||
|
44100,
|
||||||
|
2,
|
||||||
|
16,
|
||||||
|
))
|
||||||
|
.map_err(|_| SinkError::OnWrite("Failed to encode mp3".to_string()))?;
|
||||||
|
|
||||||
|
flac_stream.write_to_file(&self.sink)
|
||||||
|
.map_err(|_| SinkError::OnWrite("Failed to write flac to file".to_string()))?;
|
||||||
|
mp3_stream.write_to_file(&self.sink)
|
||||||
|
.map_err(|_| SinkError::OnWrite("Failed to write mp3 to file".to_string()))?;
|
||||||
|
|
||||||
let mut tag = Tag::new()
|
let mut tag = Tag::new()
|
||||||
.with_tag_type(TagType::Flac)
|
.with_tag_type(TagType::Flac)
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
pub mod download;
|
pub mod download;
|
||||||
pub mod file_sink;
|
pub mod channel_sink;
|
||||||
pub mod session;
|
pub mod session;
|
||||||
pub mod track;
|
pub mod track;
|
||||||
|
pub mod encoder;
|
16
src/main.rs
16
src/main.rs
|
@ -1,4 +1,5 @@
|
||||||
use spotify_dl::download::{DownloadOptions, Downloader};
|
use spotify_dl::download::{DownloadOptions, Downloader};
|
||||||
|
use spotify_dl::encoder::Format;
|
||||||
use spotify_dl::session::create_session;
|
use spotify_dl::session::create_session;
|
||||||
use spotify_dl::track::get_tracks;
|
use spotify_dl::track::get_tracks;
|
||||||
use structopt::StructOpt;
|
use structopt::StructOpt;
|
||||||
|
@ -31,7 +32,7 @@ struct Opt {
|
||||||
short = "c",
|
short = "c",
|
||||||
long = "compression",
|
long = "compression",
|
||||||
help = "Setting the flac compression level from 0 (fastest, least compression) to
|
help = "Setting the flac compression level from 0 (fastest, least compression) to
|
||||||
8 (slowest, most compression). A value larger than 8 will be Treated as 8. Default is 4."
|
8 (slowest, most compression). A value larger than 8 will be Treated as 8. Default is 4. NOT USED."
|
||||||
)]
|
)]
|
||||||
compression: Option<u32>,
|
compression: Option<u32>,
|
||||||
#[structopt(
|
#[structopt(
|
||||||
|
@ -41,6 +42,13 @@ struct Opt {
|
||||||
default_value = "5"
|
default_value = "5"
|
||||||
)]
|
)]
|
||||||
parallel: usize,
|
parallel: usize,
|
||||||
|
#[structopt(
|
||||||
|
short = "f",
|
||||||
|
long = "format",
|
||||||
|
help = "The format to download the tracks in. Default is flac.",
|
||||||
|
default_value = "flac"
|
||||||
|
)]
|
||||||
|
format: Format
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn configure_logger() {
|
pub fn configure_logger() {
|
||||||
|
@ -72,6 +80,10 @@ async fn main() -> anyhow::Result<()> {
|
||||||
std::process::exit(1);
|
std::process::exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if opt.compression.is_some() {
|
||||||
|
eprintln!("Compression level is not supported yet. It will be ignored.");
|
||||||
|
}
|
||||||
|
|
||||||
let session = create_session(opt.username, opt.password).await?;
|
let session = create_session(opt.username, opt.password).await?;
|
||||||
|
|
||||||
let track = get_tracks(opt.tracks, &session).await?;
|
let track = get_tracks(opt.tracks, &session).await?;
|
||||||
|
@ -80,7 +92,7 @@ async fn main() -> anyhow::Result<()> {
|
||||||
downloader
|
downloader
|
||||||
.download_tracks(
|
.download_tracks(
|
||||||
track,
|
track,
|
||||||
&DownloadOptions::new(opt.destination, opt.compression, opt.parallel),
|
&DownloadOptions::new(opt.destination, opt.compression, opt.parallel, opt.format),
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@ trait TrackCollection {
|
||||||
pub async fn get_tracks(spotify_ids: Vec<String>, session: &Session) -> Result<Vec<Track>> {
|
pub async fn get_tracks(spotify_ids: Vec<String>, session: &Session) -> Result<Vec<Track>> {
|
||||||
let mut tracks: Vec<Track> = Vec::new();
|
let mut tracks: Vec<Track> = Vec::new();
|
||||||
for id in spotify_ids {
|
for id in spotify_ids {
|
||||||
|
tracing::debug!("Getting tracks for: {}", id);
|
||||||
let id = parse_uri_or_url(&id).ok_or(anyhow::anyhow!("Invalid track"))?;
|
let id = parse_uri_or_url(&id).ok_or(anyhow::anyhow!("Invalid track"))?;
|
||||||
let new_tracks = match id.audio_type {
|
let new_tracks = match id.audio_type {
|
||||||
librespot::core::spotify_id::SpotifyAudioType::Track => vec![Track::from_id(id)],
|
librespot::core::spotify_id::SpotifyAudioType::Track => vec![Track::from_id(id)],
|
||||||
|
@ -39,7 +40,9 @@ fn parse_uri_or_url(track: &str) -> Option<SpotifyId> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_uri(track_uri: &str) -> Option<SpotifyId> {
|
fn parse_uri(track_uri: &str) -> Option<SpotifyId> {
|
||||||
SpotifyId::from_uri(track_uri).ok()
|
let res = SpotifyId::from_uri(track_uri);
|
||||||
|
tracing::info!("Parsed URI: {:?}", res);
|
||||||
|
res.ok()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_url(track_url: &str) -> Option<SpotifyId> {
|
fn parse_url(track_url: &str) -> Option<SpotifyId> {
|
||||||
|
|
Loading…
Add table
Reference in a new issue