Skip to content

Commit

Permalink
Remove Builds, improved build process, added -f flag for optional fil…
Browse files Browse the repository at this point in the history
…ename, slightly better output
  • Loading branch information
CromonMS committed Mar 1, 2019
1 parent 1ff0d0d commit 698c387
Show file tree
Hide file tree
Showing 11 changed files with 66 additions and 2,157 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
allmusic-scrape.zip
/builds
page.html
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2018 Cromon (Eugene Rasini)

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.
28 changes: 21 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,34 @@ Album ID is found at the end of the URL beginning with 'mw'

e.g. on Linux

```./builds/allmusic-scraper-linux -i mw0000275621```
```./builds/allmusic-scraper-linux-amd64 -i mw0000275621```

This will write a file called data.txt with Song Names and Composers
Or with optional filename

### Executables
```./builds/allmusic-scraper-linux-amd64 -i mw0000275621 -f scrape.txt```

Executables are in the builds folder
Run without arguments to get a list of options that can be passed to the binary

Linux - allmusic-scraper-linux
This will write a file called data.txt in the format

#### Unested builds
Artist - Album Title

Song Names [ Composers ]

### Building Binaries

- Clone the repo

- Run ``` ./build-allmusic-scraper.sh```

It is setup to build for the following platforms

Windows 32bit - allmusic-scrape-windows-386.exe

Windows 64bit - allmusic-scrape-windows-amd64.exe

MacOS (untested) - allmusic-scrape-darwin-amd64
MacOS - allmusic-scrape-darwin-amd64

#### For Linux

Run ```go build allmusic-scrape```
1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.0.2-alpha
11 changes: 9 additions & 2 deletions build-allmusic-scraper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,21 @@ fi
package_split=(${package//\// })
package_name=${package_split[-1]}

platforms=("windows/amd64" "windows/386" "darwin/amd64")
platforms=("windows/amd64" "windows/386" "darwin/amd64" "linux/amd64")
BUILD_DIR=builds
VERSION=`cat VERSION`
if [ `ls | grep $BUILD_DIR` ]; then
cd $BUILD_DIR
else
mkdir $BUILD_DIR && cd $BUILD_DIR
fi

for platform in "${platforms[@]}"
do
platform_split=(${platform//\// })
GOOS=${platform_split[0]}
GOARCH=${platform_split[1]}
output_name=$package_name'-'$GOOS'-'$GOARCH
output_name=$package_name'-'$GOOS'-'$GOARCH'-'$VERSION
if [ $GOOS = "windows" ]; then
output_name+='.exe'
fi
Expand Down
Binary file removed builds/allmusic-scrape-darwin-amd64
Binary file not shown.
Binary file removed builds/allmusic-scrape-windows-386.exe
Binary file not shown.
Binary file removed builds/allmusic-scrape-windows-amd64.exe
Binary file not shown.
Binary file removed builds/allmusic-scraper-linux
Binary file not shown.
22 changes: 12 additions & 10 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ import (
)

var (
id string
url string
parent string
page string
id string
url string
parent string
page string
filename string
)

func main() {
Expand All @@ -30,7 +31,7 @@ func main() {
fmt.Printf("Album ID is missing, please re-run\n")
os.Exit(1)
}
err := ioutil.WriteFile("./data.txt", nil, 0754)
err := ioutil.WriteFile(filename, nil, 0754)
check(err)
scrapeAllMusic(id)
}
Expand All @@ -45,6 +46,7 @@ func scrapeAllMusic(id string) {

func init() {
flag.StringVarP(&id, "id", "i", "", "Pass the ID of the allmusic album page")
flag.StringVarP(&filename, "filename", "f", "data.txt", "Pass in an optional filename")
}

func check(e error) {
Expand All @@ -65,7 +67,7 @@ func parseDoc(page string) {

artist := strings.Trim(doc.Find(".album-artist span a").Text(), " ")
album := strings.Trim(doc.Find(".album-title").Text(), " ")
f, err := os.OpenFile("./data.txt", os.O_APPEND|os.O_WRONLY, 0644)
f, err := os.OpenFile(filename, os.O_APPEND|os.O_WRONLY, 0644)
defer f.Close()

f.WriteString(string(artist + " - " + album + "\n"))
Expand All @@ -74,16 +76,16 @@ func parseDoc(page string) {
doc.Find(".title-composer").Each(func(index int, item *goquery.Selection) {
title := strings.Trim(item.Find(".title a").Text(), " ")
composer := strings.Trim(item.Find(".composer a").Text(), " ")
writeRelease(title, composer)
writeRelease(artist, title, composer)
})
check(err)
}

func writeRelease(t, c string) {
f, err := os.OpenFile("./data.txt", os.O_APPEND|os.O_WRONLY, 0644)
func writeRelease(a, t, c string) {
f, err := os.OpenFile(filename, os.O_APPEND|os.O_WRONLY, 0644)
defer f.Close()

f.WriteString(string(t + " - " + c + "\n"))
f.WriteString(string(a + " - " + t + " [" + c + "]" + "\n"))

check(err)
return
Expand Down
Loading

0 comments on commit 698c387

Please sign in to comment.