Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Create a table that holds the exported URLs
- $table = Import-CSV C:\path\to\csvfile.csv
- # Create an array to store all JSON objects
- $masterArray = @()
- # Iterate through each row in the table
- foreach ($row in $table) {
- # Create the JSON structure
- $jsonObject = [PSCustomObject]@{
- Title = $row.Title
- URL = $row.URL
- video_id = $row.video_id
- Transcript = (youtube_transcript_api.exe $row.video_id --format text)
- }
- # Add the object to the master array
- $masterArray += $jsonObject
- # Save individual JSONs if needed
- $jsonOutput = $jsonObject | ConvertTo-Json -Depth 3
- $fileName = ($row.Title -replace '[^\w\d]', '_') + "1" + ".json"
- Set-Content -Path "C:\temp\transcripts\$fileName" -Value $jsonOutput
- }
- # Convert the master array to JSON format
- $masterJson = $masterArray | ConvertTo-Json -Depth 3
- # Save the master JSON file
- Set-Content -Path "C:\temp\transcripts\master_transcripts.json" -Value $masterJson
Advertisement
Add Comment
Please, Sign In to add comment