func DoItAll(songs_dir string) { var urls []string songs_body := webutils.GetWebBody(BaseUri) slugs := ScrapeSlugs(songs_body) for _, slug := range slugs { mid_body := webutils.GetWebBody(BaseUri + slug) urls = append(urls, ScrapeMidUrl(mid_body)) } DownloadMids(urls, songs_dir) }
func GetTopLink(song_name string) string { query := CleanSongName(song_name) song_query := BaseUri + query log.Printf("Getting top lyrics result link for %s\n", query) search_body := webutils.GetWebBody(song_query) return ScrapeTopLink(search_body) }
func ScrapeLyrics(song_file, lyrics_dir string) { save_name := CreateSaveName(song_file) if !LyricsAlreadyDownloaded(song_file, lyrics_dir) { top_link := GetTopLink(song_file) if top_link == "" { return } lyrics_page := webutils.GetWebBody(top_link) lyrics := ScrapeLyricsFromPage(lyrics_page) lyrics_file, _ := os.Create(path.Join(lyrics_dir, save_name)) for _, lyric := range lyrics { lyrics_file.WriteString(lyric) } } else { file, err := os.Open(path.Join(lyrics_dir, save_name)) if err != nil { log.Fatal(err) } defer file.Close() scanner := bufio.NewScanner(file) for scanner.Scan() { fmt.Println(scanner.Text()) time.Sleep(1 * time.Second) } } }