-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmove_good_videos.ts
70 lines (57 loc) · 2.06 KB
/
move_good_videos.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import { isShuffleEnabled, getCurrentMedia, decodeUri, moveFile, advancePlaylist, removeMostRecentlyPlayedPlaylistItem, log, lastPlayedItemId, recentlyPlayedIds, deleteFile } from "./function_list.ts";
import { shouldDelete, shouldMove } from "./config.ts";
main()
// Main function
async function main() {
try {
// Check shuffle status first
const shuffleEnabled = await isShuffleEnabled();
if (!shuffleEnabled) {
log("Warning: Shuffle is not enabled. This script works best with shuffle enabled.");
}
// Get current media and ID before doing anything else
const mediaUri = await getCurrentMedia();
// Check if mediaUri is null
if (!mediaUri) {
log("No media to process. Exiting.");
return;
}
const currentId = lastPlayedItemId; // Store locally to ensure it doesn't change
if (!currentId) {
throw new Error("Failed to get current item ID");
}
// Decode the URI
log("Decoding URL encoding...");
const filePath = decodeUri(mediaUri.replace("file://", ""));
log(`Decoded media path: ${filePath}`);
// Only proceed with playlist operations if file operation was successful
try {
// First advance to the next item
await advancePlaylist();
// Perform the selected operation
if (shouldDelete) {
await deleteFile(filePath);
} else if (shouldMove) {
await moveFile(filePath);
} else {
log("No operation selected. Exiting.");
Deno.exit(1);
}
// Then remove the previous item after we've successfully advanced
await removeMostRecentlyPlayedPlaylistItem();
} catch (playlistError: unknown) {
if (playlistError instanceof Error) {
log(`Warning: Playlist operation failed: ${playlistError.message}`);
} else {
log(`Warning: Unknown playlist operation error: ${String(playlistError)}`);
}
}
} catch (error: unknown) {
if (error instanceof Error) {
log(`Error: ${error.message}`);
} else {
log(`Unknown error: ${String(error)}`);
}
Deno.exit(1);
}
}