-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from garzj/full-migration
Full structured migration
- Loading branch information
Showing
22 changed files
with
707 additions
and
155 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ error/ | |
|
||
# Build | ||
lib/ | ||
build/ | ||
|
||
# Env files | ||
.env | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# we need some image and video processing tools too, so use Debian 12 "Bookworm" as the base so we can get them. | ||
FROM docker.io/node:bookworm | ||
|
||
# get our image and video processing dependencies | ||
RUN apt-get update && apt-get install -y ffmpeg exiftool | ||
|
||
COPY . /app | ||
|
||
WORKDIR /app | ||
# build the application | ||
RUN yarn && yarn build | ||
|
||
ENTRYPOINT [ "yarn", "start" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { flag, number, option, positional, string } from 'cmd-ts'; | ||
|
||
export const errorDirArg = positional({ | ||
type: string, | ||
displayName: 'error_dir', | ||
description: 'Failed media will be saved here.', | ||
}); | ||
|
||
export const timeoutArg = option({ | ||
type: number, | ||
defaultValue: () => 30000, | ||
short: 't', | ||
long: 'timeout', | ||
description: | ||
'Sets the task timeout in milliseconds that will be passed to ExifTool.', | ||
}); | ||
|
||
export const forceArg = flag({ | ||
short: 'f', | ||
long: 'force', | ||
description: "Forces the operation if the given directories aren't empty.", | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import { command, string, positional } from 'cmd-ts'; | ||
import { isEmptyDir } from '../fs/is-empty-dir'; | ||
import { fileExists } from '../fs/file-exists'; | ||
import { errorDirArg, forceArg, timeoutArg } from './common'; | ||
import { migrateDirFlatGen } from '../dir/migrate-flat'; | ||
import { ExifTool } from 'exiftool-vendored'; | ||
import { MediaMigrationError } from '../media/MediaMigrationError'; | ||
|
||
export const migrateFlat = command({ | ||
name: 'google-photos-migrate-flat', | ||
args: { | ||
inputDir: positional({ | ||
type: string, | ||
displayName: 'input_dir', | ||
description: 'The path to your "Google Photos" directory.', | ||
}), | ||
outputDir: positional({ | ||
type: string, | ||
displayName: 'output_dir', | ||
description: 'The path to your flat output directory.', | ||
}), | ||
errorDir: errorDirArg, | ||
force: forceArg, | ||
timeout: timeoutArg, | ||
}, | ||
handler: async ({ inputDir, outputDir, errorDir, force, timeout }) => { | ||
const errs: string[] = []; | ||
const checkErrs = () => { | ||
if (errs.length !== 0) { | ||
errs.forEach((e) => console.error(e)); | ||
process.exit(1); | ||
} | ||
}; | ||
|
||
if (!(await fileExists(inputDir))) { | ||
errs.push(`The specified google directory does not exist: ${inputDir}`); | ||
} | ||
if (!(await fileExists(outputDir))) { | ||
errs.push(`The specified output directory does not exist: ${inputDir}`); | ||
} | ||
if (!(await fileExists(errorDir))) { | ||
errs.push(`The specified error directory does not exist: ${inputDir}`); | ||
} | ||
checkErrs(); | ||
|
||
if (!force && !(await isEmptyDir(outputDir))) { | ||
errs.push( | ||
'The output directory is not empty. Pass "-f" to force the operation.' | ||
); | ||
} | ||
if (!force && !(await isEmptyDir(errorDir))) { | ||
errs.push( | ||
'The error directory is not empty. Pass "-f" to force the operation.' | ||
); | ||
} | ||
if (await isEmptyDir(inputDir)) { | ||
errs.push(`Nothing to do, the source directory is empty: ${inputDir}`); | ||
} | ||
checkErrs(); | ||
|
||
console.log('Started migration.'); | ||
const migGen = migrateDirFlatGen({ | ||
inputDir, | ||
outputDir, | ||
errorDir, | ||
log: console.log, | ||
warnLog: console.error, | ||
exiftool: new ExifTool({ taskTimeoutMillis: timeout }), | ||
endExifTool: true, | ||
}); | ||
const counts = { err: 0, suc: 0 }; | ||
for await (const result of migGen) { | ||
if (result instanceof MediaMigrationError) { | ||
console.error(`Error: ${result}`); | ||
counts.err++; | ||
continue; | ||
} else { | ||
counts.suc++; | ||
} | ||
} | ||
|
||
console.log(`Done! Processed ${counts.suc + counts.err} files.`); | ||
console.log(`Files migrated: ${counts.suc}`); | ||
console.log(`Files failed: ${counts.err}`); | ||
}, | ||
}); |
Oops, something went wrong.