northtracks 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- northtracks-1.0.0/PKG-INFO +79 -0
- northtracks-1.0.0/README.md +63 -0
- northtracks-1.0.0/musicdl/__init__.py +1 -0
- northtracks-1.0.0/musicdl/cli.py +241 -0
- northtracks-1.0.0/musicdl/config.py +80 -0
- northtracks-1.0.0/musicdl/downloader.py +333 -0
- northtracks-1.0.0/musicdl/fixer.py +216 -0
- northtracks-1.0.0/musicdl/itunes.py +56 -0
- northtracks-1.0.0/musicdl/logger.py +32 -0
- northtracks-1.0.0/musicdl/lyrics.py +37 -0
- northtracks-1.0.0/musicdl/normalizer.py +236 -0
- northtracks-1.0.0/musicdl/saavn.py +122 -0
- northtracks-1.0.0/musicdl/spotify.py +144 -0
- northtracks-1.0.0/musicdl/tagger.py +99 -0
- northtracks-1.0.0/musicdl/youtube.py +137 -0
- northtracks-1.0.0/northtracks.egg-info/PKG-INFO +79 -0
- northtracks-1.0.0/northtracks.egg-info/SOURCES.txt +22 -0
- northtracks-1.0.0/northtracks.egg-info/dependency_links.txt +1 -0
- northtracks-1.0.0/northtracks.egg-info/entry_points.txt +2 -0
- northtracks-1.0.0/northtracks.egg-info/requires.txt +5 -0
- northtracks-1.0.0/northtracks.egg-info/top_level.txt +1 -0
- northtracks-1.0.0/pyproject.toml +29 -0
- northtracks-1.0.0/setup.cfg +4 -0
- northtracks-1.0.0/setup.py +22 -0
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: northtracks
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: North Tracks - Autonomous 320k Studio Audio Downloader & Organizer
|
|
5
|
+
Author: North Tracks Team
|
|
6
|
+
License: MIT
|
|
7
|
+
Keywords: music,downloader,320kbps,spotify,jiosaavn,audio,itunes
|
|
8
|
+
Requires-Python: >=3.9
|
|
9
|
+
Description-Content-Type: text/markdown
|
|
10
|
+
Requires-Dist: requests>=2.31.0
|
|
11
|
+
Requires-Dist: mutagen>=1.47.0
|
|
12
|
+
Requires-Dist: pycryptodome>=3.20.0
|
|
13
|
+
Requires-Dist: rich>=13.7.0
|
|
14
|
+
Requires-Dist: prompt_toolkit>=3.0.43
|
|
15
|
+
Dynamic: requires-python
|
|
16
|
+
|
|
17
|
+
ο»Ώ# π΅ North Tracks β Studio Audio Downloader & Library Engine
|
|
18
|
+
|
|
19
|
+
A high-fidelity CLI music downloader and library organizer built on the proven streaming architecture of **LuckyGuy** and **LuckyGuy-Extensions**, refined into an independent, modular Python engine.
|
|
20
|
+
|
|
21
|
+
## β¨ Features
|
|
22
|
+
|
|
23
|
+
- **North Tracks Studio Engine**: Direct DES-ECB CDN stream decryption (`38346591` key) with `_320` bitrate upgrade for unthrottled, studio-master audio streams.
|
|
24
|
+
- **Concept 2 Pre-Download Confirmation Card**: Displays an instant 0.5s metadata resolver card previewing title, artist, album, detected category, artwork source, and target path *before* downloading bytes.
|
|
25
|
+
- **Duplicate Check & Fuzzy Matcher**: Scans the library before sending network requests; catches film versions and remasters (e.g., `Kesariya (From "Brahmastra")` matches `Kesariya`), skipping existing songs with:
|
|
26
|
+
`β© Skipped: "Alag Aasmaan" (Already in Indian Indie)`.
|
|
27
|
+
- **Safe `Ctrl+C` with Atomic Rename**: Streams into `.part` files. If interrupted or cancelled with `Ctrl+C`, the handler cleans up half-written files, leaving your library clean and corruption-free.
|
|
28
|
+
- **HTTP Range Resume**: If a download breaks mid-stream, it sends `Range: bytes=X-` to resume from the exact byte where it paused rather than starting over.
|
|
29
|
+
- **Failed-Track Summary & 1-Key Retry**: Displays a clean batch summary (e.g., `15 saved β’ 2 failed`) with a 1-key `[r]` option to instantly retry only failed tracks.
|
|
30
|
+
- **Synchronized Lyrics Fetcher**: Automatically pulls synchronized timestamped lyrics via LRCLIB and embeds them directly into MP4 (`Β©lyr`) and ID3 (`USLT`) tags.
|
|
31
|
+
- **`.m3u` Playlist Companion**: Files are organized directly into category folders (`Indian Indie/`, `Bollywood/`), and a clean relative `.m3u` file is generated under `downloads/Playlists/` so media players can play the full playlist in original order.
|
|
32
|
+
- **Dual Artwork Verification Pipeline**:
|
|
33
|
+
- **Tier 1 (Apple iTunes HD)**: Queries Apple Music / iTunes API for official 600Γ600 / 1000Γ1000 artwork.
|
|
34
|
+
- **Tier 2 (JioSaavn CDN)**: Falls back to JioSaavn's 500Γ500 high-speed Akamai CDN image repository.
|
|
35
|
+
- **Tier 3 (YouTube HD)**: High-resolution web/video thumbnail fallback if absent from both platforms.
|
|
36
|
+
- **Silent Rotating Log (`northtracks.log`)**: Terminal remains uncluttered; network headers, debug info, and exceptions are logged silently to `northtracks.log`.
|
|
37
|
+
- **Universal Back Navigation**: Pressing `b` or empty `Enter` returns to the main menu from any screen.
|
|
38
|
+
|
|
39
|
+
---
|
|
40
|
+
|
|
41
|
+
## π Quick Start
|
|
42
|
+
|
|
43
|
+
### 1. Run
|
|
44
|
+
```bash
|
|
45
|
+
cd A:\Devs\Agent\Python\northcodebase
|
|
46
|
+
python app.py
|
|
47
|
+
```
|
|
48
|
+
Or double-click `run.bat` in Windows Explorer.
|
|
49
|
+
|
|
50
|
+
---
|
|
51
|
+
|
|
52
|
+
## π Project Architecture
|
|
53
|
+
|
|
54
|
+
```
|
|
55
|
+
A:\Devs\Agent\Python\northcodebase/
|
|
56
|
+
β
|
|
57
|
+
βββ musicdl/
|
|
58
|
+
β βββ __init__.py
|
|
59
|
+
β βββ cli.py # North Tracks UI with Concept 2 metadata cards & 'b' back navigation
|
|
60
|
+
β βββ config.py # Settings, destination directory, greetings, stats
|
|
61
|
+
β βββ normalizer.py # Category routing, clean short naming & fuzzy deduplication
|
|
62
|
+
β βββ fixer.py # Library scanner & Dual Artwork Verification engine
|
|
63
|
+
β βββ saavn.py # JioSaavn API & 320k DES-ECB CDN decryptor
|
|
64
|
+
β βββ spotify.py # Spotify track & playlist metadata extractor
|
|
65
|
+
β βββ youtube.py # InnerTube client audio fallback
|
|
66
|
+
β βββ itunes.py # Apple iTunes HD metadata & 1000k artwork scraper
|
|
67
|
+
β βββ lyrics.py # LRCLIB synchronized lyrics fetcher
|
|
68
|
+
β βββ logger.py # Silent rotating file logger (northtracks.log)
|
|
69
|
+
β βββ tagger.py # Mutagen MP4/ID3 artwork, lyrics & tag embedder
|
|
70
|
+
β
|
|
71
|
+
βββ downloads/ # Categorized music destination (Indian Indie, Bollywood, etc.)
|
|
72
|
+
β βββ Playlists/ # Companion .m3u playlist files
|
|
73
|
+
βββ app.py # Main entry point
|
|
74
|
+
βββ run.bat # Windows 1-click launcher
|
|
75
|
+
βββ northtracks.log # Silent diagnostic log
|
|
76
|
+
βββ config.json # Persistent user configuration
|
|
77
|
+
βββ requirements.txt # Dependencies
|
|
78
|
+
βββ README.md # Documentation
|
|
79
|
+
```
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
ο»Ώ# π΅ North Tracks β Studio Audio Downloader & Library Engine
|
|
2
|
+
|
|
3
|
+
A high-fidelity CLI music downloader and library organizer built on the proven streaming architecture of **LuckyGuy** and **LuckyGuy-Extensions**, refined into an independent, modular Python engine.
|
|
4
|
+
|
|
5
|
+
## β¨ Features
|
|
6
|
+
|
|
7
|
+
- **North Tracks Studio Engine**: Direct DES-ECB CDN stream decryption (`38346591` key) with `_320` bitrate upgrade for unthrottled, studio-master audio streams.
|
|
8
|
+
- **Concept 2 Pre-Download Confirmation Card**: Displays an instant 0.5s metadata resolver card previewing title, artist, album, detected category, artwork source, and target path *before* downloading bytes.
|
|
9
|
+
- **Duplicate Check & Fuzzy Matcher**: Scans the library before sending network requests; catches film versions and remasters (e.g., `Kesariya (From "Brahmastra")` matches `Kesariya`), skipping existing songs with:
|
|
10
|
+
`β© Skipped: "Alag Aasmaan" (Already in Indian Indie)`.
|
|
11
|
+
- **Safe `Ctrl+C` with Atomic Rename**: Streams into `.part` files. If interrupted or cancelled with `Ctrl+C`, the handler cleans up half-written files, leaving your library clean and corruption-free.
|
|
12
|
+
- **HTTP Range Resume**: If a download breaks mid-stream, it sends `Range: bytes=X-` to resume from the exact byte where it paused rather than starting over.
|
|
13
|
+
- **Failed-Track Summary & 1-Key Retry**: Displays a clean batch summary (e.g., `15 saved β’ 2 failed`) with a 1-key `[r]` option to instantly retry only failed tracks.
|
|
14
|
+
- **Synchronized Lyrics Fetcher**: Automatically pulls synchronized timestamped lyrics via LRCLIB and embeds them directly into MP4 (`Β©lyr`) and ID3 (`USLT`) tags.
|
|
15
|
+
- **`.m3u` Playlist Companion**: Files are organized directly into category folders (`Indian Indie/`, `Bollywood/`), and a clean relative `.m3u` file is generated under `downloads/Playlists/` so media players can play the full playlist in original order.
|
|
16
|
+
- **Dual Artwork Verification Pipeline**:
|
|
17
|
+
- **Tier 1 (Apple iTunes HD)**: Queries Apple Music / iTunes API for official 600Γ600 / 1000Γ1000 artwork.
|
|
18
|
+
- **Tier 2 (JioSaavn CDN)**: Falls back to JioSaavn's 500Γ500 high-speed Akamai CDN image repository.
|
|
19
|
+
- **Tier 3 (YouTube HD)**: High-resolution web/video thumbnail fallback if absent from both platforms.
|
|
20
|
+
- **Silent Rotating Log (`northtracks.log`)**: Terminal remains uncluttered; network headers, debug info, and exceptions are logged silently to `northtracks.log`.
|
|
21
|
+
- **Universal Back Navigation**: Pressing `b` or empty `Enter` returns to the main menu from any screen.
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## π Quick Start
|
|
26
|
+
|
|
27
|
+
### 1. Run
|
|
28
|
+
```bash
|
|
29
|
+
cd A:\Devs\Agent\Python\northcodebase
|
|
30
|
+
python app.py
|
|
31
|
+
```
|
|
32
|
+
Or double-click `run.bat` in Windows Explorer.
|
|
33
|
+
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
## π Project Architecture
|
|
37
|
+
|
|
38
|
+
```
|
|
39
|
+
A:\Devs\Agent\Python\northcodebase/
|
|
40
|
+
β
|
|
41
|
+
βββ musicdl/
|
|
42
|
+
β βββ __init__.py
|
|
43
|
+
β βββ cli.py # North Tracks UI with Concept 2 metadata cards & 'b' back navigation
|
|
44
|
+
β βββ config.py # Settings, destination directory, greetings, stats
|
|
45
|
+
β βββ normalizer.py # Category routing, clean short naming & fuzzy deduplication
|
|
46
|
+
β βββ fixer.py # Library scanner & Dual Artwork Verification engine
|
|
47
|
+
β βββ saavn.py # JioSaavn API & 320k DES-ECB CDN decryptor
|
|
48
|
+
β βββ spotify.py # Spotify track & playlist metadata extractor
|
|
49
|
+
β βββ youtube.py # InnerTube client audio fallback
|
|
50
|
+
β βββ itunes.py # Apple iTunes HD metadata & 1000k artwork scraper
|
|
51
|
+
β βββ lyrics.py # LRCLIB synchronized lyrics fetcher
|
|
52
|
+
β βββ logger.py # Silent rotating file logger (northtracks.log)
|
|
53
|
+
β βββ tagger.py # Mutagen MP4/ID3 artwork, lyrics & tag embedder
|
|
54
|
+
β
|
|
55
|
+
βββ downloads/ # Categorized music destination (Indian Indie, Bollywood, etc.)
|
|
56
|
+
β βββ Playlists/ # Companion .m3u playlist files
|
|
57
|
+
βββ app.py # Main entry point
|
|
58
|
+
βββ run.bat # Windows 1-click launcher
|
|
59
|
+
βββ northtracks.log # Silent diagnostic log
|
|
60
|
+
βββ config.json # Persistent user configuration
|
|
61
|
+
βββ requirements.txt # Dependencies
|
|
62
|
+
βββ README.md # Documentation
|
|
63
|
+
```
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
ο»Ώ__version__ = "1.0.0"
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
ο»Ώimport os
|
|
2
|
+
import sys
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
from rich.console import Console
|
|
5
|
+
from rich.table import Table
|
|
6
|
+
from rich import box
|
|
7
|
+
|
|
8
|
+
from prompt_toolkit import prompt
|
|
9
|
+
from prompt_toolkit.formatted_text import HTML
|
|
10
|
+
|
|
11
|
+
from musicdl.config import (
|
|
12
|
+
load_config,
|
|
13
|
+
get_download_dir,
|
|
14
|
+
set_download_dir
|
|
15
|
+
)
|
|
16
|
+
from musicdl.spotify import is_spotify_url, extract_spotify_entity
|
|
17
|
+
from musicdl.youtube import is_youtube_url, fetch_youtube_audio_stream
|
|
18
|
+
from musicdl.downloader import download_track, download_batch_tracks
|
|
19
|
+
from musicdl.fixer import scan_music_files, repair_single_file
|
|
20
|
+
from musicdl.logger import log_info, log_error
|
|
21
|
+
|
|
22
|
+
console = Console()
|
|
23
|
+
|
|
24
|
+
def clear_screen():
|
|
25
|
+
os.system("cls" if os.name == "nt" else "clear")
|
|
26
|
+
|
|
27
|
+
def get_library_stats(dest: Path):
|
|
28
|
+
if not dest.exists():
|
|
29
|
+
return 0, 0.0
|
|
30
|
+
files = [f for f in dest.rglob("*.*") if f.is_file() and f.suffix.lower() in [".m4a", ".mp3", ".webm", ".flac"]]
|
|
31
|
+
total_bytes = sum(f.stat().st_size for f in files)
|
|
32
|
+
return len(files), total_bytes / (1024 * 1024)
|
|
33
|
+
|
|
34
|
+
def print_header(dest: Path):
|
|
35
|
+
total_tracks, total_mb = get_library_stats(dest)
|
|
36
|
+
console.print()
|
|
37
|
+
console.print(" [bold white]North Tracks[/bold white] [dim]β’ 320k Studio Downloader[/dim]")
|
|
38
|
+
console.print(f" [dim]{dest} ({total_tracks} tracks β’ {total_mb:.1f} MB)[/dim]")
|
|
39
|
+
console.print()
|
|
40
|
+
|
|
41
|
+
def handle_input(query: str, dest_dir: Path):
|
|
42
|
+
target = query.strip()
|
|
43
|
+
if not target or target.lower() == "b":
|
|
44
|
+
return
|
|
45
|
+
|
|
46
|
+
# Command handlers
|
|
47
|
+
cmd = target.lower()
|
|
48
|
+
if cmd in [":dest", ":folder", ":d"]:
|
|
49
|
+
screen_change_destination()
|
|
50
|
+
return
|
|
51
|
+
elif cmd in [":stats", ":library", ":s"]:
|
|
52
|
+
screen_library_stats()
|
|
53
|
+
return
|
|
54
|
+
elif cmd in [":repair", ":fix", ":r"]:
|
|
55
|
+
screen_repair()
|
|
56
|
+
return
|
|
57
|
+
elif cmd in [":exit", ":quit", ":q"]:
|
|
58
|
+
console.print("\n [cyan]βͺ North Tracks closed.[/cyan]\n")
|
|
59
|
+
sys.exit(0)
|
|
60
|
+
|
|
61
|
+
# 1. Spotify Link
|
|
62
|
+
if is_spotify_url(target):
|
|
63
|
+
console.print("\n [cyan]β[/cyan] Resolving Spotify metadata...")
|
|
64
|
+
entity = extract_spotify_entity(target)
|
|
65
|
+
if not entity:
|
|
66
|
+
console.print(" [red]β Failed to resolve Spotify link.[/red]")
|
|
67
|
+
return
|
|
68
|
+
|
|
69
|
+
tracks = entity.get("tracks", [])
|
|
70
|
+
if not tracks:
|
|
71
|
+
console.print(" [red]β No playable tracks found in Spotify link.[/red]")
|
|
72
|
+
return
|
|
73
|
+
is_collection = entity.get("type") in ["playlist", "album"]
|
|
74
|
+
pl_name = entity.get("title") if is_collection else ""
|
|
75
|
+
|
|
76
|
+
if len(tracks) > 1:
|
|
77
|
+
batch_result = download_batch_tracks(tracks, dest_dir=dest_dir, playlist_title=pl_name)
|
|
78
|
+
while batch_result.get("failed"):
|
|
79
|
+
failed_tracks = batch_result["failed"]
|
|
80
|
+
console.print(f" [red]β {len(failed_tracks)} track(s) failed.[/red] [dim]Press 'r' to retry, or Enter to continue[/dim]")
|
|
81
|
+
retry_choice = input(" Action βΊ ").strip().lower()
|
|
82
|
+
if retry_choice == "r":
|
|
83
|
+
batch_result = download_batch_tracks(failed_tracks, dest_dir=dest_dir, playlist_title=pl_name)
|
|
84
|
+
else:
|
|
85
|
+
break
|
|
86
|
+
elif len(tracks) == 1:
|
|
87
|
+
console.print(" " + "β" * 74)
|
|
88
|
+
download_track(tracks[0], dest_dir=dest_dir, track_idx="01/01")
|
|
89
|
+
console.print(" " + "β" * 74 + "\n")
|
|
90
|
+
|
|
91
|
+
# 2. YouTube Link
|
|
92
|
+
elif is_youtube_url(target):
|
|
93
|
+
console.print("\n [cyan]β[/cyan] Resolving YouTube audio stream via InnerTube...")
|
|
94
|
+
yt_data = fetch_youtube_audio_stream(target)
|
|
95
|
+
if not yt_data:
|
|
96
|
+
console.print(" [red]β Could not fetch YouTube audio.[/red]")
|
|
97
|
+
return
|
|
98
|
+
console.print(" " + "β" * 74)
|
|
99
|
+
download_track(yt_data, dest_dir=dest_dir, track_idx="01/01")
|
|
100
|
+
console.print(" " + "β" * 74 + "\n")
|
|
101
|
+
|
|
102
|
+
# 3. Direct Song Title Search
|
|
103
|
+
else:
|
|
104
|
+
console.print(f"\n [cyan]β[/cyan] Searching studio catalog for: [bold white]{target}[/]")
|
|
105
|
+
console.print(" " + "β" * 74)
|
|
106
|
+
download_track({"title": target, "artist": ""}, dest_dir=dest_dir, track_idx="01/01")
|
|
107
|
+
console.print(" " + "β" * 74 + "\n")
|
|
108
|
+
|
|
109
|
+
def screen_change_destination():
|
|
110
|
+
dest = get_download_dir()
|
|
111
|
+
console.print(f"\n [bold white]Current Storage:[/] [dim]{dest}[/dim]")
|
|
112
|
+
console.print(" [dim]Enter new folder path (or press Enter / 'b' to cancel):[/dim]")
|
|
113
|
+
new_path = input(" New Path βΊ ").strip()
|
|
114
|
+
if new_path and new_path.lower() != "b":
|
|
115
|
+
updated = set_download_dir(new_path)
|
|
116
|
+
console.print(f" [green]β Storage updated to:[/] {updated}\n")
|
|
117
|
+
|
|
118
|
+
def screen_library_stats():
|
|
119
|
+
dest = get_download_dir()
|
|
120
|
+
subdirs = [d for d in dest.iterdir() if d.is_dir() and not d.name.startswith(".")] if dest.exists() else []
|
|
121
|
+
total_tracks, total_mb = get_library_stats(dest)
|
|
122
|
+
|
|
123
|
+
console.print(f"\n [bold white]Library Categories[/bold white] [dim]({total_tracks} tracks β’ {total_mb:.1f} MB on disk)[/dim]")
|
|
124
|
+
console.print(" " + "β" * 74)
|
|
125
|
+
|
|
126
|
+
tbl = Table(box=box.SIMPLE, show_header=True, padding=(0, 2))
|
|
127
|
+
tbl.add_column("Category", style="bold white")
|
|
128
|
+
tbl.add_column("Tracks", justify="right", style="cyan")
|
|
129
|
+
tbl.add_column("Size", justify="right", style="dim")
|
|
130
|
+
tbl.add_column("Sample Artists", style="dim")
|
|
131
|
+
|
|
132
|
+
for d in sorted(subdirs):
|
|
133
|
+
tracks = list(d.glob("*.m4a")) + list(d.glob("*.mp3")) + list(d.glob("*.webm"))
|
|
134
|
+
dir_mb = sum(t.stat().st_size for t in tracks) / (1024 * 1024)
|
|
135
|
+
artists = []
|
|
136
|
+
for t in tracks[:3]:
|
|
137
|
+
parts = t.stem.split(" - ")
|
|
138
|
+
if len(parts) > 1:
|
|
139
|
+
artists.append(parts[0])
|
|
140
|
+
sample_str = ", ".join(list(dict.fromkeys(artists)))
|
|
141
|
+
tbl.add_row(d.name, str(len(tracks)), f"{dir_mb:.1f} MB", sample_str)
|
|
142
|
+
|
|
143
|
+
console.print(tbl)
|
|
144
|
+
console.print(" " + "β" * 74 + "\n")
|
|
145
|
+
|
|
146
|
+
def screen_repair():
|
|
147
|
+
dest = get_download_dir()
|
|
148
|
+
console.print(f"\n [bold white]Library Repair & Dual Artwork Verification[/bold white]")
|
|
149
|
+
console.print(f" [dim]Default scan location: {dest}[/dim]")
|
|
150
|
+
console.print(" [dim]Enter folder path to scan (or press Enter for default / 'b' to cancel):[/dim]")
|
|
151
|
+
custom_dir = input(" Scan Path βΊ ").strip()
|
|
152
|
+
|
|
153
|
+
if custom_dir.lower() == "b":
|
|
154
|
+
return
|
|
155
|
+
|
|
156
|
+
scan_dir = Path(custom_dir).resolve() if custom_dir else dest
|
|
157
|
+
if not scan_dir.exists() or not scan_dir.is_dir():
|
|
158
|
+
console.print(f" [red]β Directory not found:[/] {scan_dir}\n")
|
|
159
|
+
return
|
|
160
|
+
|
|
161
|
+
scanned = scan_music_files(scan_dir)
|
|
162
|
+
if not scanned:
|
|
163
|
+
console.print(" [yellow]No music files found in directory.[/yellow]\n")
|
|
164
|
+
return
|
|
165
|
+
|
|
166
|
+
console.print(" " + "β" * 74)
|
|
167
|
+
tbl = Table(box=box.SIMPLE, show_header=True, padding=(0, 2))
|
|
168
|
+
tbl.add_column("#", justify="right", style="dim", width=3)
|
|
169
|
+
tbl.add_column("File Name", style="bold white")
|
|
170
|
+
tbl.add_column("Artwork", justify="center")
|
|
171
|
+
tbl.add_column("Folder", style="dim")
|
|
172
|
+
tbl.add_column("Clean Short Name", style="cyan")
|
|
173
|
+
|
|
174
|
+
for idx, t in enumerate(scanned, 1):
|
|
175
|
+
art_status = "[green]β HD[/green]" if t["has_art"] else "[red]β Broken[/red]"
|
|
176
|
+
tbl.add_row(str(idx), t["filename"][:26], art_status, t["current_folder"][:14], t["suggested_name"][:26])
|
|
177
|
+
|
|
178
|
+
console.print(tbl)
|
|
179
|
+
console.print(" " + "β" * 74)
|
|
180
|
+
console.print(" [dim]Options: [bold white]A[/bold white] (Fix All) β’ [cyan]1, 3, 5-8[/cyan] (Select) β’ [bold white]b[/bold white] (Cancel)[/dim]")
|
|
181
|
+
choice = input(" Choice βΊ ").strip().upper()
|
|
182
|
+
|
|
183
|
+
if choice in ["B", "C", "CANCEL", ""]:
|
|
184
|
+
return
|
|
185
|
+
|
|
186
|
+
to_repair = []
|
|
187
|
+
if choice in ["A", "ALL"]:
|
|
188
|
+
to_repair = scanned
|
|
189
|
+
else:
|
|
190
|
+
selected_indices = set()
|
|
191
|
+
for chunk in choice.split(","):
|
|
192
|
+
chunk = chunk.strip()
|
|
193
|
+
if "-" in chunk:
|
|
194
|
+
parts = chunk.split("-")
|
|
195
|
+
try:
|
|
196
|
+
start, end = int(parts[0]), int(parts[1])
|
|
197
|
+
selected_indices.update(range(start, end + 1))
|
|
198
|
+
except ValueError:
|
|
199
|
+
pass
|
|
200
|
+
else:
|
|
201
|
+
try:
|
|
202
|
+
selected_indices.add(int(chunk))
|
|
203
|
+
except ValueError:
|
|
204
|
+
pass
|
|
205
|
+
to_repair = [scanned[i - 1] for i in selected_indices if 1 <= i <= len(scanned)]
|
|
206
|
+
|
|
207
|
+
if not to_repair:
|
|
208
|
+
console.print(" [red]β No valid tracks selected.[/red]\n")
|
|
209
|
+
return
|
|
210
|
+
|
|
211
|
+
console.print(f"\n [cyan]β Repairing {len(to_repair)} track(s)...[/cyan]")
|
|
212
|
+
for item in to_repair:
|
|
213
|
+
res = repair_single_file(item, dest)
|
|
214
|
+
if res:
|
|
215
|
+
console.print(f" [green]β[/green] {res['new_name'][:36]:<36} [dim]β’ {res['new_category']} β’ Art: {res['art_source']}[/dim]")
|
|
216
|
+
|
|
217
|
+
console.print(f" [green]Done.[/green] [dim]{len(to_repair)} track(s) repaired and verified.[/dim]\n")
|
|
218
|
+
|
|
219
|
+
def main():
|
|
220
|
+
while True:
|
|
221
|
+
try:
|
|
222
|
+
dest = get_download_dir()
|
|
223
|
+
print_header(dest)
|
|
224
|
+
console.print(" [dim]βΊ Paste Spotify/YouTube link, song name, or command (:repair, :dest, :stats, :exit):[/dim]")
|
|
225
|
+
|
|
226
|
+
raw_input = input(" βΊ ").strip()
|
|
227
|
+
|
|
228
|
+
if not raw_input:
|
|
229
|
+
continue
|
|
230
|
+
|
|
231
|
+
handle_input(raw_input, dest)
|
|
232
|
+
|
|
233
|
+
except KeyboardInterrupt:
|
|
234
|
+
console.print("\n\n [cyan]βͺ North Tracks closed.[/cyan]\n")
|
|
235
|
+
sys.exit(0)
|
|
236
|
+
except Exception as e:
|
|
237
|
+
log_error("Unhandled CLI exception", e)
|
|
238
|
+
console.print(f"\n [red]β Error:[/] {e} [dim](details in northtracks.log)[/dim]\n")
|
|
239
|
+
|
|
240
|
+
if __name__ == "__main__":
|
|
241
|
+
main()
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
ο»Ώimport os
|
|
2
|
+
import json
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
from datetime import datetime
|
|
5
|
+
from musicdl.logger import log_info, log_error
|
|
6
|
+
|
|
7
|
+
LOCAL_ROOT = Path(__file__).resolve().parent.parent
|
|
8
|
+
if (LOCAL_ROOT / "app.py").exists():
|
|
9
|
+
CONFIG_FILE = LOCAL_ROOT / "config.json"
|
|
10
|
+
DEFAULT_DOWNLOAD_DIR = LOCAL_ROOT / "downloads"
|
|
11
|
+
else:
|
|
12
|
+
USER_DIR = Path.home() / ".northtracks"
|
|
13
|
+
USER_DIR.mkdir(parents=True, exist_ok=True)
|
|
14
|
+
CONFIG_FILE = USER_DIR / "config.json"
|
|
15
|
+
DEFAULT_DOWNLOAD_DIR = Path.home() / "Music" / "NorthTracks"
|
|
16
|
+
|
|
17
|
+
DEFAULT_CONFIG = {
|
|
18
|
+
"download_dir": str(DEFAULT_DOWNLOAD_DIR),
|
|
19
|
+
"preferred_bitrate": "320kbps",
|
|
20
|
+
"naming_style": "short", # "short" (Lead Artist - Title), "title_only", "full"
|
|
21
|
+
"create_m3u": True, # Generates .m3u companion for playlists
|
|
22
|
+
"embed_lyrics": True, # Synchronized / plain lyrics
|
|
23
|
+
"skip_duplicates": True, # Prevents downloading existing songs
|
|
24
|
+
"total_downloads": 0
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
def load_config() -> dict:
|
|
28
|
+
if CONFIG_FILE.exists():
|
|
29
|
+
try:
|
|
30
|
+
with open(CONFIG_FILE, "r", encoding="utf-8") as f:
|
|
31
|
+
data = json.load(f)
|
|
32
|
+
return {**DEFAULT_CONFIG, **data}
|
|
33
|
+
except Exception as e:
|
|
34
|
+
log_error("Failed to read config.json, restoring defaults", e)
|
|
35
|
+
save_config(DEFAULT_CONFIG)
|
|
36
|
+
return DEFAULT_CONFIG.copy()
|
|
37
|
+
|
|
38
|
+
def save_config(cfg: dict):
|
|
39
|
+
try:
|
|
40
|
+
with open(CONFIG_FILE, "w", encoding="utf-8") as f:
|
|
41
|
+
json.dump(cfg, f, indent=4)
|
|
42
|
+
except Exception as e:
|
|
43
|
+
log_error("Failed to save config.json", e)
|
|
44
|
+
|
|
45
|
+
def get_download_dir() -> Path:
|
|
46
|
+
cfg = load_config()
|
|
47
|
+
p = Path(cfg.get("download_dir", DEFAULT_DOWNLOAD_DIR))
|
|
48
|
+
p.mkdir(parents=True, exist_ok=True)
|
|
49
|
+
return p
|
|
50
|
+
|
|
51
|
+
def set_download_dir(new_path: str) -> Path:
|
|
52
|
+
p = Path(new_path).resolve()
|
|
53
|
+
p.mkdir(parents=True, exist_ok=True)
|
|
54
|
+
cfg = load_config()
|
|
55
|
+
cfg["download_dir"] = str(p)
|
|
56
|
+
save_config(cfg)
|
|
57
|
+
log_info(f"Download directory changed to: {p}")
|
|
58
|
+
return p
|
|
59
|
+
|
|
60
|
+
def set_config_value(key: str, val):
|
|
61
|
+
cfg = load_config()
|
|
62
|
+
cfg[key] = val
|
|
63
|
+
save_config(cfg)
|
|
64
|
+
log_info(f"Config updated: {key} = {val}")
|
|
65
|
+
|
|
66
|
+
def increment_download_count():
|
|
67
|
+
cfg = load_config()
|
|
68
|
+
cfg["total_downloads"] = cfg.get("total_downloads", 0) + 1
|
|
69
|
+
save_config(cfg)
|
|
70
|
+
|
|
71
|
+
def get_greeting() -> str:
|
|
72
|
+
hour = datetime.now().hour
|
|
73
|
+
if 5 <= hour < 12:
|
|
74
|
+
return "Good morning"
|
|
75
|
+
elif 12 <= hour < 17:
|
|
76
|
+
return "Good afternoon"
|
|
77
|
+
elif 17 <= hour < 22:
|
|
78
|
+
return "Good evening"
|
|
79
|
+
else:
|
|
80
|
+
return "Good night"
|