コード例 #1
0
ファイル: mpd.go プロジェクト: woody7527/MuseBot
func constructSongInfo(songDetails mpd.Attrs, m *MpdBackend) *musebot.SongInfo {
	length, _ := strconv.ParseInt(songDetails["Time"], 10, 0)

	musicUrl := songDetails["file"]
	if songDetails["file"][0:7] != "file://" {
		musicUrl = "file://" + m.musicDir + musicUrl
	}

	//stickermap, _ := m.client.StickerGet("song", songDetails["file"], "coverarturl")
	stickermap_b, _ := m.client.StickerGet("song", songDetails["file"], "songinfo")

	si := musebot.SongInfo{}
	//log.Println(si, stickermap_b["songinfo"])
	err := json.Unmarshal([]byte(stickermap_b["songinfo"]), &si)
	if err == nil {
		var wasOk bool
		sdp, wasOk := si.ProviderName.(string)
		if wasOk {
			si.Provider, wasOk = musebot.CurrentProviders[sdp]
		}
	} else {
		si.ProviderName = "<<LOCAL>>"
		si.Title = songDetails["Title"]
		si.Album = songDetails["Album"]
		si.Artist = songDetails["Artist"]
	}
	si.MusicUrl = musicUrl
	si.Length = int(length)
	si.Id = songDetails["Id"]
	return &si
}
コード例 #2
0
ファイル: mpd.go プロジェクト: woody7527/MuseBot
func (m *MpdBackend) Add(s musebot.SongInfo) error {
	m.ifNotPlayingEmptyQueue()

	// here goes
	path := s.MusicUrl

	// this should be a local filesystem path by now...
	if len(path) == 0 || path[0] != '/' {
		err := errors.New("MpdBackend: path invalid for song with path " + path)
		log.Println("Error adding song to queue: non-absolute path!", err)
		return err
	}

	if !strings.HasPrefix(path, m.musicDir) {
		hash := sha256.New()
		hash.Write([]byte(s.MusicUrl))
		// we need the suffix
		endBit := strings.LastIndex(path, ".")
		newPath := m.musicDir + "/zz_" + hex.EncodeToString(hash.Sum([]byte{})) + path[endBit:]
		os.Symlink(path, newPath)

		s.MusicUrl = newPath
	}
	s.MusicUrl = s.MusicUrl[len(m.musicDir):]

	log.Println(s)
	log.Println(s.MusicUrl)

	// defer this
	defer m.forcePlayback()

	s.ProviderName = s.Provider.PackageName()
	s.Provider = nil
	jsonS, err := json.Marshal(s)

	m.client.Update(s.MusicUrl)
	m.client.StickerSet("song", s.MusicUrl, "coverarturl", s.CoverArtUrl)
	if err == nil {
		m.client.StickerSet("song", s.MusicUrl, "songinfo", string(jsonS))
	}

	return m.client.Add(s.MusicUrl)
}
コード例 #3
0
ファイル: grooveshark.go プロジェクト: woody7527/MuseBot
func (p *GroovesharkProvider) FetchSong(song *musebot.SongInfo, comms chan musebot.ProviderMessage) {
	// this should be run inside a goroutine :P
	// here goes
	if song.ProviderName != p.PackageName() {
		// what. the. hell.
		comms <- musebot.ProviderMessage{"error", errors.New("Song was not from this provider!")}
	}

	downloadLocation := p.cacheDir + "/" + (song.ProviderId) + ".mp3"

	if c, _ := doesFileExist(downloadLocation); !c {
		// GO GO GO
		params := map[string]interface{}{}
		params["mobile"] = false
		params["prefetch"] = false
		params["songID"] = song.ProviderId
		params["country"] = p.info.headers["country"]

		comms <- musebot.ProviderMessage{"stages", 1}
		comms <- musebot.ProviderMessage{"current_stage", 1}
		comms <- musebot.ProviderMessage{"current_stage_description", "Downloading file..."}

		res, err := p.apiCall("getStreamKeyFromSongIDEx", params)
		if err != nil {
			comms <- musebot.ProviderMessage{"error", err}
			return
		}

		// now we need two pieces of iformation:
		// the streamKey, and the ip
		_, didFail := ((res.(map[string]interface{}))["result"]).([]interface{})
		if didFail {
			comms <- musebot.ProviderMessage{"error", errors.New("That song appears to no longer exist!")}
			return
		}

		resMap := ((res.(map[string]interface{}))["result"]).(map[string]interface{})
		resStreamKey := (resMap["streamKey"]).(string)
		resIp := (resMap["ip"]).(string)

		finalUrl := "http://" + resIp + "/stream.php?streamKey=" + resStreamKey // phew!
		downloadFileAndReportProgress(finalUrl, downloadLocation, comms)
	} else {
		comms <- musebot.ProviderMessage{"stages", 0}
		// awesome
	}

	song.MusicUrl = downloadLocation

	// that's actually us done! :)
	comms <- musebot.ProviderMessage{"done", nil}
}