Hacker News new | ask | show | jobs
by netmare 1019 days ago
As long as we're golfing: In PowerShell, using my personal script library:

    F:films> ls -rec -file | gec video | gvi | ndur
    372:18:09
where:

- `ls -rec -file` gets all files recursively under CWD (F:films)

- `gec video` selects video files via extension (gec -> Get-ExtensionCategory)

- `gvi` uses FFPROBE to get video info in custom object (gvi -> Get-VideoInfo)

- `ndur` sums Duration property of objects and converts seconds to 'hhh:mm:ss'

Most people I've shown this have found the syntax and aliases confusing and non-intuitive. They prefer the find/xargs/awk incantations, which, I'm told, are more elegant, correct and precise. After that, I'm usually speechless.

1 comments

>using my personal script library

That's like those hacking scenes where they do:

  $ ./hack
Are those `gec`, `gvi`, certainly `ndur` isn't, part of pwsh default installation? If not how much works it needs to implement them? You may quickly find out why peeps prefer the Unix incantations. (Also will assume only one of those two approaches come with manuals for commands run.)
These are all my scripts. They're object-oriented, self-documented, tab-completable and a `hg clone` away. They're simply more polished versions of what I could do on Windows with built-in PowerShell (and FFPROBE of course):

    F:films> filter probe_format {
        ffprobe $_.fullname -v error -show_entries format=duration -of json |
            convertfrom-json | % format
    }
    F:films> ls -file -rec | ? extension -in .mp4,.avi,.mkv | probe_format |
        measure -sum duration | % { New-TimeSpan -Seconds $_.sum } | % tostring
    15.12:18:09  # same result as before (15days+12hours, etc.)
Even this makes much more sense to me than the Unix equivalent. I realize that Bash/AWK was better than CMD.EXE batch files, but, come on...
That looks pretty nice actually. But can be said the extra need to output and convert from json to object format introduce an extra complexity compared to the similar bash and fam command. Otherwise can see how the others parts (listing all files and choosing by extension, summing up a specific field from the output) can be more intuitive.