From 52fbd5d6bddb25d9ce2119f0d59830240bc6b449 Mon Sep 17 00:00:00 2001 From: TJ Horner Date: Wed, 13 Mar 2019 15:42:12 -0700 Subject: [PATCH] more things --- README.md | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++-- e621/e621.go | 10 ++++++++-- install.sh | 30 +++++++++++++++++++++++++++++ 3 files changed, 89 insertions(+), 4 deletions(-) create mode 100755 install.sh diff --git a/README.md b/README.md index f1ee242..e913300 100644 --- a/README.md +++ b/README.md @@ -12,9 +12,58 @@ It supports concurrently downloading posts, and you can set a maximum number of I made this because I wanted to rewrite one of my previous projects in Go, so I decided to start with this one since it's a pretty small and simple command line tool that encapsulates a lot of concepts in the language (type definition, imports, goroutines, standard libraries, slices, to name a few). -## Installing, Building, etc. +## Installing -See [here](https://github.com/tjhorner/nplcsv/blob/master/README.md) since it uses the same Makefile. +### Prebuilt Binaries + +There is an install script available for Linux/macOS [here](https://github.com/tjhorner/e6dl/blob/master/install.sh). It automatically grabs the latest release (at the time of writing) and saves to `/usr/local/bin/e6dl`. + +### From Source + +Clone repo. + +```bash +# Build e6dl then install it to /usr/local/bin +make install +``` + +You can also install it to a custom path of your choosing: + +```bash +make install INSTALLPATH="/bin" +``` + +If you wanna get rid of it: + +```bash +make uninstall +``` + +## Building + +First, install Go. + +Then just: + +```bash +make build +``` + +`bin/e6dl` will magically appear. You can also just: + +```bash +go run main.go +``` + +To distribute: + +```bash +make dist +``` + +3 files will be spit out in the `dist` directory - one for Windows, one for macOS, and one for Linux. + +You can also run `make dist-win`, `make dist-macos`, or `make dist-linux` to build them individually. ## Example diff --git a/e621/e621.go b/e621/e621.go index bdccac2..c7c14a7 100644 --- a/e621/e621.go +++ b/e621/e621.go @@ -5,6 +5,7 @@ import ( "io/ioutil" "net/http" "strconv" + "time" ) // Post represents an e621 post object returned by the e621 API. @@ -43,8 +44,13 @@ type Post struct { // SerializedDate represents a serialized date passed via JSON type SerializedDate struct { JSONClass string `json:"json_class"` - Seconds int `json:"s"` - Nanoseconds int `json:"n"` + Seconds int64 `json:"s"` + Nanoseconds int64 `json:"n"` +} + +// Time returns a time.Time object representing the SerializedDate +func (date *SerializedDate) Time() time.Time { + return time.Unix(0, date.Nanoseconds) } // GetPostsForTags gets a list of e621 Posts diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..831f2ab --- /dev/null +++ b/install.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +latest_release="v0.0.5" + +case $(uname -s) in + Darwin*) os="darwin";; + Linux*) os="linux";; + *) + echo "Unsupported system type! Please build directly from source." + exit 1 + ;; +esac + +case $(uname -m) in + x86_64*) arch="amd64";; + *) + echo "Unsupported processor architecture! Please build directly from source." + exit 1 + ;; +esac + +echo "Detected system: $os, $arch" +echo "Downloading binary for release $latest_release from GitHub..." + +url="https://github.com/tjhorner/e6dl/releases/download/$latest_release/e6dl-$os-$arch" + +curl $url -Lo /usr/local/bin/e6dl +chmod +x /usr/local/bin/e6dl + +echo "Done! Installed to /usr/local/bin/e6dl. Simply remove this binary to uninstall." \ No newline at end of file