Mise à jour: Voici le script de travail! Géré pour le résoudre! :) Modifiez le chemin de la playlist (le répertoire principal, où tous les sous-dossiers seront créés). Également modifier la longueur de la liste de lecture!
Function Get-MP3Data
{
[CmdletBinding()]
[Alias()]
[OutputType([Psobject])]
Param
(
[String] [Parameter(Mandatory=$true, ValueFromPipeline=$true)] $Directory
)
Begin
{
$shell = New-Object -ComObject "Shell.Application"
}
Process
{
Foreach($Dir in $Directory)
{
$ObjDir = $shell.NameSpace($Dir)
$Files = gci $Dir| ?{$_.Extension -in '.mp3','.mp4'}
Foreach($File in $Files)
{
$ObjFile = $ObjDir.parsename($File.Name)
$MetaData = @{}
$MP3 = ($ObjDir.Items()|?{$_.path -like "*.mp3" -or $_.path -like "*.mp4"})
$PropertArray = 0,1,2,12,13,14,15,16,17,18,19,20,21,22,27,28,36,220,223
Foreach($item in $PropertArray)
{
If($ObjDir.GetDetailsOf($ObjFile, $item)) #To avoid empty values
{
$MetaData[$($ObjDir.GetDetailsOf($MP3,$item))] = $ObjDir.GetDetailsOf($ObjFile, $item)
}
}
New-Object psobject -Property $MetaData |select *, @{n="Directory";e={$Dir}}, @{n="Fullname";e={Join-Path $Dir $File.Name -Resolve}}, @{n="Extension";e={$File.Extension}}
}
}
}
End
{
}
}
# Create playlist
$TotalLength = 0
$MaxLength = 3600
$TempPlaylist = @()
$PlaylistName = 1
$PlaylistPath = "C:\Users\Admin\Desktop\New folder"
if ($TotalLength -lt $MaxLength)
{
ForEach($item in ($PlaylistPath |Get-Mp3Data)){
# Get all song names and song durations
$SongName = $item.Fullname
$Seconds = [int](([datetime]$item.Length).TimeOfDay.TotalSeconds)
# Append song duration to total length and add song to temporary playlist
$TotalLength += $Seconds
$TempPlaylist += ,$SongName
# Create a folder for the playlist if it doesn't exist
if (!(test-path $PlaylistPath\$PlaylistName))
{
New-item -ItemType Directory -Force -Name $PlaylistName -Path $PlaylistPath
Write-Host Created new folder $PlaylistName
}
# Check if the total length is >= maxlength, then move temporary playlist to a new folder
if ($TotalLength -ge $MaxLength)
{
# Loop through all songs in the temporary playlist
For($i=0; $i -lt $TempPlaylist.length; $i++)
{
Move-Item -Path $TempPlaylist[$i] -Destination $PlaylistName
Write-Host Moved file $TempPlaylist[$i] to $PlaylistName
}
# Increment playlist folder name
$PlaylistName++
# Reset the temporary playlist
$TempPlaylist = @()
# Reset the temporary playlist length
$TotalLength = 0
}
}
}
Pour ajouter randomization à elle (de sorte que les fichiers mp3 sont triés au hasard avant inséré dans des listes de lecture), il suffit de changer
ForEach($item in ($PlaylistPath | Get-Mp3Data)){
à
ForEach($item in ($PlaylistPath | Get-Mp3Data) | Sort-Object {Get-Random}){
Essayez powershell mp3 * Durée * Au lieu de la longueur, la longueur est plus communément parler de la taille du fichier. https://superuser.com/questions/704575/get-song-duration-from-an-mp3-file-in-a-script et https://geekeefy.wordpress.com/2016/10/15/powershell- get-mp3mp4-fichiers-métadonnées-et-comment-utiliser-ça-faire-vous-vie-facile /. – TessellatingHeckler
Merci, je vais chercher ça –
@TessellatingHeckler S'il vous plaît vérifier ma réponse ci-dessous. J'ai réussi à le faire fonctionner, mais il y a place à amélioration. Pourriez-vous s'il vous plaît jeter un coup d'œil? Comment puis-je me débarrasser des erreurs? –