This shows you the differences between two versions of the page.
— |
script:powershell:multimedia:youtube:csv [2025/03/17 09:59] (current) admin created |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Utilisation de PowerShell pour Extraire des Données YouTube ====== | ||
+ | ===== Introduction ===== | ||
+ | Dans cet article, nous allons explorer deux scripts PowerShell. Le script permet d'utilise yt-dlp pour extraire des informations de vidéos YouTube et les stocker dans un fichier CSV. | ||
+ | ===== Extraire des Données YouTube ===== | ||
+ | |||
+ | <sxh> | ||
+ | yt-dlp "" --write-annotations --write-info-json --skip-download --write-thumbnail --convert-thumbnails png --ppa "ThumbnailsConvertor:-q:v 1" -o "%(upload_date>%Y-%m-%d)s %(title)+.100U [%(id)s]" --add-metadata --parse-metadata "description:%(webpage_url)s" --write-auto-sub --sub-lang "fr" | ||
+ | |||
+ | # Définir le répertoire d'entrée et le fichier de sortie | ||
+ | $inputDir = "C:\Path\Folder" | ||
+ | $pathToOutputFile = "C:\Path\Folder\Result\Result.csv" | ||
+ | |||
+ | if ((test-path $(split-path $pathToOutputFile -parent)) -eq $false){ | ||
+ | new-item -Path $(split-path $pathToOutputFile -parent) -ItemType Directory -Force | ||
+ | } | ||
+ | |||
+ | # Créer une liste pour stocker les données CSV | ||
+ | $csvData = @() | ||
+ | |||
+ | # Récupérer tous les fichiers JSON dans le répertoire d'entrée de manière récursive | ||
+ | $jsonFiles = Get-ChildItem -Path $inputDir -Recurse -Include *.json | ||
+ | |||
+ | # Pour chaque fichier JSON, extraire les champs nécessaires et les ajouter à la liste CSV | ||
+ | foreach ($jsonFile in $jsonFiles) { | ||
+ | $jsonContent = Get-Content -Path $jsonFile.FullName | ConvertFrom-Json | ||
+ | |||
+ | $csvData += [PSCustomObject]@{ | ||
+ | fulltitle = $jsonContent.title | ||
+ | url = "https://www.youtube.com/watch?v=$($jsonContent.id)" | ||
+ | channel = $jsonContent.channel | ||
+ | description = $jsonContent.description | ||
+ | release_date = $jsonContent.release_date | ||
+ | channel_id = $jsonContent.channel_id | ||
+ | tags = $jsonContent.tags -join ", " | ||
+ | webpage_url = $jsonContent.webpage_url | ||
+ | categories = $jsonContent.categories -join ", " | ||
+ | comment_count = $jsonContent.comment_count | ||
+ | like_count = $jsonContent.like_count | ||
+ | } | ||
+ | } | ||
+ | |||
+ | # Exporter les données CSV dans le fichier de sortie | ||
+ | $csvData | Export-Csv -Path $pathToOutputFile -NoTypeInformation -Encoding UTF8 -Delimiter ';' | ||
+ | |||
+ | Write-Host "Le fichier CSV a été créé à l'emplacement suivant : $pathToOutputFile" | ||
+ | </sxh> |