Skip to content

Commit

Permalink
sync script use token from file
Browse files Browse the repository at this point in the history
  • Loading branch information
iBicha committed Sep 11, 2023
1 parent 6c29993 commit f60d8b6
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions tools/profile-sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ function getArgumentParser() {

parser.add_argument('--browser', { help: 'Use cookies from browser' });
parser.add_argument('--invidious', { help: 'Invidious instance to sync to' });
parser.add_argument('--invidious-token-file', { help: 'Invidious auth token. If provided, manual authorization will be skipped' });
parser.add_argument('--output-file', { help: 'Write profile to Invidious JSON compatible file' });
parser.add_argument('--playlist-limit', { help: 'Maximum playlist video count', type: 'int', default: 500 });

Expand Down Expand Up @@ -272,11 +273,13 @@ async function deleteAccessToken(invidiousInstance, token) {
(async () => {
let invidiousInstance = undefined
let token = undefined;
let unregisterToken = false;
try {
const parser = getArgumentParser()
const args = parser.parse_args()

invidiousInstance = args.invidious
invidiousTokenFile = args.invidious_token_file
browser = args.browser
outputFile = args.output_file
playlistLimit = args.playlist_limit
Expand Down Expand Up @@ -317,18 +320,22 @@ async function deleteAccessToken(invidiousInstance, token) {
}
}

token = await getAccessToken(invidiousInstance)
if (!invidiousTokenFile) {
token = await getAccessToken(invidiousInstance)
unregisterToken = true;
} else {
token = fs.readFileSync(invidiousTokenFile, 'utf8');
}

await deletePlaylists(invidiousInstance, token, playlistsToDelete)
await importInvidiousProfile(invidiousInstance, token, profile);
}

}
catch (error) {
console.error(error);
}
finally {
if (token) {
if (token && unregisterToken) {
console.log("Deleting token")
await deleteAccessToken(invidiousInstance, token)
}
Expand Down

0 comments on commit f60d8b6

Please sign in to comment.