Skip to content

Commit bd6dfe5

Browse files
authored
Merge pull request #3 from aryakaul/auto-curated-default
feat: no option default
2 parents 8f0c1fa + de04ee3 commit bd6dfe5

2 files changed

Lines changed: 55 additions & 11 deletions

File tree

README.md

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,22 @@
1010

1111
## Quick Start
1212

13-
Pick an artist list (one name per line). A starter list lives at
14-
[`arya-curated`](https://raw.githubusercontent.com/aryakaul/tinyjam/main/arya-curated).
13+
Pick an artist list (one name per line). My list lives at [`arya-curated`](https://raw.githubusercontent.com/aryakaul/tinyjam/main/arya-curated).
14+
Launch `tinyjam` with no options to have it automatically grab that curated list
15+
and start streaming it (same as `tinyjam -l arya-curated -n`).
1516

1617
### macOS (Homebrew)
1718
```bash
1819
brew tap aryakaul/formulae
1920
brew install tinyjam
20-
wget https://raw.githubusercontent.com/aryakaul/tinyjam/main/arya-curated
21-
tinyjam -l ./arya-curated -n # stream without downloading
21+
tinyjam
2222
```
2323

2424
### Any platform (PyPI)
2525
```bash
2626
pip install tinyjam
2727
# tinyjam expects `mpv` and `yt-dlp` on your PATH
28-
wget https://raw.githubusercontent.com/aryakaul/tinyjam/main/arya-curated
29-
tinyjam -l ./arya-curated
28+
tinyjam
3029
```
3130

3231
### From source
@@ -35,7 +34,7 @@ git clone https://github.com/aryakaul/tinyjam.git
3534
cd tinyjam
3635
pip install --upgrade pip build
3736
pip install -e .
38-
tinyjam -l ./arya-curated -n
37+
tinyjam -l ./arya-curated -o ~/videos/tinydesk
3938
```
4039

4140
---
@@ -58,7 +57,7 @@ tinyjam --help
5857
-v, --verbose Extra logging
5958
```
6059

61-
Tinyjam keeps a download cache, retries through `yt-dlp`, and can fetch manual subtitles when a Tiny Desk isn’t in your preferred language. Use `--nodownload` to shuffle a curated list straight from YouTube, or let it fill `./jamsesh` and loop locally via mpv. Want deterministic runs? Pass `--playlist-order forward` to honor the jam list top-to-bottom or `--playlist-order reverse` to flip it.
60+
Tinyjam keeps a download cache, retries through `yt-dlp`, and can fetch manual subtitles when a Tiny Desk isn’t in your preferred language. Use `--nodownload` to shuffle a curated list straight from YouTube, or let it fill `./jamsesh` and loop locally via mpv. Running `tinyjam` with zero flags defaults to streaming my curated list.
6261

6362
Enjoy the desks ✨
6463

src/tinyjam/cli.py

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,16 @@
1818
import shutil
1919
import subprocess
2020
import sys
21+
import tempfile
2122
import threading
2223
from dataclasses import dataclass, field
2324
from pathlib import Path
2425
from typing import Any, Dict, Iterable, List, Optional, Sequence, Set, Tuple
2526

2627
from loguru import logger
2728
from tqdm import tqdm
29+
from urllib.error import HTTPError, URLError
30+
from urllib.request import urlopen
2831

2932
YT_CHANNEL_ID = "UC4eYXhJI4-7wSWc8UNRwD4A"
3033
STANDARD_OPS: Sequence[str] = (
@@ -42,6 +45,9 @@
4245
ENGLISH_PREFIXES = ("en", "eng")
4346
SUB_LINE_RE = re.compile(r"^([A-Za-z0-9][\w\.-]*)\s")
4447
PLAYLIST_ORDER_CHOICES = ("shuffle", "forward", "reverse")
48+
CURATED_JAMLIST_URL = (
49+
"https://raw.githubusercontent.com/aryakaul/tinyjam/refs/heads/main/arya-curated"
50+
)
4551

4652

4753
def configure_logging(verbose: bool) -> None:
@@ -159,6 +165,35 @@ def build_subtitle_args(target_language: str) -> List[str]:
159165
]
160166

161167

168+
def fetch_curated_jamlist() -> Path:
169+
try:
170+
with urlopen(CURATED_JAMLIST_URL, timeout=30) as response:
171+
payload = response.read()
172+
except (HTTPError, URLError) as exc:
173+
logger.error("failed to download curated jam list | {}", exc)
174+
sys.exit(1)
175+
except OSError as exc:
176+
logger.error("network error loading curated jam list | {}", exc)
177+
sys.exit(1)
178+
179+
if not payload:
180+
logger.error("curated jam list download returned no data")
181+
sys.exit(1)
182+
183+
try:
184+
with tempfile.NamedTemporaryFile(
185+
"wb", delete=False, prefix="tinyjam-curated-", suffix=".txt"
186+
) as handle:
187+
handle.write(payload)
188+
temp_path = Path(handle.name)
189+
except OSError as exc:
190+
logger.error("failed to persist curated jam list | {}", exc)
191+
sys.exit(1)
192+
193+
logger.info("using curated jam list from {}", CURATED_JAMLIST_URL)
194+
return temp_path
195+
196+
162197
@dataclass
163198
class TinyJamContext:
164199
jamlist: Path
@@ -820,15 +855,19 @@ def run(self) -> int:
820855
return 0
821856

822857

823-
def parse_args(argv: Optional[Sequence[str]] = None) -> TinyJamContext:
858+
def parse_args(
859+
argv: Optional[Sequence[str]] = None,
860+
*,
861+
require_list: bool = True,
862+
) -> TinyJamContext:
824863
parser = argparse.ArgumentParser(
825864
description="Jam to tiny desks with tinyjam (Python edition)",
826865
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
827866
)
828867
parser.add_argument(
829868
"-l",
830869
"--list",
831-
required=True,
870+
required=require_list,
832871
type=Path,
833872
help="path to artist list file (one per line)",
834873
)
@@ -917,8 +956,14 @@ def parse_args(argv: Optional[Sequence[str]] = None) -> TinyJamContext:
917956

918957

919958
def main(argv: Optional[Sequence[str]] = None) -> int:
920-
ctx = parse_args(argv)
959+
args_list = list(argv) if argv is not None else sys.argv[1:]
960+
use_curated_default = len(args_list) == 0
961+
ctx = parse_args(args_list, require_list=not use_curated_default)
921962
configure_logging(ctx.verbose)
963+
if use_curated_default:
964+
ctx.jamlist = fetch_curated_jamlist()
965+
ctx.nodownload = True
966+
logger.info("no options provided | defaulting to streaming mode")
922967
app = TinyJam(ctx)
923968
return app.run()
924969

0 commit comments

Comments
 (0)