Added reddit downloader
This commit is contained in:
parent
e6743ce3f8
commit
6d36e06449
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
*jpg
|
||||||
|
*jpeg
|
29
reddit-image.nu
Executable file
29
reddit-image.nu
Executable file
|
@ -0,0 +1,29 @@
|
||||||
|
#!/usr/bin/env nu
|
||||||
|
|
||||||
|
def main [--url(-u): string, --download(-d)] {
|
||||||
|
let clipboard = xclip -o
|
||||||
|
let url = $url. | default $clipboard
|
||||||
|
match ($url | str contains "reddit.com") {
|
||||||
|
true => ($url | get_url)
|
||||||
|
false => ("URL is not a valid Reddit URL"; exit 1)
|
||||||
|
} | download_url $download
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# Documentation for handle_url
|
||||||
|
def download_url [download: bool] {
|
||||||
|
let input = $in
|
||||||
|
match $download {
|
||||||
|
true => (wget $input)
|
||||||
|
false => (kitten icat $input)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
def get_url [] {
|
||||||
|
let input = $in
|
||||||
|
let decoded = $input | url decode
|
||||||
|
match ($decoded | str contains "preview") {
|
||||||
|
true => ( ($decoded | parse "{reddit}={imageUrl}?{params}").imageUrl.0 | str replace "preview" "i" )
|
||||||
|
false => ($decoded | parse "{reddit}={imageUrl}").imageUrl.0
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue