reelsort 0.2.8 → 0.2.9

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.
package/dist/cli.js CHANGED
@@ -1705,46 +1705,49 @@ var gatherEntries = (source) => {
1705
1705
  }
1706
1706
  return result;
1707
1707
  };
1708
- var findShowFolder = (destRoot, title) => {
1709
- if (!(0, import_fs15.existsSync)(destRoot)) return null;
1710
- const normalize = (s) => s.toLowerCase().replace(/[^a-z0-9]/g, "");
1711
- const target = normalize(title);
1712
- return (0, import_fs15.readdirSync)(destRoot).filter((f) => {
1708
+ var nTitle = (s) => s.toLowerCase().replace(/[^a-z0-9]/g, "");
1709
+ var showDirIndexCache = /* @__PURE__ */ new Map();
1710
+ var getShowDirIndex = (destRoot) => {
1711
+ if (showDirIndexCache.has(destRoot)) return showDirIndexCache.get(destRoot);
1712
+ const idx = /* @__PURE__ */ new Map();
1713
+ showDirIndexCache.set(destRoot, idx);
1714
+ if (!(0, import_fs15.existsSync)(destRoot)) return idx;
1715
+ let dirs;
1716
+ try {
1717
+ dirs = (0, import_fs15.readdirSync)(destRoot);
1718
+ } catch {
1719
+ return idx;
1720
+ }
1721
+ for (const dir of dirs) {
1713
1722
  try {
1714
- return (0, import_fs15.lstatSync)((0, import_path15.resolve)(destRoot, f)).isDirectory();
1723
+ if (!(0, import_fs15.lstatSync)((0, import_path15.resolve)(destRoot, dir)).isDirectory()) continue;
1715
1724
  } catch {
1716
- return false;
1725
+ continue;
1717
1726
  }
1718
- }).find((f) => normalize(f) === target) ?? null;
1719
- };
1720
- var findShowFolderByContent = (destRoot, title) => {
1721
- if (!(0, import_fs15.existsSync)(destRoot)) return null;
1722
- const normalize = (s) => s.toLowerCase().replace(/[^a-z0-9]/g, "");
1723
- const target = normalize(title);
1724
- const matchesTitle = (name) => {
1725
- if (!isTvEpisodeName(name)) return false;
1726
- const p = parseDownloadName(name);
1727
- return !!p && normalize(p.title) === target;
1728
- };
1729
- for (const folder of (0, import_fs15.readdirSync)(destRoot)) {
1727
+ idx.set(nTitle(dir), dir);
1730
1728
  try {
1731
- const folderPath = (0, import_path15.resolve)(destRoot, folder);
1732
- if (!(0, import_fs15.lstatSync)(folderPath).isDirectory()) continue;
1733
- const children = (0, import_fs15.readdirSync)(folderPath);
1734
- if (children.some(matchesTitle)) return folder;
1735
- for (const child of children) {
1736
- if (!isSeasonDirName(child)) continue;
1729
+ const children = (0, import_fs15.readdirSync)((0, import_path15.resolve)(destRoot, dir));
1730
+ const tryFile = (name) => {
1731
+ if (!isTvEpisodeName(name)) return;
1732
+ const p = parseDownloadName(name);
1733
+ if (p) {
1734
+ const k = nTitle(p.title);
1735
+ if (!idx.has(k)) idx.set(k, dir);
1736
+ }
1737
+ };
1738
+ children.forEach(tryFile);
1739
+ children.forEach((child) => {
1740
+ if (!isSeasonDirName(child)) return;
1737
1741
  try {
1738
- const seasonPath = (0, import_path15.resolve)(folderPath, child);
1739
- if (!(0, import_fs15.lstatSync)(seasonPath).isDirectory()) continue;
1740
- if ((0, import_fs15.readdirSync)(seasonPath).some(matchesTitle)) return folder;
1742
+ const sp = (0, import_path15.resolve)(destRoot, dir, child);
1743
+ if ((0, import_fs15.lstatSync)(sp).isDirectory()) (0, import_fs15.readdirSync)(sp).forEach(tryFile);
1741
1744
  } catch {
1742
1745
  }
1743
- }
1746
+ });
1744
1747
  } catch {
1745
1748
  }
1746
1749
  }
1747
- return null;
1750
+ return idx;
1748
1751
  };
1749
1752
  var findSeasonFolder = (showPath, season, specialsFolder) => {
1750
1753
  if (!(0, import_fs15.existsSync)(showPath)) return null;
@@ -1774,9 +1777,9 @@ var classifyMovieConfidence = (entry) => {
1774
1777
  return "ambiguous";
1775
1778
  };
1776
1779
  var typeColor = {
1777
- movie: (s) => import_termkit13.Color.cyan.encoder(s),
1778
- tv: (s) => import_termkit13.Color.green.encoder(s),
1779
- book: (s) => import_termkit13.Color.yellow.encoder(s),
1780
+ movie: (s) => import_termkit13.Color.yellow.encoder(s),
1781
+ tv: (s) => import_termkit13.Color.blue.encoder(s),
1782
+ book: (s) => import_termkit13.Color.white.encoder(s),
1780
1783
  ps3: (s) => import_termkit13.Color.magenta.encoder(s)
1781
1784
  };
1782
1785
  var typeGlyph = (t) => typeColor[t]("?");
@@ -2058,7 +2061,7 @@ var scan = async ({ type, hardlink: useHardlink, dryRun, auto, force, interactiv
2058
2061
  showPath = registeredShow.path;
2059
2062
  showFolderName = showPath.split("/").pop() ?? registeredShow.path;
2060
2063
  } else {
2061
- const existingFolder = findShowFolder(destRoot, resolvedTitle) ?? findShowFolderByContent(destRoot, resolvedTitle);
2064
+ const existingFolder = getShowDirIndex(destRoot).get(nTitle(resolvedTitle)) ?? null;
2062
2065
  if (existingFolder) {
2063
2066
  showFolderName = existingFolder;
2064
2067
  showPath = (0, import_path15.resolve)(destRoot, existingFolder);
@@ -2066,6 +2069,7 @@ var scan = async ({ type, hardlink: useHardlink, dryRun, auto, force, interactiv
2066
2069
  showFolderName = formatMovieName(movieFormat, resolvedTitle, resolvedYear);
2067
2070
  showPath = (0, import_path15.resolve)(destRoot, showFolderName);
2068
2071
  if (!dryRun) upsertShow(showPath, tmdbId ?? null, resolvedTitle);
2072
+ getShowDirIndex(destRoot).set(nTitle(resolvedTitle), showFolderName);
2069
2073
  } else {
2070
2074
  pendingTv.push({ entry, entryPath, isDir, parsed, resolvedTitle, destRoot });
2071
2075
  continue;
@@ -2741,7 +2745,7 @@ var watch = async ({ hardlink = false, auto = false }) => {
2741
2745
  var watch_default = watch;
2742
2746
 
2743
2747
  // package.json
2744
- var version = "0.2.8";
2748
+ var version = "0.2.9";
2745
2749
 
2746
2750
  // src/program.ts
2747
2751
  var toCamel = (s) => s.replace(/-([a-z])/g, (_, c) => c.toUpperCase());
@@ -2780,9 +2784,10 @@ var program_default = program;
2780
2784
 
2781
2785
  // src/cli.ts
2782
2786
  if (!process.stdout.isTTY) {
2783
- const { FORCE_COLOR, MSYSTEM, WT_SESSION, TERM } = process.env;
2784
- if (FORCE_COLOR || MSYSTEM || WT_SESSION || TERM?.startsWith("xterm")) {
2787
+ const { FORCE_COLOR, MSYSTEM, WT_SESSION, TERM, PSModulePath } = process.env;
2788
+ if (FORCE_COLOR || MSYSTEM || WT_SESSION || TERM?.startsWith("xterm") || PSModulePath) {
2785
2789
  Object.defineProperty(process.stdout, "isTTY", { value: true, configurable: true });
2790
+ Object.defineProperty(process.stdin, "isTTY", { value: true, configurable: true });
2786
2791
  }
2787
2792
  }
2788
2793
  var run = async (args) => {
package/dist/index.js CHANGED
@@ -1411,46 +1411,49 @@ var gatherEntries = (source) => {
1411
1411
  }
1412
1412
  return result;
1413
1413
  };
1414
- var findShowFolder = (destRoot, title) => {
1415
- if (!(0, import_fs11.existsSync)(destRoot)) return null;
1416
- const normalize = (s) => s.toLowerCase().replace(/[^a-z0-9]/g, "");
1417
- const target = normalize(title);
1418
- return (0, import_fs11.readdirSync)(destRoot).filter((f) => {
1414
+ var nTitle = (s) => s.toLowerCase().replace(/[^a-z0-9]/g, "");
1415
+ var showDirIndexCache = /* @__PURE__ */ new Map();
1416
+ var getShowDirIndex = (destRoot) => {
1417
+ if (showDirIndexCache.has(destRoot)) return showDirIndexCache.get(destRoot);
1418
+ const idx = /* @__PURE__ */ new Map();
1419
+ showDirIndexCache.set(destRoot, idx);
1420
+ if (!(0, import_fs11.existsSync)(destRoot)) return idx;
1421
+ let dirs;
1422
+ try {
1423
+ dirs = (0, import_fs11.readdirSync)(destRoot);
1424
+ } catch {
1425
+ return idx;
1426
+ }
1427
+ for (const dir of dirs) {
1419
1428
  try {
1420
- return (0, import_fs11.lstatSync)((0, import_path12.resolve)(destRoot, f)).isDirectory();
1429
+ if (!(0, import_fs11.lstatSync)((0, import_path12.resolve)(destRoot, dir)).isDirectory()) continue;
1421
1430
  } catch {
1422
- return false;
1431
+ continue;
1423
1432
  }
1424
- }).find((f) => normalize(f) === target) ?? null;
1425
- };
1426
- var findShowFolderByContent = (destRoot, title) => {
1427
- if (!(0, import_fs11.existsSync)(destRoot)) return null;
1428
- const normalize = (s) => s.toLowerCase().replace(/[^a-z0-9]/g, "");
1429
- const target = normalize(title);
1430
- const matchesTitle = (name) => {
1431
- if (!isTvEpisodeName(name)) return false;
1432
- const p = parseDownloadName(name);
1433
- return !!p && normalize(p.title) === target;
1434
- };
1435
- for (const folder of (0, import_fs11.readdirSync)(destRoot)) {
1433
+ idx.set(nTitle(dir), dir);
1436
1434
  try {
1437
- const folderPath = (0, import_path12.resolve)(destRoot, folder);
1438
- if (!(0, import_fs11.lstatSync)(folderPath).isDirectory()) continue;
1439
- const children = (0, import_fs11.readdirSync)(folderPath);
1440
- if (children.some(matchesTitle)) return folder;
1441
- for (const child of children) {
1442
- if (!isSeasonDirName(child)) continue;
1435
+ const children = (0, import_fs11.readdirSync)((0, import_path12.resolve)(destRoot, dir));
1436
+ const tryFile = (name) => {
1437
+ if (!isTvEpisodeName(name)) return;
1438
+ const p = parseDownloadName(name);
1439
+ if (p) {
1440
+ const k = nTitle(p.title);
1441
+ if (!idx.has(k)) idx.set(k, dir);
1442
+ }
1443
+ };
1444
+ children.forEach(tryFile);
1445
+ children.forEach((child) => {
1446
+ if (!isSeasonDirName(child)) return;
1443
1447
  try {
1444
- const seasonPath = (0, import_path12.resolve)(folderPath, child);
1445
- if (!(0, import_fs11.lstatSync)(seasonPath).isDirectory()) continue;
1446
- if ((0, import_fs11.readdirSync)(seasonPath).some(matchesTitle)) return folder;
1448
+ const sp = (0, import_path12.resolve)(destRoot, dir, child);
1449
+ if ((0, import_fs11.lstatSync)(sp).isDirectory()) (0, import_fs11.readdirSync)(sp).forEach(tryFile);
1447
1450
  } catch {
1448
1451
  }
1449
- }
1452
+ });
1450
1453
  } catch {
1451
1454
  }
1452
1455
  }
1453
- return null;
1456
+ return idx;
1454
1457
  };
1455
1458
  var findSeasonFolder = (showPath, season, specialsFolder) => {
1456
1459
  if (!(0, import_fs11.existsSync)(showPath)) return null;
@@ -1480,9 +1483,9 @@ var classifyMovieConfidence = (entry) => {
1480
1483
  return "ambiguous";
1481
1484
  };
1482
1485
  var typeColor = {
1483
- movie: (s) => import_termkit9.Color.cyan.encoder(s),
1484
- tv: (s) => import_termkit9.Color.green.encoder(s),
1485
- book: (s) => import_termkit9.Color.yellow.encoder(s),
1486
+ movie: (s) => import_termkit9.Color.yellow.encoder(s),
1487
+ tv: (s) => import_termkit9.Color.blue.encoder(s),
1488
+ book: (s) => import_termkit9.Color.white.encoder(s),
1486
1489
  ps3: (s) => import_termkit9.Color.magenta.encoder(s)
1487
1490
  };
1488
1491
  var typeGlyph = (t) => typeColor[t]("?");
@@ -1764,7 +1767,7 @@ var scan = async ({ type, hardlink: useHardlink, dryRun, auto, force, interactiv
1764
1767
  showPath = registeredShow.path;
1765
1768
  showFolderName = showPath.split("/").pop() ?? registeredShow.path;
1766
1769
  } else {
1767
- const existingFolder = findShowFolder(destRoot, resolvedTitle) ?? findShowFolderByContent(destRoot, resolvedTitle);
1770
+ const existingFolder = getShowDirIndex(destRoot).get(nTitle(resolvedTitle)) ?? null;
1768
1771
  if (existingFolder) {
1769
1772
  showFolderName = existingFolder;
1770
1773
  showPath = (0, import_path12.resolve)(destRoot, existingFolder);
@@ -1772,6 +1775,7 @@ var scan = async ({ type, hardlink: useHardlink, dryRun, auto, force, interactiv
1772
1775
  showFolderName = formatMovieName(movieFormat, resolvedTitle, resolvedYear);
1773
1776
  showPath = (0, import_path12.resolve)(destRoot, showFolderName);
1774
1777
  if (!dryRun) upsertShow(showPath, tmdbId ?? null, resolvedTitle);
1778
+ getShowDirIndex(destRoot).set(nTitle(resolvedTitle), showFolderName);
1775
1779
  } else {
1776
1780
  pendingTv.push({ entry, entryPath, isDir, parsed, resolvedTitle, destRoot });
1777
1781
  continue;
package/dist/index.mjs CHANGED
@@ -1333,46 +1333,49 @@ var gatherEntries = (source) => {
1333
1333
  }
1334
1334
  return result;
1335
1335
  };
1336
- var findShowFolder = (destRoot, title) => {
1337
- if (!existsSync10(destRoot)) return null;
1338
- const normalize = (s) => s.toLowerCase().replace(/[^a-z0-9]/g, "");
1339
- const target = normalize(title);
1340
- return readdirSync7(destRoot).filter((f) => {
1336
+ var nTitle = (s) => s.toLowerCase().replace(/[^a-z0-9]/g, "");
1337
+ var showDirIndexCache = /* @__PURE__ */ new Map();
1338
+ var getShowDirIndex = (destRoot) => {
1339
+ if (showDirIndexCache.has(destRoot)) return showDirIndexCache.get(destRoot);
1340
+ const idx = /* @__PURE__ */ new Map();
1341
+ showDirIndexCache.set(destRoot, idx);
1342
+ if (!existsSync10(destRoot)) return idx;
1343
+ let dirs;
1344
+ try {
1345
+ dirs = readdirSync7(destRoot);
1346
+ } catch {
1347
+ return idx;
1348
+ }
1349
+ for (const dir of dirs) {
1341
1350
  try {
1342
- return lstatSync4(resolve8(destRoot, f)).isDirectory();
1351
+ if (!lstatSync4(resolve8(destRoot, dir)).isDirectory()) continue;
1343
1352
  } catch {
1344
- return false;
1353
+ continue;
1345
1354
  }
1346
- }).find((f) => normalize(f) === target) ?? null;
1347
- };
1348
- var findShowFolderByContent = (destRoot, title) => {
1349
- if (!existsSync10(destRoot)) return null;
1350
- const normalize = (s) => s.toLowerCase().replace(/[^a-z0-9]/g, "");
1351
- const target = normalize(title);
1352
- const matchesTitle = (name) => {
1353
- if (!isTvEpisodeName(name)) return false;
1354
- const p = parseDownloadName(name);
1355
- return !!p && normalize(p.title) === target;
1356
- };
1357
- for (const folder of readdirSync7(destRoot)) {
1355
+ idx.set(nTitle(dir), dir);
1358
1356
  try {
1359
- const folderPath = resolve8(destRoot, folder);
1360
- if (!lstatSync4(folderPath).isDirectory()) continue;
1361
- const children = readdirSync7(folderPath);
1362
- if (children.some(matchesTitle)) return folder;
1363
- for (const child of children) {
1364
- if (!isSeasonDirName(child)) continue;
1357
+ const children = readdirSync7(resolve8(destRoot, dir));
1358
+ const tryFile = (name) => {
1359
+ if (!isTvEpisodeName(name)) return;
1360
+ const p = parseDownloadName(name);
1361
+ if (p) {
1362
+ const k = nTitle(p.title);
1363
+ if (!idx.has(k)) idx.set(k, dir);
1364
+ }
1365
+ };
1366
+ children.forEach(tryFile);
1367
+ children.forEach((child) => {
1368
+ if (!isSeasonDirName(child)) return;
1365
1369
  try {
1366
- const seasonPath = resolve8(folderPath, child);
1367
- if (!lstatSync4(seasonPath).isDirectory()) continue;
1368
- if (readdirSync7(seasonPath).some(matchesTitle)) return folder;
1370
+ const sp = resolve8(destRoot, dir, child);
1371
+ if (lstatSync4(sp).isDirectory()) readdirSync7(sp).forEach(tryFile);
1369
1372
  } catch {
1370
1373
  }
1371
- }
1374
+ });
1372
1375
  } catch {
1373
1376
  }
1374
1377
  }
1375
- return null;
1378
+ return idx;
1376
1379
  };
1377
1380
  var findSeasonFolder = (showPath, season, specialsFolder) => {
1378
1381
  if (!existsSync10(showPath)) return null;
@@ -1402,9 +1405,9 @@ var classifyMovieConfidence = (entry) => {
1402
1405
  return "ambiguous";
1403
1406
  };
1404
1407
  var typeColor = {
1405
- movie: (s) => Color9.cyan.encoder(s),
1406
- tv: (s) => Color9.green.encoder(s),
1407
- book: (s) => Color9.yellow.encoder(s),
1408
+ movie: (s) => Color9.yellow.encoder(s),
1409
+ tv: (s) => Color9.blue.encoder(s),
1410
+ book: (s) => Color9.white.encoder(s),
1408
1411
  ps3: (s) => Color9.magenta.encoder(s)
1409
1412
  };
1410
1413
  var typeGlyph = (t) => typeColor[t]("?");
@@ -1686,7 +1689,7 @@ var scan = async ({ type, hardlink: useHardlink, dryRun, auto, force, interactiv
1686
1689
  showPath = registeredShow.path;
1687
1690
  showFolderName = showPath.split("/").pop() ?? registeredShow.path;
1688
1691
  } else {
1689
- const existingFolder = findShowFolder(destRoot, resolvedTitle) ?? findShowFolderByContent(destRoot, resolvedTitle);
1692
+ const existingFolder = getShowDirIndex(destRoot).get(nTitle(resolvedTitle)) ?? null;
1690
1693
  if (existingFolder) {
1691
1694
  showFolderName = existingFolder;
1692
1695
  showPath = resolve8(destRoot, existingFolder);
@@ -1694,6 +1697,7 @@ var scan = async ({ type, hardlink: useHardlink, dryRun, auto, force, interactiv
1694
1697
  showFolderName = formatMovieName(movieFormat, resolvedTitle, resolvedYear);
1695
1698
  showPath = resolve8(destRoot, showFolderName);
1696
1699
  if (!dryRun) upsertShow(showPath, tmdbId ?? null, resolvedTitle);
1700
+ getShowDirIndex(destRoot).set(nTitle(resolvedTitle), showFolderName);
1697
1701
  } else {
1698
1702
  pendingTv.push({ entry, entryPath, isDir, parsed, resolvedTitle, destRoot });
1699
1703
  continue;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "reelsort",
3
- "version": "0.2.8",
3
+ "version": "0.2.9",
4
4
  "description": "CLI to rename, organize, and manage your movie and TV library — Plex-compatible naming, hardlink support, and automated watch mode.",
5
5
  "keywords": [
6
6
  "media",