Created
January 2, 2018 16:37
-
-
Save thraxil/8d858eddd187d8a7a9edb91057d7ee72 to your computer and use it in GitHub Desktop.
yearly music link script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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