-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
136 additions
and
3 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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// declaring module will allow typescript to import the module | ||
declare module "csv-iter-parse" { | ||
// typing module default export as `any` will allow you to access its members without compiler warning | ||
type Apps = { | ||
csv_async_iter: any; | ||
}; | ||
|
||
const ts: Apps; | ||
export = ts; | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,71 @@ | ||
<script lang="ts"> | ||
import { PassthroughBlobProvider, ZipReader } from "async-zip-reader"; | ||
import { csv_async_iter } from "csv-iter-parse"; | ||
export let channelsIdsTakeoutSave: (channelIDs: string[]) => void; | ||
let files: FileList; | ||
let isLoading = false; | ||
const subCsvPath = | ||
"Takeout/YouTube and YouTube Music/subscriptions/subscriptions.csv"; | ||
async function handleFileSelect(file: File) { | ||
const zip = await ZipReader.init(new PassthroughBlobProvider(file)); | ||
const zipEntry = zip.files.find((x) => x.path === subCsvPath); | ||
if (zipEntry) { | ||
const subscriptCSVFile = await zip.extract(zipEntry); | ||
const channelIds: string[] = []; | ||
let isFirstRow = true; | ||
for await (let row of csv_async_iter(subscriptCSVFile.stream())) { | ||
if (isFirstRow) { | ||
isFirstRow = false; | ||
continue; | ||
} | ||
const id = row[0]; | ||
if (id) channelIds.push("channel/" + id); | ||
} | ||
channelsIdsTakeoutSave(channelIds); | ||
} | ||
} | ||
const fileCheck = async () => { | ||
if (files && !isLoading) { | ||
const file = files.item(0); | ||
if (file) { | ||
try { | ||
isLoading = true; | ||
await handleFileSelect(file); | ||
} catch (error) { | ||
console.log(error); | ||
} finally { | ||
isLoading = false; | ||
} | ||
} | ||
} | ||
}; | ||
$: { | ||
console.log(files); | ||
fileCheck(); | ||
} | ||
</script> | ||
|
||
<div class="space-y-2 m-1 p-1 form-control"> | ||
<div class="font-bold text-sm">Takeout import</div> | ||
<div class="relative w-full h-full"> | ||
{#if isLoading} | ||
<div | ||
class="absolute w-full flex justify-center items-center backdrop-blur-sm h-full rounded" | ||
> | ||
<div class="loading" /> | ||
</div> | ||
{/if} | ||
<input | ||
bind:files | ||
name="Takeout" | ||
class="file-input w-full file-input-sm" | ||
type="file" | ||
/> | ||
</div> | ||
</div> |
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