Exemplo n.º 1
0
void Lyrics::update()
{
#	ifdef HAVE_CURL_CURL_H
	if (isReadyToTake)
		Take();
	
	if (isDownloadInProgress)
	{
		w.flush();
		w.refresh();
	}
#	endif // HAVE_CURL_CURL_H
	if (ReloadNP)
	{
		const MPD::Song s = myPlaylist->nowPlayingSong();
		if (!s.empty() && !s.getArtist().empty() && !s.getTitle().empty())
		{
			drawHeader();
			itsScrollBegin = 0;
			itsSong = s;
			Load();
		}
		ReloadNP = 0;
	}
}
Exemplo n.º 2
0
std::string Lyrics::GenerateFilename(const MPD::Song &s)
{
	std::string filename;
	if (Config.store_lyrics_in_song_dir)
	{
		if (s.isFromDatabase())
		{
			filename = Config.mpd_music_dir;
			filename += "/";
			filename += s.getURI();
		}
		else
			filename = s.getURI();
		// replace song's extension with .txt
		size_t dot = filename.rfind('.');
		assert(dot != std::string::npos);
		filename.resize(dot);
		filename += ".txt";
	}
	else
	{
		std::string file = s.getArtist();
		file += " - ";
		file += s.getTitle();
		file += ".txt";
		removeInvalidCharsFromFilename(file);
		filename = Config.lyrics_directory;
		filename += "/";
		filename += file;
	}
	return filename;
}
Exemplo n.º 3
0
void Lyrics::DownloadInBackground(const MPD::Song &s)
{
	if (s.empty() || s.getArtist().empty() || s.getTitle().empty())
		return;
	
	std::string filename = GenerateFilename(s);
	std::ifstream f(filename.c_str());
	if (f.is_open())
	{
		f.close();
		return;
	}
	Statusbar::msg("Fetching lyrics for \"%s\"...", s.toString(Config.song_status_format_no_colors, Config.tags_separator).c_str());
	
	MPD::Song *s_copy = new MPD::Song(s);
	pthread_mutex_lock(&itsDIBLock);
	if (itsWorkersNumber == itsMaxWorkersNumber)
		itsToDownload.push(s_copy);
	else
	{
		++itsWorkersNumber;
		pthread_t t;
		pthread_attr_t attr;
		pthread_attr_init(&attr);
		pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
		pthread_create(&t, &attr, DownloadInBackgroundImpl, s_copy);
	}
	pthread_mutex_unlock(&itsDIBLock);
}
Exemplo n.º 4
0
void Lyrics::DownloadInBackgroundImplHelper(const MPD::Song &s)
{
	std::string artist = Curl::escape(s.getArtist());
	std::string title = Curl::escape(s.getTitle());
	
	LyricsFetcher::Result result;
	bool fetcher_defined = itsFetcher && *itsFetcher;
	for (LyricsFetcher **plugin = fetcher_defined ? itsFetcher : lyricsPlugins; *plugin != 0; ++plugin)
	{
		result = (*plugin)->fetch(artist, title);
		if (result.first)
			break;
		if (fetcher_defined)
			break;
	}
	if (result.first == true)
		Save(GenerateFilename(s), result.second);
}