Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 2da2ea64ee | |||
| 7e52b8ab35 | |||
| 4b89a5e678 | |||
| c0677b3cb7 | |||
| 176e4566df | |||
| f319d0dcbb | |||
| 61c53655ff | |||
| 77bbc70c9b | |||
| 360ba44dd5 | |||
| 9011335181 | |||
| 3d0f21bf57 | |||
| b6fa1ec6a5 | |||
| 9bfe08cad0 |
+3
-3
@@ -14,9 +14,9 @@ async def get_metadata(page, headless=True):
|
||||
const [url, config] = args;
|
||||
if (url.includes('/api/load?url=%2Fapi%2Ffetch%2Fstream%2Fv2')) {
|
||||
const payload = JSON.parse(config.body);
|
||||
const title = document.querySelector('h1.svelte-6pt9ji').textContent;
|
||||
const title = document.querySelector('h1.svelte-6pt9ji').textContent.trim();
|
||||
const artists = Array.from(document.querySelectorAll('h2.svelte-6pt9ji a.normal'))
|
||||
.map(a => a.textContent)
|
||||
.map(a => a.textContent.trim())
|
||||
.join(', ');
|
||||
const cover = document.querySelector('.svelte-6pt9ji .meta.svelte-6pt9ji a').href;
|
||||
|
||||
@@ -96,4 +96,4 @@ async def main(headless=True):
|
||||
await browser.stop()
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
asyncio.run(main())
|
||||
|
||||
+8
-7
@@ -5,13 +5,15 @@ import asyncio
|
||||
from GetMetadata import main as get_metadata
|
||||
|
||||
class TrackDownloader:
|
||||
def __init__(self):
|
||||
def __init__(self, use_fallback=False):
|
||||
self.client = requests.Session()
|
||||
self.headers = {
|
||||
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36'
|
||||
}
|
||||
self.progress_callback = None
|
||||
self.filename_format = 'title_artist'
|
||||
self.use_fallback = use_fallback
|
||||
self.base_domain = "lucida.su" if use_fallback else "lucida.to"
|
||||
|
||||
def set_progress_callback(self, callback):
|
||||
self.progress_callback = callback
|
||||
@@ -66,7 +68,7 @@ class TrackDownloader:
|
||||
"url": track_url
|
||||
}
|
||||
|
||||
response = self.client.post("https://lucida.to/api/load?url=/api/fetch/stream/v2",
|
||||
response = self.client.post(f"https://{self.base_domain}/api/load?url=/api/fetch/stream/v2",
|
||||
json=initial_request,
|
||||
headers=self.headers)
|
||||
|
||||
@@ -84,7 +86,7 @@ class TrackDownloader:
|
||||
|
||||
file_name = self.generate_filename(metadata)
|
||||
|
||||
completion_url = f"https://{server}.lucida.to/api/fetch/request/{handoff}"
|
||||
completion_url = f"https://{server}.{self.base_domain}/api/fetch/request/{handoff}"
|
||||
|
||||
print("Waiting for track processing to complete")
|
||||
while True:
|
||||
@@ -95,7 +97,7 @@ class TrackDownloader:
|
||||
raise Exception(f"API request failed: {completion_response.get('message', 'Unknown error')}")
|
||||
time.sleep(1)
|
||||
|
||||
download_url = f"https://{server}.lucida.to/api/fetch/request/{handoff}/download"
|
||||
download_url = f"https://{server}.{self.base_domain}/api/fetch/request/{handoff}/download"
|
||||
print(f"Starting download of: {file_name}")
|
||||
|
||||
response = self.client.get(download_url, stream=True, headers=self.headers)
|
||||
@@ -111,8 +113,7 @@ class TrackDownloader:
|
||||
file.write(chunk)
|
||||
downloaded_size += len(chunk)
|
||||
if self.progress_callback:
|
||||
progress = int((downloaded_size / total_size) * 100) if total_size > 0 else 0
|
||||
self.progress_callback(progress)
|
||||
self.progress_callback(downloaded_size, total_size)
|
||||
|
||||
if downloaded_size == 0:
|
||||
raise Exception("No data received from server")
|
||||
@@ -139,4 +140,4 @@ async def main():
|
||||
print(f"An error occurred: {str(e)}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
asyncio.run(main())
|
||||
|
||||
@@ -1,26 +1,32 @@
|
||||
[](https://github.com/afkarxyz/SpotifyFLAC/releases)
|
||||
|
||||
**Spotify FLAC** allows you to download Spotify tracks in true, lossless FLAC format, providing the highest audio quality for an exceptional listening experience.
|
||||
**Spotify FLAC** allows you to download Spotify tracks in true FLAC format through services like Tidal, Amazon Music, Qobuz, and Deezer with the help of Lucida.
|
||||
|
||||
> [!NOTE]
|
||||
> Requires **Google Chrome**
|
||||
|
||||
#### [Download](https://github.com/afkarxyz/SpotifyFLAC/releases/download/v1.0/SpotifyFLAC.exe) Spotify FLAC
|
||||
> [!WARNING]
|
||||
Sometimes, the **download speed** from Lucida can be fast or slow; it varies unpredictably.
|
||||
|
||||
#### [Download](https://github.com/afkarxyz/SpotifyFLAC/releases/download/v1.3/SpotifyFLAC.exe) Spotify FLAC
|
||||
|
||||
## Screenshots
|
||||
|
||||

|
||||

|
||||
|
||||

|
||||
> - When **Headless** is enabled, the browser runs in the background without a graphical interface, improving performance and allowing seamless automation.
|
||||
> - When **Fallback** is enabled, it will use the backup server Lucida.su
|
||||
> - **Filename: Title** means the filename format is `Title - Artist`, and vice versa.
|
||||
> - I highly recommend **Tidal** or **Amazon Music** because `Qobuz` and `Deezer` occasionally experience issues.
|
||||
|
||||

|
||||

|
||||
|
||||
> When **Headless** is enabled, the browser runs in the background without a graphical interface, improving performance and allowing seamless automation.
|
||||

|
||||
|
||||
## Lossless Audio Check
|
||||
|
||||

|
||||

|
||||
|
||||

|
||||

|
||||
|
||||
#### [Download](https://github.com/afkarxyz/SpotifyFLAC/releases/download/v0/FLAC-Checker.zip) FLAC Checker
|
||||
|
||||
+123
-17
@@ -1,12 +1,13 @@
|
||||
import sys
|
||||
import asyncio
|
||||
import os
|
||||
import time
|
||||
from pathlib import Path
|
||||
from PyQt6.QtWidgets import (QApplication, QMainWindow, QWidget, QVBoxLayout,
|
||||
QHBoxLayout, QLabel, QLineEdit, QPushButton,
|
||||
QProgressBar, QFileDialog, QCheckBox, QRadioButton,
|
||||
QGroupBox)
|
||||
from PyQt6.QtCore import QThread, pyqtSignal, Qt, QSettings
|
||||
QGroupBox, QComboBox)
|
||||
from PyQt6.QtCore import QThread, pyqtSignal, Qt, QSettings, QSize
|
||||
from PyQt6.QtGui import QIcon, QPixmap, QCursor
|
||||
from GetMetadata import get_metadata
|
||||
from LucidaDownloader import TrackDownloader
|
||||
@@ -28,10 +29,12 @@ class MetadataFetcher(QThread):
|
||||
finished = pyqtSignal(dict)
|
||||
error = pyqtSignal(str)
|
||||
|
||||
def __init__(self, url, headless=True):
|
||||
def __init__(self, url, headless=True, service="tidal", use_fallback=False):
|
||||
super().__init__()
|
||||
self.url = url
|
||||
self.headless_mode = headless
|
||||
self.service = service
|
||||
self.use_fallback = use_fallback
|
||||
self.max_retries = 3
|
||||
|
||||
def extract_track_id(self, url):
|
||||
@@ -43,9 +46,11 @@ class MetadataFetcher(QThread):
|
||||
import zendriver as zd
|
||||
from asyncio import sleep
|
||||
|
||||
domain = "lucida.su" if self.use_fallback else "lucida.to"
|
||||
|
||||
for attempt in range(self.max_retries):
|
||||
try:
|
||||
lucida_url = f"https://lucida.to/?url=https%3A%2F%2Fopen.spotify.com%2Ftrack%2F{track_id}&country=auto&to=tidal"
|
||||
lucida_url = f"https://{domain}/?url=https%3A%2F%2Fopen.spotify.com%2Ftrack%2F{track_id}&country=auto&to={self.service}"
|
||||
browser = await zd.start(headless=self.headless_mode)
|
||||
try:
|
||||
page = await browser.get(lucida_url)
|
||||
@@ -82,19 +87,45 @@ class MetadataFetcher(QThread):
|
||||
|
||||
class DownloaderWorker(QThread):
|
||||
progress = pyqtSignal(int)
|
||||
status = pyqtSignal(str)
|
||||
finished = pyqtSignal(str)
|
||||
error = pyqtSignal(str)
|
||||
|
||||
def __init__(self, metadata, output_dir, filename_format='title_artist'):
|
||||
def __init__(self, metadata, output_dir, filename_format='title_artist', use_fallback=False):
|
||||
super().__init__()
|
||||
self.metadata = metadata
|
||||
self.output_dir = output_dir
|
||||
self.filename_format = filename_format
|
||||
self.downloader = TrackDownloader()
|
||||
self.use_fallback = use_fallback
|
||||
self.downloader = TrackDownloader(use_fallback=use_fallback)
|
||||
self.last_update_time = 0
|
||||
self.last_downloaded_size = 0
|
||||
|
||||
def format_size(self, size_bytes):
|
||||
return f"{size_bytes / (1024 * 1024):.2f}MB"
|
||||
|
||||
def format_speed(self, speed_bytes):
|
||||
return f"{speed_bytes * 8 / (1024 * 1024):.2f}Mbps"
|
||||
|
||||
def progress_callback(self, downloaded_size, total_size):
|
||||
current_time = time.time()
|
||||
if current_time - self.last_update_time >= 0.5:
|
||||
progress = int((downloaded_size / total_size) * 100) if total_size > 0 else 0
|
||||
self.progress.emit(progress)
|
||||
|
||||
time_diff = current_time - self.last_update_time
|
||||
if time_diff > 0:
|
||||
speed = (downloaded_size - self.last_downloaded_size) / time_diff
|
||||
status = f"Downloading... {self.format_size(downloaded_size)}/{self.format_size(total_size)} | {self.format_speed(speed)}"
|
||||
self.status.emit(status)
|
||||
|
||||
self.last_update_time = current_time
|
||||
self.last_downloaded_size = downloaded_size
|
||||
|
||||
def run(self):
|
||||
try:
|
||||
self.downloader.set_progress_callback(self.progress.emit)
|
||||
self.status.emit("Preparing...")
|
||||
self.downloader.set_progress_callback(self.progress_callback)
|
||||
self.downloader.set_filename_format(self.filename_format)
|
||||
self.progress.emit(0)
|
||||
downloaded_file = self.downloader.download(self.metadata, self.output_dir)
|
||||
@@ -103,6 +134,39 @@ class DownloaderWorker(QThread):
|
||||
except Exception as e:
|
||||
self.error.emit(f"Error: {str(e)}")
|
||||
|
||||
class ServiceComboBox(QComboBox):
|
||||
def __init__(self, parent=None):
|
||||
super().__init__(parent)
|
||||
self.setIconSize(QSize(16, 16))
|
||||
self.setup_items()
|
||||
|
||||
def setup_items(self):
|
||||
current_dir = os.path.dirname(os.path.abspath(__file__))
|
||||
icons_dir = os.path.join(current_dir, 'icons')
|
||||
|
||||
if not os.path.exists(icons_dir):
|
||||
os.makedirs(icons_dir)
|
||||
|
||||
services = [
|
||||
{'id': 'tidal', 'name': 'Tidal', 'icon': 'tidal.png'},
|
||||
{'id': 'amazon', 'name': 'Amazon Music', 'icon': 'amazon.png'},
|
||||
{'id': 'qobuz', 'name': 'Qobuz', 'icon': 'qobuz.png'},
|
||||
{'id': 'deezer', 'name': 'Deezer', 'icon': 'deezer.png'}
|
||||
]
|
||||
|
||||
for service in services:
|
||||
icon_path = os.path.join(icons_dir, service['icon'])
|
||||
if not os.path.exists(icon_path):
|
||||
self.create_placeholder_icon(icon_path)
|
||||
|
||||
icon = QIcon(icon_path)
|
||||
self.addItem(icon, service['name'], service['id'])
|
||||
|
||||
def create_placeholder_icon(self, path):
|
||||
pixmap = QPixmap(16, 16)
|
||||
pixmap.fill(Qt.GlobalColor.transparent)
|
||||
pixmap.save(path)
|
||||
|
||||
class SpotifyFlacGUI(QMainWindow):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
@@ -128,9 +192,19 @@ class SpotifyFlacGUI(QMainWindow):
|
||||
|
||||
def load_settings(self):
|
||||
headless = self.settings.value('headless', True, type=bool)
|
||||
fallback = self.settings.value('fallback', False, type=bool)
|
||||
service = self.settings.value('service', 'tidal')
|
||||
format_type = self.settings.value('format', 'title_artist')
|
||||
output_dir = self.settings.value('output_dir', self.default_music_dir)
|
||||
|
||||
self.headless_checkbox.setChecked(headless)
|
||||
self.fallback_checkbox.setChecked(fallback)
|
||||
|
||||
for i in range(self.service_combo.count()):
|
||||
if self.service_combo.itemData(i) == service:
|
||||
self.service_combo.setCurrentIndex(i)
|
||||
break
|
||||
|
||||
self.format_title_artist.setChecked(format_type == 'title_artist')
|
||||
self.format_artist_title.setChecked(format_type == 'artist_title')
|
||||
self.dir_input.setText(output_dir)
|
||||
@@ -138,6 +212,10 @@ class SpotifyFlacGUI(QMainWindow):
|
||||
def setup_settings_persistence(self):
|
||||
self.headless_checkbox.stateChanged.connect(
|
||||
lambda x: self.settings.setValue('headless', bool(x)))
|
||||
self.fallback_checkbox.stateChanged.connect(
|
||||
lambda x: self.settings.setValue('fallback', bool(x)))
|
||||
self.service_combo.currentIndexChanged.connect(
|
||||
lambda i: self.settings.setValue('service', self.service_combo.itemData(i)))
|
||||
self.format_title_artist.toggled.connect(
|
||||
lambda x: self.settings.setValue('format', 'title_artist' if x else 'artist_title'))
|
||||
self.dir_input.textChanged.connect(
|
||||
@@ -185,26 +263,45 @@ class SpotifyFlacGUI(QMainWindow):
|
||||
settings_group = QGroupBox("Settings")
|
||||
settings_layout = QHBoxLayout(settings_group)
|
||||
settings_layout.setContentsMargins(10, 0, 10, 10)
|
||||
settings_layout.setSpacing(20)
|
||||
settings_layout.setSpacing(10)
|
||||
|
||||
settings_container = QWidget()
|
||||
settings_container_layout = QHBoxLayout(settings_container)
|
||||
settings_container_layout.setContentsMargins(0, 0, 0, 0)
|
||||
settings_container_layout.setSpacing(20)
|
||||
settings_container_layout.setSpacing(10)
|
||||
|
||||
self.headless_checkbox = QCheckBox("Headless")
|
||||
self.headless_checkbox.setCursor(QCursor(Qt.CursorShape.PointingHandCursor))
|
||||
self.headless_checkbox.setChecked(True)
|
||||
settings_container_layout.addWidget(self.headless_checkbox)
|
||||
|
||||
self.fallback_checkbox = QCheckBox("Fallback")
|
||||
self.fallback_checkbox.setCursor(QCursor(Qt.CursorShape.PointingHandCursor))
|
||||
self.fallback_checkbox.setChecked(False)
|
||||
settings_container_layout.addWidget(self.fallback_checkbox)
|
||||
|
||||
service_widget = QWidget()
|
||||
service_layout = QHBoxLayout(service_widget)
|
||||
service_layout.setContentsMargins(0, 0, 0, 0)
|
||||
service_layout.setSpacing(10)
|
||||
|
||||
service_label = QLabel("Service:")
|
||||
self.service_combo = ServiceComboBox()
|
||||
self.service_combo.setCursor(QCursor(Qt.CursorShape.PointingHandCursor))
|
||||
|
||||
service_layout.addWidget(service_label)
|
||||
service_layout.addWidget(self.service_combo)
|
||||
|
||||
settings_container_layout.addWidget(service_widget)
|
||||
|
||||
format_widget = QWidget()
|
||||
format_layout = QHBoxLayout(format_widget)
|
||||
format_layout.setContentsMargins(0, 0, 0, 0)
|
||||
format_layout.setSpacing(15)
|
||||
format_layout.setSpacing(10)
|
||||
|
||||
format_label = QLabel("Filename Format:")
|
||||
self.format_title_artist = QRadioButton("Title - Artist")
|
||||
self.format_artist_title = QRadioButton("Artist - Title")
|
||||
format_label = QLabel("Filename:")
|
||||
self.format_title_artist = QRadioButton("Title")
|
||||
self.format_artist_title = QRadioButton("Artist")
|
||||
self.format_title_artist.setCursor(QCursor(Qt.CursorShape.PointingHandCursor))
|
||||
self.format_artist_title.setCursor(QCursor(Qt.CursorShape.PointingHandCursor))
|
||||
self.format_title_artist.setChecked(True)
|
||||
@@ -323,7 +420,9 @@ class SpotifyFlacGUI(QMainWindow):
|
||||
self.fetch_button.setEnabled(False)
|
||||
self.status_label.setText("Fetching track information...")
|
||||
headless = self.headless_checkbox.isChecked()
|
||||
self.fetcher = MetadataFetcher(url, headless=headless)
|
||||
fallback = self.fallback_checkbox.isChecked()
|
||||
service = self.service_combo.currentData()
|
||||
self.fetcher = MetadataFetcher(url, headless=headless, service=service, use_fallback=fallback)
|
||||
self.fetcher.finished.connect(self.handle_track_info)
|
||||
self.fetcher.error.connect(self.handle_fetch_error)
|
||||
self.fetcher.start()
|
||||
@@ -415,20 +514,27 @@ class SpotifyFlacGUI(QMainWindow):
|
||||
self.cancel_button.hide()
|
||||
self.progress_bar.show()
|
||||
self.progress_bar.setValue(0)
|
||||
self.status_label.setText("Downloading...")
|
||||
self.status_label.setText("Preparing...")
|
||||
|
||||
format_type = 'artist_title' if self.format_artist_title.isChecked() else 'title_artist'
|
||||
fallback = self.fallback_checkbox.isChecked()
|
||||
|
||||
self.worker = DownloaderWorker(
|
||||
metadata=self.metadata,
|
||||
output_dir=output_dir,
|
||||
filename_format=format_type
|
||||
filename_format=format_type,
|
||||
use_fallback=fallback
|
||||
)
|
||||
|
||||
self.worker.progress.connect(self.update_progress)
|
||||
self.worker.status.connect(self.update_status)
|
||||
self.worker.finished.connect(self.download_finished)
|
||||
self.worker.error.connect(self.download_error)
|
||||
self.worker.start()
|
||||
|
||||
def update_status(self, status):
|
||||
self.status_label.setText(status)
|
||||
|
||||
def update_progress(self, value):
|
||||
self.progress_bar.setValue(value)
|
||||
|
||||
@@ -457,4 +563,4 @@ def main():
|
||||
sys.exit(app.exec())
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user