Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 13567802a0 | |||
| d704782519 | |||
| 884c02278f | |||
| d6abe2bae3 | |||
| 7b858dd0ce | |||
| cfeb9a2ef2 |
@@ -6,7 +6,7 @@
|
|||||||
<b>SpotiFLAC</b> allows you to download Spotify tracks in true FLAC format through services like Tidal, Amazon Music and Deezer with the help of Lucida.
|
<b>SpotiFLAC</b> allows you to download Spotify tracks in true FLAC format through services like Tidal, Amazon Music and Deezer with the help of Lucida.
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
### [Download](https://github.com/afkarxyz/SpotiFLAC/releases/download/v1.9/SpotiFLAC.exe)
|
### [Download](https://github.com/afkarxyz/SpotiFLAC/releases/download/v2.0/SpotiFLAC.exe)
|
||||||
|
|
||||||
#
|
#
|
||||||
|
|
||||||
|
|||||||
+19
-11
@@ -1,8 +1,8 @@
|
|||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
|
import requests
|
||||||
import time
|
import time
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import requests
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from packaging import version
|
from packaging import version
|
||||||
from PyQt6.QtWidgets import (QApplication, QMainWindow, QWidget, QVBoxLayout,
|
from PyQt6.QtWidgets import (QApplication, QMainWindow, QWidget, QVBoxLayout,
|
||||||
@@ -37,12 +37,20 @@ class MetadataFetcher(QThread):
|
|||||||
self.service = service
|
self.service = service
|
||||||
self.use_fallback = use_fallback
|
self.use_fallback = use_fallback
|
||||||
self.max_retries = 3
|
self.max_retries = 3
|
||||||
|
self.downloader = TrackDownloader(use_fallback=use_fallback)
|
||||||
|
|
||||||
def extract_track_id(self, url):
|
def extract_track_id(self, url):
|
||||||
if "track/" in url:
|
if "track/" in url:
|
||||||
return url.split("track/")[1].split("?")[0].split("/")[0]
|
return url.split("track/")[1].split("?")[0].split("/")[0]
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
async def get_track_info_async(self, track_id, service, use_fallback):
|
||||||
|
try:
|
||||||
|
metadata = await self.downloader.get_track_info(track_id, service, use_fallback)
|
||||||
|
return metadata
|
||||||
|
except Exception as e:
|
||||||
|
raise e
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
try:
|
try:
|
||||||
track_id = self.extract_track_id(self.url)
|
track_id = self.extract_track_id(self.url)
|
||||||
@@ -50,15 +58,12 @@ class MetadataFetcher(QThread):
|
|||||||
self.error.emit("Invalid Spotify URL")
|
self.error.emit("Invalid Spotify URL")
|
||||||
return
|
return
|
||||||
|
|
||||||
fallback = "su" if self.use_fallback else "to"
|
import asyncio
|
||||||
api_url = f"https://apislucida.vercel.app/{fallback}/{track_id}/{self.service}"
|
|
||||||
|
|
||||||
for attempt in range(self.max_retries):
|
for attempt in range(self.max_retries):
|
||||||
try:
|
try:
|
||||||
response = requests.get(api_url)
|
metadata = asyncio.run(self.get_track_info_async(
|
||||||
response.raise_for_status()
|
track_id, self.service, self.use_fallback))
|
||||||
|
|
||||||
metadata = response.json()
|
|
||||||
formatted_metadata = {
|
formatted_metadata = {
|
||||||
'title': metadata['title'],
|
'title': metadata['title'],
|
||||||
'artists': metadata['artists'],
|
'artists': metadata['artists'],
|
||||||
@@ -72,7 +77,7 @@ class MetadataFetcher(QThread):
|
|||||||
self.finished.emit(formatted_metadata)
|
self.finished.emit(formatted_metadata)
|
||||||
return
|
return
|
||||||
|
|
||||||
except requests.exceptions.RequestException as e:
|
except Exception as e:
|
||||||
if attempt < self.max_retries - 1:
|
if attempt < self.max_retries - 1:
|
||||||
time.sleep(2 * (attempt + 1))
|
time.sleep(2 * (attempt + 1))
|
||||||
continue
|
continue
|
||||||
@@ -130,6 +135,9 @@ class DownloaderWorker(QThread):
|
|||||||
time_diff = current_time - self.last_update_time
|
time_diff = current_time - self.last_update_time
|
||||||
if time_diff > 0:
|
if time_diff > 0:
|
||||||
speed = (downloaded_size - self.last_downloaded_size) / time_diff
|
speed = (downloaded_size - self.last_downloaded_size) / time_diff
|
||||||
|
if downloaded_size == 0 and total_size == 0:
|
||||||
|
status = "Preparing metadata..."
|
||||||
|
else:
|
||||||
status = f"Downloading... {self.format_size(downloaded_size)}/{self.format_size(total_size)} | {self.format_speed(speed)}"
|
status = f"Downloading... {self.format_size(downloaded_size)}/{self.format_size(total_size)} | {self.format_speed(speed)}"
|
||||||
self.status.emit(status)
|
self.status.emit(status)
|
||||||
|
|
||||||
@@ -303,7 +311,7 @@ class UpdateDialog(QDialog):
|
|||||||
class SpotiFlacGUI(QMainWindow):
|
class SpotiFlacGUI(QMainWindow):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.current_version = "1.9"
|
self.current_version = "2.1"
|
||||||
self.settings = QSettings('SpotiFlac', 'Settings')
|
self.settings = QSettings('SpotiFlac', 'Settings')
|
||||||
self.setWindowTitle("SpotiFLAC")
|
self.setWindowTitle("SpotiFLAC")
|
||||||
self.check_for_updates = self.settings.value('check_for_updates', True, type=bool)
|
self.check_for_updates = self.settings.value('check_for_updates', True, type=bool)
|
||||||
@@ -362,7 +370,7 @@ class SpotiFlacGUI(QMainWindow):
|
|||||||
self.fallback_checkbox.setChecked(fallback)
|
self.fallback_checkbox.setChecked(fallback)
|
||||||
|
|
||||||
for i in range(self.service_combo.count()):
|
for i in range(self.service_combo.count()):
|
||||||
if self.service_combo.itemData(i) == service:
|
if self.service_combo.itemData(i, Qt.ItemDataRole.UserRole + 1) == service:
|
||||||
self.service_combo.setCurrentIndex(i)
|
self.service_combo.setCurrentIndex(i)
|
||||||
break
|
break
|
||||||
|
|
||||||
@@ -374,7 +382,7 @@ class SpotiFlacGUI(QMainWindow):
|
|||||||
self.fallback_checkbox.stateChanged.connect(
|
self.fallback_checkbox.stateChanged.connect(
|
||||||
lambda x: self.settings.setValue('fallback', bool(x)))
|
lambda x: self.settings.setValue('fallback', bool(x)))
|
||||||
self.service_combo.currentIndexChanged.connect(
|
self.service_combo.currentIndexChanged.connect(
|
||||||
lambda i: self.settings.setValue('service', self.service_combo.itemData(i)))
|
lambda i: self.settings.setValue('service', self.service_combo.itemData(i, Qt.ItemDataRole.UserRole + 1)))
|
||||||
self.format_title_artist.toggled.connect(
|
self.format_title_artist.toggled.connect(
|
||||||
lambda x: self.settings.setValue('format', 'title_artist' if x else 'artist_title'))
|
lambda x: self.settings.setValue('format', 'title_artist' if x else 'artist_title'))
|
||||||
self.dir_input.textChanged.connect(
|
self.dir_input.textChanged.connect(
|
||||||
|
|||||||
+51
-3
@@ -101,10 +101,31 @@ class TrackDownloader:
|
|||||||
print("Waiting for track processing to complete")
|
print("Waiting for track processing to complete")
|
||||||
while True:
|
while True:
|
||||||
completion_response = self.client.get(completion_url, headers=self.headers).json()
|
completion_response = self.client.get(completion_url, headers=self.headers).json()
|
||||||
if completion_response["status"] == "completed":
|
|
||||||
|
status = completion_response["status"]
|
||||||
|
if status == "completed":
|
||||||
|
print("Processing completed: 100%")
|
||||||
break
|
break
|
||||||
elif completion_response["status"] == "error":
|
elif status == "error":
|
||||||
raise Exception(f"API request failed: {completion_response.get('message', 'Unknown error')}")
|
raise Exception(f"API request failed: {completion_response.get('message', 'Unknown error')}")
|
||||||
|
else:
|
||||||
|
progress = completion_response.get("progress", {})
|
||||||
|
if progress:
|
||||||
|
current = progress.get("current", 0)
|
||||||
|
total = progress.get("total", 100)
|
||||||
|
percent = int((current / total) * 100) if total > 0 else 0
|
||||||
|
action = progress.get("action", "Processing")
|
||||||
|
print(f"Progress: {percent}% - {action} ({current}/{total})")
|
||||||
|
|
||||||
|
if action.lower() == "metadata":
|
||||||
|
if self.progress_callback:
|
||||||
|
self.progress_callback(0, 0)
|
||||||
|
else:
|
||||||
|
print(f"Status: {status} - Waiting for progress information...")
|
||||||
|
if status.lower() == "metadata":
|
||||||
|
if self.progress_callback:
|
||||||
|
self.progress_callback(0, 0)
|
||||||
|
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
download_url = f"https://{server}.{self.base_domain}/api/fetch/request/{handoff}/download"
|
download_url = f"https://{server}.{self.base_domain}/api/fetch/request/{handoff}/download"
|
||||||
@@ -118,16 +139,33 @@ class TrackDownloader:
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
with open(file_path, 'wb') as file:
|
with open(file_path, 'wb') as file:
|
||||||
|
start_time = time.time()
|
||||||
|
last_update_time = start_time
|
||||||
|
|
||||||
for chunk in response.iter_content(chunk_size=8192):
|
for chunk in response.iter_content(chunk_size=8192):
|
||||||
if chunk:
|
if chunk:
|
||||||
file.write(chunk)
|
file.write(chunk)
|
||||||
downloaded_size += len(chunk)
|
downloaded_size += len(chunk)
|
||||||
|
|
||||||
|
current_time = time.time()
|
||||||
|
if current_time - last_update_time >= 1:
|
||||||
|
if total_size > 0:
|
||||||
|
progress_percent = (downloaded_size / total_size) * 100
|
||||||
|
elapsed_time = current_time - start_time
|
||||||
|
speed = downloaded_size / (1024 * 1024 * elapsed_time) if elapsed_time > 0 else 0
|
||||||
|
print(f"Download progress: {progress_percent:.2f}% ({downloaded_size}/{total_size}) - {speed:.2f} MB/s")
|
||||||
|
else:
|
||||||
|
print(f"Downloaded {downloaded_size / (1024 * 1024):.2f} MB")
|
||||||
|
|
||||||
|
last_update_time = current_time
|
||||||
|
|
||||||
if self.progress_callback:
|
if self.progress_callback:
|
||||||
self.progress_callback(downloaded_size, total_size)
|
self.progress_callback(downloaded_size, total_size)
|
||||||
|
|
||||||
if downloaded_size == 0:
|
if downloaded_size == 0:
|
||||||
raise Exception("No data received from server")
|
raise Exception("No data received from server")
|
||||||
|
|
||||||
|
print(f"Download completed: {file_path}")
|
||||||
return file_path
|
return file_path
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@@ -144,10 +182,20 @@ async def main():
|
|||||||
track_id = "2plbrEY59IikOBgBGLjaoe"
|
track_id = "2plbrEY59IikOBgBGLjaoe"
|
||||||
service = "amazon"
|
service = "amazon"
|
||||||
|
|
||||||
|
def progress_update(current, total):
|
||||||
|
if total > 0:
|
||||||
|
percent = (current / total) * 100
|
||||||
|
print(f"\rDownload progress: {percent:.2f}% ({current}/{total})", end="")
|
||||||
|
|
||||||
|
downloader.set_progress_callback(progress_update)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
print(f"Getting track info for ID: {track_id} from {service}")
|
||||||
metadata = await downloader.get_track_info(track_id, service)
|
metadata = await downloader.get_track_info(track_id, service)
|
||||||
|
print(f"Track info received: {metadata['title']} by {metadata['artists']}")
|
||||||
|
|
||||||
downloaded_file = downloader.download(metadata, output_dir)
|
downloaded_file = downloader.download(metadata, output_dir)
|
||||||
print(f"File downloaded successfully: {downloaded_file}")
|
print(f"\nFile downloaded successfully: {downloaded_file}")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"An error occurred: {str(e)}")
|
print(f"An error occurred: {str(e)}")
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1,3 +1,3 @@
|
|||||||
{
|
{
|
||||||
"version": "1.8"
|
"version": "2.0"
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user