aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--LICENSE19
-rw-r--r--README.md37
-rw-r--r--doc/Makefile37
-rw-r--r--doc/metube.1.scd42
-rw-r--r--doc/metube.5.scd44
-rw-r--r--go.mod5
-rw-r--r--go.sum2
-rw-r--r--metube.go40
8 files changed, 226 insertions, 0 deletions
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..774b542
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,19 @@
+Copyright (c) 2021 Julian Hurst
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..c112585
--- /dev/null
+++ b/README.md
@@ -0,0 +1,37 @@
+# metube
+
+metube is a program for searching youtube and extracting video information such as the title, channel, url, length...
+
+It uses [ytparser](https://git.sr.ht/~ark/ytparser) under the hood.
+
+## Usage
+
+ metube [options] search_term
+ -f string
+ The format to print items in. Follows go template syntax. See metube(5) for more info. (default "channel: {{.ChannelTitle}}, title: {{.Title}}, url: {{.Url}}")
+ -l string
+ The language to search in (follows youtube's language codes: en, fr, de, jp...) (default "en")
+ -o string
+ The criterion to use for the search order (relevance, date, views, rating) (default "relevance")
+ -p int
+ The page to get
+
+## Build & install
+
+To build metube, simply install go and run:
+
+ $ go build
+
+To install, you can run:
+
+ # GOBIN=/usr/local/bin go install
+
+To build the docs, install [scdoc](https://git.sr.ht/~sircmpwn/scdoc) and run:
+
+ $ cd doc
+ $ make
+ # make install
+
+## Patches
+
+Most if not all patches will probably concern [ytparser](https://git.sr.ht/~ark/ytparser).
diff --git a/doc/Makefile b/doc/Makefile
new file mode 100644
index 0000000..5ac3d05
--- /dev/null
+++ b/doc/Makefile
@@ -0,0 +1,37 @@
+.POSIX:
+
+PREFIX?=/usr/local
+_INSTDIR=$(DESTDIR)$(PREFIX)
+MANDIR?=$(_INSTDIR)/share/man
+
+DOCS := \
+ metube.1 \
+ metube.5
+
+
+RM?=rm -f
+
+all: doc
+
+%.1: %.1.scd
+ scdoc < $< > $@
+
+%.5: %.5.scd
+ scdoc < $< > $@
+
+doc: $(DOCS)
+
+clean:
+ $(RM) $(DOCS)
+
+install: all
+ install -D -m 644 -t $(MANDIR)/man1 metube.1
+ install -D -m 644 -t $(MANDIR)/man5 metube.5
+
+uninstall:
+ $(RM) $(MANDIR)/man1/metube.1
+ $(RM) $(MANDIR)/man1/metube.5
+
+.DEFAULT_GOAL := doc
+
+.PHONY: all doc clean install uninstall
diff --git a/doc/metube.1.scd b/doc/metube.1.scd
new file mode 100644
index 0000000..114807a
--- /dev/null
+++ b/doc/metube.1.scd
@@ -0,0 +1,42 @@
+metube(1)
+
+# NAME
+
+metube - A youtube searching program
+
+# DESCRIPTION
+
+metube is a program for searching youtube and extracting video information such
+as the title, channel, url, length...
+
+It uses ytparser under the hood.
+
+# OPTIONS
+
+*-h*
+ Display a help message.
+
+*-f string*
+ The format to print items in. Follows go template syntax. See metube(5)
+ for more info. (default "channel: {{.ChannelTitle}}, title: {{.Title}}, url:
+ {{.Url}}")
+
+*-l string*
+ The language to search in (follows youtube's language codes: en, fr, de,
+ jp...) (default "en")
+
+*-o string*
+ The criterion to use for the search order (relevance, date, views, rating)
+ (default "relevance")
+
+*-p int*
+ The page to get
+
+# SEE ALSO
+
+*metube*(5)
+
+# AUTHORS
+
+Maintained by Julian Hurst <julian.hurst92@gmail.com>. For more information
+about metube, see https://git.sr.ht/~ark/metube.
diff --git a/doc/metube.5.scd b/doc/metube.5.scd
new file mode 100644
index 0000000..22aa9a6
--- /dev/null
+++ b/doc/metube.5.scd
@@ -0,0 +1,44 @@
+metube(5)
+
+# NAME
+
+metube - Video information format for metube(1)
+
+# FORMAT
+
+The format follows go's template format and provides the following variables:
+
+*Id*
+ The id of the video.
+
+*Title*
+ The video's title.
+
+*Url*
+ The youtube url of the video.
+
+*ThumbUrl*
+ The url of the video's thumbnail.
+
+*ChannelId*
+ The id of the video's channel.
+
+*ChannelTitle*
+ The title of the video's channel.
+
+*ChannelUrl*
+ The url of the video's channel.
+
+*Published*
+ The video's published date provided by youtube.
+
+*LengthText*
+ The length of the video.
+
+# SEE ALSO
+
+*metube*(1)
+
+# AUTHOR
+
+Maintained by Julian Hurst <julian.hurst92@gmail.com>. For more information about metube, see https://git.sr.ht/~ark/metube.
diff --git a/go.mod b/go.mod
new file mode 100644
index 0000000..0160c1d
--- /dev/null
+++ b/go.mod
@@ -0,0 +1,5 @@
+module git.sr.ht/~ark/metube
+
+go 1.15
+
+require git.sr.ht/~ark/ytparser v0.0.0-20210109223427-f650ebfaf23d
diff --git a/go.sum b/go.sum
new file mode 100644
index 0000000..f5683fa
--- /dev/null
+++ b/go.sum
@@ -0,0 +1,2 @@
+git.sr.ht/~ark/ytparser v0.0.0-20210109223427-f650ebfaf23d h1:b4fisCeY0QXQcHec9NuPAzE7W8fhmi2TPtO4a3G92M0=
+git.sr.ht/~ark/ytparser v0.0.0-20210109223427-f650ebfaf23d/go.mod h1:/LVNTXoOf1dnQ85TQK3Osw8KK7POmeeqBQUoXivfIPI=
diff --git a/metube.go b/metube.go
new file mode 100644
index 0000000..ca270bc
--- /dev/null
+++ b/metube.go
@@ -0,0 +1,40 @@
+package main
+
+import (
+ "flag"
+ "strings"
+ "bufio"
+ "os"
+
+ "git.sr.ht/~ark/ytparser"
+)
+
+const defaultFormat string = "channel: {{.ChannelTitle}}, title: {{.Title}}, url: {{.Url}}"
+
+func readStdin() string {
+ var b strings.Builder
+ scanner := bufio.NewScanner(os.Stdin)
+ for scanner.Scan() {
+ b.WriteString(scanner.Text())
+ }
+ if err := scanner.Err(); err != nil {
+ panic(err)
+ }
+ return b.String()
+}
+
+func main() {
+ format := flag.String("f", defaultFormat, "The format to print items in. Follows go template syntax. See metube(5) for more info.")
+ page := flag.Int("p", 0, "The page to get")
+ lang := flag.String("l", "en", "The language to search in (follows youtube's language codes: en, fr, de, jp...)")
+ order := flag.String("o", "relevance", "The criterion to use for the search order (relevance, date, views, rating)")
+ flag.Parse()
+ if *format == "-" {
+ *format = readStdin()
+ }
+ items, err := ytparser.Search(strings.Join(flag.Args(), " "), *page, *lang, *order)
+ if err != nil {
+ panic(err)
+ }
+ ytparser.PrintItems(items, *format)
+}