示例#1
0
func ParseVirtualDJTracklist(bufReader *bufio.Reader) []Track {
	var list []Track

	for line, _, err := bufReader.ReadLine(); err != io.EOF; line, _, err = bufReader.ReadLine() {
		data := strings.SplitN(string(line), " : ", 2)
		trackdata := strings.SplitN(data[1], " - ", 2)
		if len(trackdata) != 2 {
			term.OutputError("Error parsing track " + string(data[1]))
			term.OutputMessage("Please enter an artist for this track: ")
			artist, err := term.STD_IN.ReadString('\n')
			if err != nil {
				term.OutputError("Incorrect artist entry.")
				os.Exit(2)
			}
			term.OutputMessage("Please enter a name for this track: ")
			track, err := term.STD_IN.ReadString('\n')
			if err != nil {
				term.OutputError("Incorrect track name entry.")
				os.Exit(2)
			}

			trackdata = []string{artist, track}
		}

		thistrack := new(Track)
		thistrack.Artist = trackdata[0]
		thistrack.Song = trackdata[1]

		list = append(list, *thistrack)
	}

	return list
}
示例#2
0
func getCoverUrlFromInput() string {
	term.OutputMessage("Enter a URL the cover image: ")
	cover_url, err := STD_IN.ReadString('\n')
	if err != nil {
		term.OutputError("Error accepting input.")
		os.Exit(2)
	}
	return strings.TrimRightFunc(cover_url, unicode.IsSpace)
}
示例#3
0
func FetchImage(artistTrack *ArtistTrack) {
	term.OutputMessage(term.Yellow + "Fetching image.." + term.Reset)
	term.OutputMessage(term.Yellow + "." + term.Reset)
	client := http.Client{}

	req, err := http.NewRequest("GET", artistTrack.Tracks[0].Cover, nil)
	if err != nil {
		fmt.Printf("Error - %s", err.Error())
	}
	resp, doError := client.Do(req)
	if doError != nil {
		term.OutputError("Error - " + doError.Error())
	}

	outputImage, _, err := image.Decode(resp.Body)
	artistTrack.Tracks[0].CoverImage = outputImage

	term.OutputMessage(term.Yellow + term.Bold + "DONE!\n" + term.Reset)
}
示例#4
0
func parseTracklist(tracklist *string) []Track {
	var list []Track

	fin, err := os.Open(*tracklist)
	if err != nil {
		term.OutputError(fmt.Sprintf("The file %s does not exist!\n", *tracklist))
		os.Exit(1)
	}
	defer fin.Close()

	bufReader := bufio.NewReader(fin)

	for line, _, err := bufReader.ReadLine(); err != io.EOF; line, _, err = bufReader.ReadLine() {
		data := strings.SplitN(string(line), " : ", 2)
		trackdata := strings.SplitN(data[1], " - ", 2)
		if len(trackdata) != 2 {
			term.OutputError("Error parsing track " + string(data[1]))
			term.OutputMessage("Please enter an artist for this track: ")
			artist, err := STD_IN.ReadString('\n')
			if err != nil {
				term.OutputError("Incorrect artist entry.")
				os.Exit(2)
			}
			term.OutputMessage("Please enter a name for this track: ")
			track, err := STD_IN.ReadString('\n')
			if err != nil {
				term.OutputError("Incorrect track name entry.")
				os.Exit(2)
			}

			trackdata = []string{artist, track}
		}

		thistrack := new(Track)
		thistrack.Artist = trackdata[0]
		thistrack.Song = trackdata[1]

		list = append(list, *thistrack)
	}

	return list
}
示例#5
0
func ParseBasicTracklist(bufReader *bufio.Reader) []Track {
	var list []Track

	regex, err := regexp.Compile(`([0-9]+)(?:.{1}?\s)(.+)(?:\s-\s)(.+)`)
	if err != nil {
		term.OutputError("Error matching strings")
		os.Exit(2)
	}

	for line, _, err := bufReader.ReadLine(); err != io.EOF; line, _, err = bufReader.ReadLine() {

		trackdata := regex.FindAllStringSubmatch(string(line), 3)[0]
		// trackdata := strings.SplitN(data[1], " - ", 2)
		// t
		if len(trackdata) != 4 {
			term.OutputError("Error parsing track " + string(line))
			term.OutputMessage("Please enter an artist for this track: ")
			artist, err := term.STD_IN.ReadString('\n')
			if err != nil {
				term.OutputError("Incorrect artist entry.")
				os.Exit(2)
			}
			term.OutputMessage("Please enter a name for this track: ")
			track, err := term.STD_IN.ReadString('\n')
			if err != nil {
				term.OutputError("Incorrect track name entry.")
				os.Exit(2)
			}

			trackdata = []string{"0", artist, track}
		}

		thistrack := new(Track)
		thistrack.Artist = trackdata[2]
		thistrack.Song = trackdata[3]

		list = append(list, *thistrack)
	}

	return list
}
示例#6
0
func getCoverUrl(db *bolt.DB, artist string, track string) string {
	term.OutputMessage(fmt.Sprintf(term.Green+"Searching for %s - %s.."+term.Reset, artist, track))

	cover_url := GetData(db, artist, track)
	if cover_url != "" {
		term.OutputMessage(term.Green + term.Bold + "DONE!\n" + term.Reset)
	} else {
		term.OutputMessage(term.Green + "." + term.Reset)
		cover_url = itunes.GetCoverFor(artist, track)
		if cover_url == "" {
			term.OutputMessage(term.Green + "." + term.Reset)
			cover_url = google.GetCoverFor(artist, track)
		}
		if cover_url == "" {
			term.OutputMessage(term.Green + ".\n" + term.Reset)
			term.OutputError(fmt.Sprintf("Unable to find a cover for %s - %s", artist, track))
			cover_url = getCoverUrlFromInput()
		}
		if cover_url != "" {
			term.OutputMessage(term.Green + term.Bold + "DONE!\n" + term.Reset)
			InsertData(db, artist, track, cover_url)
		}
	}

	return cover_url
}
示例#7
0
func GetCover(db *bolt.DB, index int, artistTrack *ArtistTrack) bool {
	artist := artistTrack.Artist
	track := artistTrack.Tracks[0].Song

	artistTrack.Tracks[0].Cover = getCoverUrl(db, artist, track)

	if artistTrack.Tracks[0].Cover != "" {
		FetchImage(artistTrack)
		term.OutputImageUrl(artistTrack.Tracks[0].Cover, "Image.jpg")
		term.OutputMessage("Is this the correct image? (y/n) ")
		return AskForConfirmation()
	} else {
		return false
	}
}
示例#8
0
func GetPaginatedCoverFor(artist string, song string, start int) string {
	query := "site:bandcamp.com " + artist + " - " + song + " bandcamp cover art"

	cover_search_url := fmt.Sprintf(GOOGLE_URL, url.QueryEscape(query), start)

	request := BuildHttpRequest(cover_search_url, "GET")
	client := http.Client{}
	resp, doError := client.Do(request)
	defer resp.Body.Close()

	if doError != nil {
		term.OutputError("Error fetching artwork for " + artist + " - " + song + ": " + doError.Error())
	}

	var responseObj *Response = new(Response)

	err := json.NewDecoder(resp.Body).Decode(&responseObj)
	if err != nil {
		term.OutputError(err.Error())
		os.Exit(2)
	}

	var songObj *Result = new(Result)

	if responseObj.Status != 200 {
		term.OutputError(fmt.Sprintf("Error fetching artwork from google - %d", responseObj.Status))
	} else {
		for _, result := range responseObj.Data.Results {
			if strings.Contains(result.OriginalContextUrl, "bandcamp.com") &&
				(strings.Contains(result.ContentNoFormatting, "cover art") ||
					strings.Contains(result.ContentNoFormatting, song) ||
					strings.Contains(result.TitleNoFormatting, song)) ||
				(strings.HasPrefix(result.ContentNoFormatting, song[0:15])) {
				songObj = &result
				break
			}
		}
	}
	if songObj.Url == "" {
		term.OutputMessage(term.Green + "." + term.Reset)
	}
	return songObj.Url
}
示例#9
0
func createImage(selection ArtistTrackList, output_filename string, overlay string) {
	if len(selection) != 9 {
		term.OutputError("Unable to find enough images to make cover")
	} else {
		term.OutputMessage(term.Yellow + "Generating image.." + term.Reset)
		xt := 3
		yt := 3
		width := xt * 160
		height := yt * 160

		dst := image.NewRGBA(image.Rect(0, 0, width, height))
		count := 0
		for y := 0; y < yt; y++ {
			for x := 0; x < xt; x++ {
				term.OutputMessage(term.Yellow + "." + term.Reset)
				src := selection[count].Tracks[0].CoverImage
				draw.Draw(dst, image.Rect(x*160, y*160, (x+1)*160, (y+1)*160), imaging.Thumbnail(src, 160, 160, imaging.CatmullRom), image.Pt(0, 0), draw.Src)
				count = count + 1
			}
		}

		if overlay != "" {
			term.OutputMessage(term.Yellow + "." + term.Reset)
			maskImage(dst, overlay)
			term.OutputMessage(term.Yellow + "." + term.Reset)
		}

		f, err := os.Create(output_filename)
		if err != nil {
			term.OutputError("\ncant save picture: " + err.Error())
		}
		defer f.Close()

		term.OutputMessage(term.Yellow + "." + term.Reset)
		jpeg.Encode(f, dst, nil)
		term.OutputMessage(term.Yellow + term.Bold + "DONE!\n" + term.Reset)
	}
}
示例#10
0
func showAboutMessage() {
	term.OutputMessage(fmt.Sprintf("Build Number: %s\n", MINVERSION))
	term.OutputMessage("Created by: Greg Tangey (http://ignite.digitalignition.net/)\n")
	term.OutputMessage("Website: http://www.rhythmandpoetry.net/\n")
}
示例#11
0
func showWelcomeMessage() {
	term.OutputMessage(term.Green + "Cover Builder v" + VERSION + term.Reset + "\n\n")
}