Skip to content

Instantly share code, notes, and snippets.

@thraxil thraxil/yearly.go
Created Jan 2, 2018

Embed
What would you like to do?
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
You can’t perform that action at this time.