From a17fe93f2ef8320db4d20cb9c7cab4a0888ea295 Mon Sep 17 00:00:00 2001 From: iratusmachina Date: Fri, 12 Jan 2024 23:01:05 -0500 Subject: [PATCH] Adding LICENSE --- LICENSE | 24 +++++++++++ go.mod | 2 + go.sum | 2 + internal/cmdline/cmdline.go | 85 +++++++++++++++++++++++++++++++++++++ main.go | 26 ++++++++++++ 5 files changed, 139 insertions(+) create mode 100644 LICENSE create mode 100644 go.sum create mode 100644 internal/cmdline/cmdline.go diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..3c577b0 --- /dev/null +++ b/LICENSE @@ -0,0 +1,24 @@ +This is free and unencumbered software released into the public domain. + +Anyone is free to copy, modify, publish, use, compile, sell, or +distribute this software, either in source code form or as a compiled +binary, for any purpose, commercial or non-commercial, and by any +means. + +In jurisdictions that recognize copyright laws, the author or authors +of this software dedicate any and all copyright interest in the +software to the public domain. We make this dedication for the benefit +of the public at large and to the detriment of our heirs and +successors. We intend this dedication to be an overt act of +relinquishment in perpetuity of all present and future rights to this +software under copyright law. + +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 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. + +For more information, please refer to \ No newline at end of file diff --git a/go.mod b/go.mod index 5a48e7e..fcb478b 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,5 @@ module lyricdownloader go 1.20 + +require github.com/joho/godotenv v1.5.1 diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..d61b19e --- /dev/null +++ b/go.sum @@ -0,0 +1,2 @@ +github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= +github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= diff --git a/internal/cmdline/cmdline.go b/internal/cmdline/cmdline.go new file mode 100644 index 0000000..a2d086c --- /dev/null +++ b/internal/cmdline/cmdline.go @@ -0,0 +1,85 @@ +package cmdline + +import ( + "flag" + "fmt" + "log" + "os" +) + +var ( + printDebug bool + outputFile string +) + +// func searchGoogle(song string, lg *log.Logger) { + +// } + +// func searchGenius(song string, lg *log.Logger) { + +// } + +func Main() int { + programName := os.Args[0] + errorLog := log.New(os.Stderr, "", 0) + mainLog := log.New(os.Stdout, "", 0) + + flags := flag.NewFlagSet(os.Args[0], flag.ExitOnError) + flags.Usage = func() { + out := flags.Output() + fmt.Fprintf(out, "Usage: %v [dir]\n\n", programName) + fmt.Fprint(out, " [dir] is optional; if not passed, '.' is used.\n\n") + fmt.Fprint(out, " By default, the server listens on localhost:8080. Both the\n") + fmt.Fprint(out, " host and the port are configurable with flags. Set the host\n") + fmt.Fprint(out, " to something else if you want the server to listen on a\n") + fmt.Fprint(out, " specific network interface. Setting the port to 0 will\n") + fmt.Fprint(out, " instruct the server to pick a random available port.\n\n") + flags.PrintDefaults() + } + + outputFlag := flags.String("output", "", "Lyrics filename") + verboseFlag := flags.Bool("verbose", false, "Turn on debug. Default is false.") + searchFlag := flags.String("search", "", "Name of song to search. If the name of the song is not a single word, put in quotes\"\"") + + flags.Parse(os.Args[1:]) + + if len(flags.Args()) > 1 { + errorLog.Println("Error: too many command-line arguments") + flags.Usage() + return 1 + } + + allSetFlags := flagsSet(flags) + + songToSearch := *searchFlag + + if len(songToSearch) == 0 { + errorLog.Println("Error: the song name must be provided for search") + flags.Usage() + return 1 + } + + if allSetFlags["output"] { + outputFile = *outputFlag + } else { + mainLog.Printf("Using %s as the name of the file(s) for downloaded lyrics..\n", songToSearch) + } + + printDebug = *verboseFlag + if printDebug { + mainLog.Printf("Output flag: %s, Debug flag: %t, Search flag: %s\n", outputFile, printDebug, songToSearch) + } + + return 0 +} + +// flagsSet returns a set of all the flags what were actually set on the +// command line. +func flagsSet(flags *flag.FlagSet) map[string]bool { + s := make(map[string]bool) + flags.Visit(func(f *flag.Flag) { + s[f.Name] = true + }) + return s +} diff --git a/main.go b/main.go index e69de29..dc5b721 100644 --- a/main.go +++ b/main.go @@ -0,0 +1,26 @@ +package main + +import ( + "fmt" + "lyricdownloader/internal/cmdline" + "os" + + _ "github.com/joho/godotenv/autoload" +) + +// Possible algorithm +// First call the Genius API to get the lyrics +// Second scrape the Google search to get the musicmatch api version of the lyrics +// Compare two of them, If there are the same, print one, else print both files + +// Possible flags -o (output) -versbose (print all debug) -search (the actual song you want to search) + +var geniusApiToken = os.Getenv("GENIUS_API_TOKEN") + +func main() { + + fmt.Println(geniusApiToken) + + os.Exit(cmdline.Main()) + +}