Skip to content

Instantly share code, notes, and snippets.

@thraxil
Created January 2, 2018 16:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thraxil/8d858eddd187d8a7a9edb91057d7ee72 to your computer and use it in GitHub Desktop.
Save thraxil/8d858eddd187d8a7a9edb91057d7ee72 to your computer and use it in GitHub Desktop.
yearly music link script
package main
import (
"bufio"
"fmt"
"log"
"os"
"strings"
"github.com/thraxil/bcscrape"
)
func main() {
file, err := os.Open("music.txt")
if err != nil {
log.Fatal(err)
}
defer file.Close()
scanner := bufio.NewScanner(file)
for scanner.Scan() {
line := scanner.Text()
parts := strings.Split(line, " - ")
url := parts[1]
// side effect of this is that the URL is normalized
t, url := bcscrape.DetermineType(url)
if t == "track" {
// we want the album that the track is from
track := bcscrape.NewTrackPage(url)
track.Fetch()
url = track.AlbumURL
}
// get album info
a := bcscrape.NewAlbumPage(url)
a.Fetch()
// print line of markdown
fmt.Printf("* [%s](%s) - [%s](%s)\n", a.Artist, a.ArtistURL, a.Title, a.URL)
}
if err := scanner.Err(); err != nil {
log.Fatal(err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment