crateport 1.0.3__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.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Phillip Stockmann <ZyanKLee@users.noreply.github.com>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,134 @@
1
+ Metadata-Version: 2.4
2
+ Name: crateport
3
+ Version: 1.0.3
4
+ Summary: DJ-focused playlist tool: generate from artist/track lists or convert VirtualDJ exports to Soundiiz-ready CSVs with ISRC enrichment.
5
+ License: MIT License
6
+
7
+ Copyright (c) 2026 Phillip Stockmann <ZyanKLee@users.noreply.github.com>
8
+
9
+ Permission is hereby granted, free of charge, to any person obtaining a copy
10
+ of this software and associated documentation files (the "Software"), to deal
11
+ in the Software without restriction, including without limitation the rights
12
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
+ copies of the Software, and to permit persons to whom the Software is
14
+ furnished to do so, subject to the following conditions:
15
+
16
+ The above copyright notice and this permission notice shall be included in all
17
+ copies or substantial portions of the Software.
18
+
19
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25
+ SOFTWARE.
26
+ License-File: LICENSE
27
+ Keywords: deezer,playlist,csv,music
28
+ Author: Phillip Stockmann
29
+ Author-email: ZyanKLee@users.noreply.github.com
30
+ Requires-Python: >=3.14,<4.0
31
+ Classifier: Programming Language :: Python :: 3
32
+ Classifier: License :: OSI Approved :: MIT License
33
+ Classifier: Operating System :: OS Independent
34
+ Requires-Dist: click (>=8.1,<9.0)
35
+ Requires-Dist: python-dotenv (>=1.0,<2.0)
36
+ Requires-Dist: requests (>=2.32.5,<3.0.0)
37
+ Requires-Dist: sqlalchemy (>=2.0,<3.0)
38
+ Description-Content-Type: text/markdown
39
+
40
+ # crateport
41
+
42
+ A DJ-focused playlist tool with two workflows:
43
+
44
+ - **`generate`** — build a playlist from a list of artists, albums, or tracks using the Deezer public API, then export it to XSPF / M3U / CSV / JSON. See [docs/generate.md](docs/generate.md) for details.
45
+ - **`convert`** — take a VirtualDJ CSV export, enrich every track with an ISRC via Deezer (falling back to MusicBrainz), and produce a Soundiiz-compatible CSV ready for import into Deezer or any other streaming platform. See [docs/convert.md](docs/convert.md) for details.
46
+
47
+ No Deezer application credentials required. API responses are cached locally in SQLite.
48
+
49
+ ---
50
+
51
+ ## Requirements
52
+
53
+ - Python ≥ 3.14
54
+ - [pipx](https://pipx.pypa.io/) for installation
55
+
56
+ ---
57
+
58
+ ## Installation
59
+
60
+ ```bash
61
+ git clone https://github.com/ZyanKLee/crateport.git
62
+ cd crateport
63
+ pipx install .
64
+ ```
65
+
66
+ The `crateport` command is then available globally.
67
+
68
+ To upgrade after pulling new changes:
69
+
70
+ ```bash
71
+ pipx install . --force
72
+ ```
73
+
74
+ To uninstall:
75
+
76
+ ```bash
77
+ pipx uninstall crateport
78
+ ```
79
+
80
+ ### Working directory
81
+
82
+ crateport always reads and writes relative to **where you run the command**, regardless of where it is installed:
83
+
84
+ | Path | Purpose |
85
+ |------|---------|
86
+ | `./output/` | Generated CSVs, XSPF, M3U, JSON, and `cache.db` — created automatically |
87
+ | `./source_data/` | Convenient place for input files — created automatically, not required |
88
+ | `./.env` | Optional configuration overrides (see [Configuration](#configuration)) |
89
+
90
+ ---
91
+
92
+ ## Quick start
93
+
94
+ ```bash
95
+ # Convert a VirtualDJ set export to Soundiiz CSV with ISRC
96
+ crateport convert "source_data/2026-03-13 My Set.csv" --name "My_Set_2026-03-13"
97
+
98
+ # Generate a playlist from an artist list
99
+ crateport generate source_data/artists.txt --name "My Techno Mix"
100
+ ```
101
+
102
+ **Full command reference:** [docs/convert.md](docs/convert.md) · [docs/generate.md](docs/generate.md)
103
+
104
+ ---
105
+
106
+ ## Configuration
107
+
108
+ Copy `.env.example` to `.env` and adjust as needed. All values are optional.
109
+
110
+ ```bash
111
+ cp .env.example .env
112
+ ```
113
+
114
+ | Variable | Default | Description |
115
+ |----------|---------|-------------|
116
+ | `DATABASE_URL` | `sqlite:///output/cache.db` | SQLAlchemy database URL — switch to `postgresql+psycopg2://…` for PostgreSQL |
117
+ | `CACHE_TTL_HOURS` | `24` | How long cached API responses remain valid (hours) |
118
+ | `MUSICBRAINZ_USER_AGENT` | built-in | User-Agent sent to MusicBrainz (identify your instance) |
119
+ | `DEEZER_APP_ID` | *(empty)* | Reserved for future direct Deezer push (not required for file export) |
120
+ | `DEEZER_SECRET` | *(empty)* | Reserved for future direct Deezer push |
121
+ | `DEEZER_REDIRECT_URI` | `http://localhost:8080/callback` | Reserved for future direct Deezer push |
122
+
123
+ ---
124
+
125
+ ## Contributing
126
+
127
+ See [CONTRIBUTING.md](CONTRIBUTING.md) for project structure and development setup.
128
+
129
+ ---
130
+
131
+ ## License
132
+
133
+ MIT License © 2026 Zyan K. Lee
134
+
@@ -0,0 +1,94 @@
1
+ # crateport
2
+
3
+ A DJ-focused playlist tool with two workflows:
4
+
5
+ - **`generate`** — build a playlist from a list of artists, albums, or tracks using the Deezer public API, then export it to XSPF / M3U / CSV / JSON. See [docs/generate.md](docs/generate.md) for details.
6
+ - **`convert`** — take a VirtualDJ CSV export, enrich every track with an ISRC via Deezer (falling back to MusicBrainz), and produce a Soundiiz-compatible CSV ready for import into Deezer or any other streaming platform. See [docs/convert.md](docs/convert.md) for details.
7
+
8
+ No Deezer application credentials required. API responses are cached locally in SQLite.
9
+
10
+ ---
11
+
12
+ ## Requirements
13
+
14
+ - Python ≥ 3.14
15
+ - [pipx](https://pipx.pypa.io/) for installation
16
+
17
+ ---
18
+
19
+ ## Installation
20
+
21
+ ```bash
22
+ git clone https://github.com/ZyanKLee/crateport.git
23
+ cd crateport
24
+ pipx install .
25
+ ```
26
+
27
+ The `crateport` command is then available globally.
28
+
29
+ To upgrade after pulling new changes:
30
+
31
+ ```bash
32
+ pipx install . --force
33
+ ```
34
+
35
+ To uninstall:
36
+
37
+ ```bash
38
+ pipx uninstall crateport
39
+ ```
40
+
41
+ ### Working directory
42
+
43
+ crateport always reads and writes relative to **where you run the command**, regardless of where it is installed:
44
+
45
+ | Path | Purpose |
46
+ |------|---------|
47
+ | `./output/` | Generated CSVs, XSPF, M3U, JSON, and `cache.db` — created automatically |
48
+ | `./source_data/` | Convenient place for input files — created automatically, not required |
49
+ | `./.env` | Optional configuration overrides (see [Configuration](#configuration)) |
50
+
51
+ ---
52
+
53
+ ## Quick start
54
+
55
+ ```bash
56
+ # Convert a VirtualDJ set export to Soundiiz CSV with ISRC
57
+ crateport convert "source_data/2026-03-13 My Set.csv" --name "My_Set_2026-03-13"
58
+
59
+ # Generate a playlist from an artist list
60
+ crateport generate source_data/artists.txt --name "My Techno Mix"
61
+ ```
62
+
63
+ **Full command reference:** [docs/convert.md](docs/convert.md) · [docs/generate.md](docs/generate.md)
64
+
65
+ ---
66
+
67
+ ## Configuration
68
+
69
+ Copy `.env.example` to `.env` and adjust as needed. All values are optional.
70
+
71
+ ```bash
72
+ cp .env.example .env
73
+ ```
74
+
75
+ | Variable | Default | Description |
76
+ |----------|---------|-------------|
77
+ | `DATABASE_URL` | `sqlite:///output/cache.db` | SQLAlchemy database URL — switch to `postgresql+psycopg2://…` for PostgreSQL |
78
+ | `CACHE_TTL_HOURS` | `24` | How long cached API responses remain valid (hours) |
79
+ | `MUSICBRAINZ_USER_AGENT` | built-in | User-Agent sent to MusicBrainz (identify your instance) |
80
+ | `DEEZER_APP_ID` | *(empty)* | Reserved for future direct Deezer push (not required for file export) |
81
+ | `DEEZER_SECRET` | *(empty)* | Reserved for future direct Deezer push |
82
+ | `DEEZER_REDIRECT_URI` | `http://localhost:8080/callback` | Reserved for future direct Deezer push |
83
+
84
+ ---
85
+
86
+ ## Contributing
87
+
88
+ See [CONTRIBUTING.md](CONTRIBUTING.md) for project structure and development setup.
89
+
90
+ ---
91
+
92
+ ## License
93
+
94
+ MIT License © 2026 Zyan K. Lee
File without changes
@@ -0,0 +1,12 @@
1
+ """Allow ``python -m crateport`` to run the CLI.
2
+
3
+ Subcommands
4
+ -----------
5
+ ``crateport generate <input_file>`` – generate a playlist from artist/track list
6
+ ``crateport convert <vdj_csv>`` – convert VirtualDJ CSV → Soundiiz CSV with ISRC
7
+ """
8
+
9
+ from crateport.cli import cli
10
+
11
+ if __name__ == "__main__":
12
+ cli()
@@ -0,0 +1,181 @@
1
+ """Deezer OAuth 2.0 authentication.
2
+
3
+ Deezer uses a custom three-legged OAuth flow:
4
+
5
+ 1. Open the authorization URL in the user's browser.
6
+ 2. The user logs in and grants permissions.
7
+ 3. Deezer redirects to *redirect_uri* with ``?code=<auth_code>``.
8
+ 4. Exchange the code for an access token.
9
+
10
+ A lightweight ``http.server`` is started locally to capture the callback
11
+ when the redirect URI points to ``localhost``.
12
+
13
+ .. note::
14
+
15
+ You must register an application at https://developers.deezer.com/ and
16
+ populate ``DEEZER_APP_ID`` and ``DEEZER_SECRET`` in your ``.env`` file.
17
+ """
18
+
19
+ from __future__ import annotations
20
+
21
+ import logging
22
+ import threading
23
+ import urllib.parse
24
+ import webbrowser
25
+ from http.server import BaseHTTPRequestHandler, HTTPServer
26
+
27
+ import requests
28
+
29
+ from .config import config
30
+
31
+ logger = logging.getLogger(__name__)
32
+
33
+ _AUTH_URL = "https://connect.deezer.com/oauth/auth.php"
34
+ _TOKEN_URL = "https://connect.deezer.com/oauth/access_token.php"
35
+ _TOKEN_FILE = config.output_dir / ".deezer_token"
36
+
37
+ _PERMS = "basic_access,email,manage_library,delete_library"
38
+
39
+
40
+ # ---------------------------------------------------------------------------
41
+ # Token persistence
42
+ # ---------------------------------------------------------------------------
43
+
44
+
45
+ def load_saved_token() -> str | None:
46
+ """Return the access token saved from a previous session, or ``None``."""
47
+ if _TOKEN_FILE.exists():
48
+ return _TOKEN_FILE.read_text().strip() or None
49
+ return None
50
+
51
+
52
+ def save_token(token: str) -> None:
53
+ """Persist *token* to disk for reuse across sessions."""
54
+ _TOKEN_FILE.write_text(token)
55
+ _TOKEN_FILE.chmod(0o600)
56
+ logger.debug("Saved access token to %s", _TOKEN_FILE)
57
+
58
+
59
+ # ---------------------------------------------------------------------------
60
+ # OAuth flow
61
+ # ---------------------------------------------------------------------------
62
+
63
+
64
+ def get_access_token(force_reauth: bool = False) -> str:
65
+ """Return a valid Deezer access token, prompting the user to log in if needed.
66
+
67
+ Raises
68
+ ------
69
+ ValueError
70
+ When ``DEEZER_APP_ID`` or ``DEEZER_SECRET`` are not configured.
71
+ RuntimeError
72
+ When the OAuth flow fails or times out.
73
+ """
74
+ if not force_reauth:
75
+ token = load_saved_token()
76
+ if token:
77
+ logger.debug("Using saved Deezer access token.")
78
+ return token
79
+
80
+ if not config.deezer_app_id or not config.deezer_secret:
81
+ raise ValueError(
82
+ "DEEZER_APP_ID and DEEZER_SECRET must be set in your .env file.\n"
83
+ "Register an application at https://developers.deezer.com/"
84
+ )
85
+
86
+ code = _run_local_oauth_flow()
87
+ token = _exchange_code_for_token(code)
88
+ save_token(token)
89
+ return token
90
+
91
+
92
+ def _build_auth_url() -> str:
93
+ params = {
94
+ "app_id": config.deezer_app_id,
95
+ "redirect_uri": config.deezer_redirect_uri,
96
+ "perms": _PERMS,
97
+ "response_type": "code",
98
+ }
99
+ return f"{_AUTH_URL}?{urllib.parse.urlencode(params)}"
100
+
101
+
102
+ def _run_local_oauth_flow() -> str:
103
+ """Open the browser and wait for the OAuth callback. Return the auth code."""
104
+ parsed = urllib.parse.urlparse(config.deezer_redirect_uri)
105
+ host = parsed.hostname or "localhost"
106
+ port = parsed.port or 8080
107
+
108
+ received_code: list[str] = []
109
+ done = threading.Event()
110
+
111
+ class Handler(BaseHTTPRequestHandler): # pylint: disable=too-few-public-methods
112
+ """Minimal HTTP handler that captures the OAuth callback code."""
113
+
114
+ def do_GET(self) -> None: # noqa: N802 # pylint: disable=invalid-name
115
+ """Handle the OAuth redirect GET request and extract the auth code."""
116
+ qs = urllib.parse.parse_qs(urllib.parse.urlparse(self.path).query)
117
+ code = qs.get("code", [""])[0]
118
+ if code:
119
+ received_code.append(code)
120
+ self.send_response(200)
121
+ self.send_header("Content-Type", "text/html")
122
+ self.end_headers()
123
+ msg = (
124
+ "<h2>Authorization successful!</h2><p>You can close this tab.</p>"
125
+ if code
126
+ else "<h2>No code received.</h2>"
127
+ )
128
+ self.wfile.write(msg.encode())
129
+ done.set()
130
+
131
+ def log_message(self, *args) -> None: # silence request logs
132
+ pass
133
+
134
+ server = HTTPServer((host, port), Handler)
135
+ thread = threading.Thread(target=server.serve_forever, daemon=True)
136
+ thread.start()
137
+
138
+ auth_url = _build_auth_url()
139
+ logger.info("Opening browser for Deezer authorization…")
140
+ print(f"\nIf your browser does not open automatically, visit:\n {auth_url}\n")
141
+ webbrowser.open(auth_url)
142
+
143
+ if not done.wait(timeout=120):
144
+ server.shutdown()
145
+ raise RuntimeError("Timed out waiting for Deezer OAuth callback (120 s).")
146
+
147
+ server.shutdown()
148
+ if not received_code:
149
+ raise RuntimeError("OAuth callback received but no auth code was found.")
150
+ return received_code[0]
151
+
152
+
153
+ def _exchange_code_for_token(code: str) -> str:
154
+ """Exchange an authorization code for an access token."""
155
+ params = {
156
+ "app_id": config.deezer_app_id,
157
+ "secret": config.deezer_secret,
158
+ "code": code,
159
+ "output": "json",
160
+ }
161
+ resp = requests.get(_TOKEN_URL, params=params, timeout=15)
162
+ resp.raise_for_status()
163
+ # Deezer may return JSON or URL-encoded depending on the ``output`` param
164
+ try:
165
+ data = resp.json()
166
+ token = data.get("access_token", "")
167
+ except ValueError:
168
+ qs = urllib.parse.parse_qs(resp.text)
169
+ token = qs.get("access_token", [""])[0]
170
+
171
+ if not token:
172
+ raise RuntimeError(f"Failed to obtain access token. Response: {resp.text}")
173
+ logger.info("Successfully obtained Deezer access token.")
174
+ return token
175
+
176
+
177
+ def revoke_saved_token() -> None:
178
+ """Delete the locally saved token file."""
179
+ if _TOKEN_FILE.exists():
180
+ _TOKEN_FILE.unlink()
181
+ logger.info("Saved token deleted.")