• Operand
  • da ploy? ed.

gram: build

> ./config/nushell/media.nu

Lenses
(coming soon!)


source ./day.nu
source ./disc.nu

def channels [] { echo "needs encoding!" }

def --env "media base" [] { d -b nvme0n1p6; mkcd media; pwd }
  # disc load card/media; mkcd ~/card/media/youtube.com

def "media play" [] { d -b nvme0n1p6;
  mpv ...(tree -afix media/youtube.com/ | lines | where { $in =~ .mkv }) }

def "media place" [
  address: string,
  --key (-k): cell-path = path,
] { media base; (media label $address -k $key) | path expand }

def "media label" [
  address: string,
  --key (-k): cell-path = $.path,
] {
  $address | url parse | # tee { table -e | print } |
    get host $key | update 1 { str substring 1..-1 } | path join
}

def "media bundle" [
  ...addresses: string,
  --label (-l): string,
  --key (-k): cell-path = $.path,
] {
  d -b nvme0n1p6; mkcd media
  $addresses |
    each { media label $in -k $key } | str join "\n" |
    save ([ (day) (cloc) $label bundle index ] | str join '.')
  $addresses |
    each { media address $in -k $key} | uniq |
    tee { str join "\n" | save ([ (day) (cloc) $label bundle key index ] | str join '.') }
}

def "media address" [
  address: string,
  place?: path,
  --key (-k): cell-path = path,
] {
  mkcd (media place $address -k $key)
  print; print; print "----"
  print $"# [media address] Pulling ($address) -> (pwd)"

  (nsh yt-dlp yt-dlp
    --break-per-input # ... see `help yt-dlp`.
    --check-all-formats # ... see `help yt-dlp`.
    --check-formats # ... see `help yt-dlp`.
    --embed-thumbnail # ... see `help yt-dlp`.
    --no-resize-buffer # ... see `help yt-dlp`.
    --prefer-free-formats # ... see `help yt-dlp`.
    --live-from-start # ... see `help yt-dlp`.
# --yes-playlist # ... see `help yt-dlp`.
    # --cookies ~/disc/nvme0n1p6/media/cookies.txt

# log all enabled media encodings
# and capción languages.
# --list-formats
# --list-subs
# --sub-langs all # ... see `help yt-dlp`.
# --write-auto-subs # ... see `help yt-dlp`.

# slice open media packages,
# and pull an audio copy.
    --extract-audio
    --keep-video

    --lazy-playlist # ... see `help yt-dlp`.

# ensure copies are made using closed capcións
# include as many languages as possible.
# [chec] are dubbed audio copies included as an opción?
    --write-pages # ... see `help yt-dlp`.
    --write-subs # ... see `help yt-dlp`.

# log each, and record names and hashes in a cache.
    --download-archive ../arc.log

# signal dials - message packaging.
    --retries 24
# --http-chunk-size 8M
# --buffer-size 16384 # ... see `help yt-dlp`.
    --retry-sleep 12 # ... see `help yt-dlp`.
# --limit-rate 300M
# --throttled-rate 128M

    $address # a generic online media address;
    # many domains are already enrolled.

  ) | tee { save -a ([ (day) (cloc) address log ] | str join '.') } |
  tee { print } | media parse | get 0
  # mpv ...(glob ([ $place *.mkv ] | path join))
}

def "media channel" [...channels: string] {
  $channels | each {|channel| media address $"https://youtube.com/@($channel)" }
}

def "media parse" [] {
  let dl = lines | where { $in =~ '[download]' }
  ( $dl | where { $in =~ 'Destination:' } |
    each { parse -r '\[\w+\] .+:.+\[(?P<label>[a-zA-Z0-9\-]+)\]\.[\w\.]+' | get label.0 }
  ) ++ (
    $dl | where { $in =~ ': has already been recorded in the archive' } |
    each { parse -r '\[download\] (?P<label>[a-zA-Z0-9\-]+): .+$' | get label.0 }
  ) |
  uniq }

def "media records" [] {
  let all = tree -afix ~/disc/nvme0n1p6/media/ | lines
  $in | media parse | each {|l| $all | where { $in =~ $l and $in =~ mkv } } | flatten }