• Various PowerShell questions and extended file properties

    Home » Forums » Developers, developers, developers » DevOps Lounge » Various PowerShell questions and extended file properties

    Author
    Topic
    #481351

    Win 7 64 bit.

    I am trying to obtain the length of mp3 and mov files using extended file properties. I created a nasty, but working way using VBS but thought I’d give PowerShell a try and found an example to modify.

    It gives me the correct answer SOMETIMES as I test with various files, but sometimes NOT. It is driving me crazy. For a correct answer, I’m using the Length value I can display in Windows Explorer.

    I also realize I must divide length by some value to convert to seconds, but I have to keep changing this value for various files to get the correct answer. 16000 works for one mp3 file, but not another in the same folder. What should be 02:22 comes back as 02:58 for one and 01:00 and 01:01 (which is fine) for another. What the heck am I doing wrong?

    Finally, I have four versions of PS in my start menu…. PS (x86), PS ISE, PS, and PS (x86) ISE. What’s the difference?

    “C:Windowssyswow64Windowspowershellv1.0powershell.exe” -noexit dir “D:AudioSongsOtherSongsTheme 1.mp3″ | Select-object @{Expression={ ‘{0:#,00.00}’ -f ($_.length/16000)};Label=”Playing time”}

    Thanks for any help in any of this.

    Viewing 5 reply threads
    Author
    Replies
    • #1317447

      MP3 files are compressed and the size is related to the amount of music info. Straight division won’t give you an accurate answer.
      5 minute of a single guitar will produce a small file.
      5 minutes of a symphony orchestra will produce a large file.

      cheers, Paul

      • #1317510

        I understand what you are saying and it works correctly when I use objFolder.GetDetailsOf(strFileItem, 27) in vbs.

        PowerShell must have a way to access the information. Does anyone know how?

    • #1317532

      See if Read extend file attributes helps.

      Joe

      --Joe

    • #1318289

      I use TagLib-Sharp (https://github.com/mono/taglib-sharp) for reading MP3 tags. I have been using it with PowerShell for years to manage my MP3 collection. I have all my MP3s organized in a separate folder (not referenced via my music library or anything else) and I use a PowerShell script with taglib-sharp to copy randomly selected MP3s (based on rating and maximum target directory size) to other folders, which I then use to play music in winamp or copy to my MP3 player or to other devices. Part of the report I print at the end is how many hours/minutes/seconds of music I copied.

      I recently have a need to read video data also (mainly the length of the video), and will try using taglig-sharp for that also. I should know in a month or so how that went.

      There are several tutorials on using taglib-sharp. But if interested I could post some code snippets.

      • #1318498

        Thanks for your reply and offer. I REALLY want to spend time getting familiar with PowerShell but know nothing about it at this time so TagLib-Sharp seems way over my head for now.

        I was hoping for a one line command I could enter with a hard coded mp3 filename which would return the song duration which I can direct into my program and parse and use. I didn’t think this would be such a difficult request but it seems I have a talent for asking the simple questions which are not. I do have a way to get the duration using VBS so, unless some PS expert posts the code, I’m stuck for now.

        I don’t even know how to run a PS ‘batch’ file yet but it is on my list!

    • #1318421

      To answer your other question, Windows Powershell (x86) is the 32-bit, and Windows Powershell is the 64-bit console version. Similarly, Windows Powershell (x86) ISE is the 32-bit, and Windows Powershell ISE is the 64-bit Integrated Scripting Environment version.

      • #1318499

        To answer your other question, Windows Powershell (x86) is the 32-bit, and Windows Powershell is the 64-bit console version. Similarly, Windows Powershell (x86) ISE is the 32-bit, and Windows Powershell ISE is the 64-bit Integrated Scripting Environment version.

        Thanks for the info. I still don’t know when to use the console and when to use the ISE, but at least I know the difference and can look it up. I appreciate it.

    • #1318515

      TTTWSL,

      In a nutshell, use the ISE to develope & debug and the console to run your debugged code. :cheers:

      May the Forces of good computing be with you!

      RG

      PowerShell & VBA Rule!
      Computer Specs

      • #1369448

        hello

        use this stuf:

        # $music = [system.Environment]::GetFolderPath(“…………”)
        $list = dir “….. folder name …..” -Recurse | Add-FileDetails
        $list | Where-Object { $_.Extended_length} | Sort-Object Extended_length | Select-Object Name, Extended_length
        $list

        greats
        @renas

    • #1369449
    Viewing 5 reply threads
    Reply To: Various PowerShell questions and extended file properties

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: