コード例 #1
0
ファイル: network.cpp プロジェクト: Unymicle/NetEase
void NetWork::dealLyric(QNetworkReply *reply)
{
	QJsonObject obj = getObject(*reply);
	if (obj.isEmpty())
		return;
	QJsonObject lrcObj = obj.find("lrc").value().toObject();
	QString strLyric = lrcObj.find("lyric").value().toString();
	if (strLyric == "")
		strLyric = "当前歌曲没有歌词";
	emit lyric(strLyric);
}
コード例 #2
0
ファイル: lyricfile.cpp プロジェクト: DchunWang/Haku
//载入歌词文件,使其成为程序中能够处理的一个对象
void LyricFile::loadLyricFile()
{
    //暂时只用绝对路径,之后得修改为能够自动寻找到歌词文件的函数来
    //lyricFileDir  = "F:\\Music\\杀阵.lrc";

    //以所在路径的歌词文件新建一个对象????(
    //QFile lyric(lyricFileDir);
    QFile lyric("F:\\Music\\杀阵.lrc");

    lyric.open(QIODevice::ReadOnly);


    //注意,这里缺少错误处理,也即如果打不开或没有歌词文件时的应对,之后得补上!!!!
//    if(!lyric.open(QIODevice::ReadOnly | QIODevice::Text))
//    {
//            //这里应该要有错误处理,之后补上!!!
//    }

    //处理.lyc歌词文件时二进制文件吗???
   // QDataStream lyricStream(&lyric);

    //直接将歌词文件读取到QString类型对象中,
    QString lyricStream = QString(lyric.readAll());
    //openTest = lyricStream;
    //openTest = lyricStream;

    lyricFileList = lyricStream.split("\n");

    //测试用,看二进制是否是这样转换为QString格式
//    QString testLrcStr;
//    lyricStream >> testLrcStr;

    //歌词文件不是文本文件??暂时注释掉,用二进制的处理方式尝试下,看能不能处理歌词类型的文件
    //QTextStream lyricStream(&lyric);
    //将歌词文件的每一行(包含时间与歌词)保存都QStringList中,方便之后处理
//    while(!lyricStream.atEnd())
//    {
//        //读取歌词对象的每一行,并添加到lyricFileList中
//        QString temp = lyricStream.readLine();
//        lyricFileList.append(temp);
//    }

    /* 经过以上的处理,歌词文件就按行(包括时间与歌词)保存到lyricFileList中了,
     * 之后就对其再进行更加精细的处理,分别提取出时间与歌词,同时时间与歌词还要对应起来
     * 但这里有一个问题:那就是原来歌词文件每行都应该是只有一句歌词及其时间,不能有多句歌词
     * 在一行中!!!
     * 针对有多句歌词在同一行的歌词文件,之后再补充对其的处理
     * */

    //因为采用二进制转QString,所以暂时注释掉下面这句,换做QString做参数
    splitLyricFile(lyricFileList);
    //splitLyricFile(testLrcStr);
}
コード例 #3
0
    void PianorollTrackView::onLyricEditCommitSlot() {
        const VSQ_NS::Event *event = lyricEdit->event();
        if (!event) return;

        VSQ_NS::Lyric originalLyric = event->lyricHandle.getLyricCount() == 0
                ? VSQ_NS::Lyric("a", "a")
                : event->lyricHandle.getLyricAt(0);

        // TODO(kbinani): separate into phrases

        std::string word;
        std::string symbol;
        if (lyricEdit->symbolEditMode) {
            word = originalLyric.phrase;
            symbol = lyricEdit->text().toStdString();
        } else {
            word = lyricEdit->text().toStdString();

            if (originalLyric.isProtected) {
                symbol = originalLyric.getPhoneticSymbol();
            } else {
                symbol = "a";
                const VSQ_NS::PhoneticSymbolDictionary::Element *element
                        = controllerAdapter->attachPhoneticSymbol(word);
                if (element) symbol = element->symbol();
            }
        }

        VSQ_NS::Lyric lyric(word, symbol);
        lyric.isProtected = lyricEdit->symbolEditMode
                ? true
                : originalLyric.isProtected;
        VSQ_NS::Event edited = *lyricEdit->event();
        if (edited.lyricHandle.getLyricCount() == 0) {
            edited.lyricHandle.addLyric(lyric);
        } else {
            edited.lyricHandle.setLyricAt(0, lyric);
        }

        if (edited.lyricHandle.getLyricCount() != event->lyricHandle.getLyricCount() ||
                !lyric.equals(originalLyric)) {
            EditEventCommand command(trackIndex, lyricEdit->event()->id, edited);
            controllerAdapter->execute(&command);
            updateWidget();
        }
    }
コード例 #4
0
    void PropertyValueProxy::add(const VSQ_NS::Event *item, const VSQ_NS::Sequence *sequence) {
        VSQ_NS::Lyric lyric("a", "a");
        if (0 < item->lyricHandle.getLyricCount()) {
            lyric = item->lyricHandle.getLyricAt(0);
        }

        VSQ_NS::tick_t clock = item->clock;
        int measure, beat, tick;
        getNotelocation(item->clock, &measure, &beat, &tick, sequence);

        int vibType = 0;
        int vibLength = 0;
        if (item->vibratoHandle.getHandleType() == VSQ_NS::HandleType::VIBRATO) {
            if (item->vibratoHandle.iconId.length() == 9 && 0 < item->getLength()) {
                std::string vibTypeString = item->vibratoHandle.iconId.substr(6);
                vibType = StringUtil::parseInt<int>(vibTypeString, 16) + 1;
                vibLength = item->vibratoHandle.getLength();
            }
        }

        setValue(&lyricPhrase, lyric.phrase);
        setValue(&lyricPhoneticSymbol, lyric.getPhoneticSymbol());
        setValue(&lyricConsonantAdjustment, lyric.getConsonantAdjustment());
        setValue(&lyricProtect, lyric.isProtected ? 2 : 1);

        setValue(&noteLength, item->getLength());
        setValue(&noteNumber, item->note);

        setValue(&notelocationClock, clock);
        setValue(&notelocationMeasure, measure);
        setValue(&notelocationBeat, beat);
        setValue(&notelocationTick, tick);

        setValue(&vibratoType, vibType);
        setValue(&vibratoLength, vibLength);

        isFirst = false;
    }
コード例 #5
0
pfc::string8 provider_azlyrics::lookup_one(unsigned p_index, const metadb_handle_ptr & p_meta, threaded_process_status & p_status, abort_callback & p_abort)
{
	TRACK_CALL_TEXT("provider_azlyrics::lookup_one");

	const float threshold = 0.8f;

	// Regular Expression Class
	CRegexpT<char> regexp;

	// Buffer
	pfc::string8 buff;

	try
	{
		TRACK_CALL_TEXT("Try");
		// Init fetcher
		curl_wrapper_simple fetcher(&m_config_item);

		const metadb_handle_ptr & p = p_meta;

		if (p.is_empty())
		{
			return "";
		}

		pfc::string8_fast artist, title, album;
		static_api_ptr_t<titleformat_compiler> compiler;
		service_ptr_t<titleformat_object> script;

		file_info_impl info;
		p->get_info(info);

		// Get count of artists
		t_size count = info.meta_get_count_by_name("artist");

		// Get TITLE
		title = info.meta_get("title", 0);

		// Iterate through all artists listed
		for (int j = 0; j < count; j++)
		{
			TRACK_CALL_TEXT("For");
			// Get Artist
			artist = info.meta_get("artist", j);

			console::printf("%s - %s", artist, title);

			// Search the lyrics
			pfc::string8_fast url("http://search.azlyrics.com/search.php?q=");

			url += fetcher.quote(artist);
			url += "+";
			url += fetcher.quote(title);

			// Get it now
			try
			{
				fetcher.fetch(url, buff);
			}
			catch (pfc::exception & e)
			{
				console_error(e.what());
				continue;
			}
			catch (...)
			{
				continue;
			}

			if (buff.get_length() == 0)
				continue;

			int resultStart = buff.find_first("<b>1.</b>");
			int startUrl = buff.find_first("<a href=\"", resultStart) + 9;
			int endUrl = buff.find_first("\"", startUrl);

			url = pfc::string8_fast(buff.get_ptr()+startUrl, endUrl - startUrl);

			// Get it now
			try
			{
				fetcher.fetch(url, buff);
			}
			catch (pfc::exception & e)
			{
				console_error(e.what());
				continue;
			}
			catch (...)
			{
				continue;
			}

			if (buff.get_length() == 0)
				continue;

			const char * regex_lyrics = "<!-- END OF RINGTONE 1 -->\\s*?<b>\"(?P<title>.*?)\"</b><br>\\s*?<br>\\s\\s(?P<lyrics>.*?)\\s<br>";

			// expression for extract lyrics
			regexp.Compile(regex_lyrics, IGNORECASE | SINGLELINE);

			int noGroup = regexp.GetNamedGroupNumber("lyrics");
			int noTitle = regexp.GetNamedGroupNumber("title");

			MatchResult result = regexp.Match(buff.get_ptr());

			if (result.IsMatched())
			{
				int nStart = result.GetGroupStart(noTitle);
				int nEnd = result.GetGroupEnd(noTitle);

				pfc::string8_fast songTitle(buff.get_ptr() +nStart, nEnd - nStart);

				int levDist = LD(title, title.get_length(), songTitle, songTitle.get_length());

				float good = 1.0f - ((float)levDist / title.get_length());

				if (good < threshold)
					return "";

				nStart = result.GetGroupStart(noGroup);
				nEnd = result.GetGroupEnd(noGroup);

				pfc::string8 lyric(buff.get_ptr() + nStart, nEnd - nStart);

				convert_html_to_plain(lyric);

				if (lyric.get_length() > 0)
				{
					string_helper::remove_end_linebreaks(lyric);

					return lyric;
				}
			}
		}
	}
	catch (pfc::exception & e)
	{
		console_error(e.what());
		return "";
	}
	catch (...)
	{
		return "";
	}

	return "";
}
コード例 #6
0
//************************************************************************
//*                              AZ Lyrics                               *
//************************************************************************
pfc::string_list_impl * provider_azlyrics::lookup(unsigned p_index, metadb_handle_list_cref p_meta, threaded_process_status & p_status, abort_callback & p_abort)
{
	TRACK_CALL_TEXT("provider_azlyrics::lookup");
	const float threshold = 0.8f;

	// Regular Expression Class
	CRegexpT<char> regexp;

	// Buffer
	pfc::string8 buff;
	pfc::string_list_impl * str_list = new pfc::string_list_impl;

	try
	{
		// Init fetcher
		curl_wrapper_simple fetcher(&m_config_item);

		for (t_size i = 0; i < p_meta.get_count(); ++i)
		{
			if (p_abort.is_aborting())
				break;

			// Sleep
			how_to_sleep(i);
			// Clear buff
			buff.reset();

			const metadb_handle_ptr & p = p_meta.get_item(i);

			if (p.is_empty())
			{
				str_list->add_item("");
				continue;
			}

			// Set progress
			pfc::string8_fast path = file_path_canonical(p->get_path());

			// add subsong index?
			if (p->get_subsong_index() > 0)
			{
				path.add_string(" /index:");
				path.add_string(pfc::format_uint(p->get_subsong_index()));
			}

			p_status.set_item_path(path);
			p_status.set_progress(i + 1, p_meta.get_count());

			pfc::string8_fast artist, title;

			file_info_impl info;
			p->get_info(info);

			// Get count of artists
			t_size count = info.meta_get_count_by_name("artist");

			// Get TITLE
			title = info.meta_get("title", 0);

			bool found = false;

			// Iterate through all artists listed
			for (int j = 0; j < count && !found; j++)
			{
				// Get Artist
				artist = info.meta_get("artist", j);

				// Search the lyrics
				pfc::string8_fast url("http://search.azlyrics.com/search.php?q=");

				url += fetcher.quote(artist);
				url += "+";
				url += fetcher.quote(title);

				// Get it now
				try
				{
					fetcher.fetch(url, buff);
				}
				catch (pfc::exception & e)
				{
					console_error(e.what());
					continue;
				}
				catch (...)
				{
					continue;
				}

				int resultStart = buff.find_first("<b>1.</b>");
				int startUrl = buff.find_first("<a href=\"", resultStart) + 9;
				int endUrl = buff.find_first("\"", startUrl);

				url = pfc::string8_fast(buff.get_ptr()+startUrl, endUrl - startUrl);

				// Get it now
				try
				{
					fetcher.fetch(url, buff);
				}
				catch (pfc::exception & e)
				{
					console_error(e.what());
					continue;
				}
				catch (...)
				{
					continue;
				}

				const char * regex_lyrics = "<!-- END OF RINGTONE 1 -->\\s*?<b>\"(?P<title>.*?)\"</b><br>\\s*?<br>\\s\\s(?P<lyrics>.*?)\\s<br>";

				// expression for extract lyrics
				regexp.Compile(regex_lyrics, IGNORECASE | SINGLELINE);

				int noGroup = regexp.GetNamedGroupNumber("lyrics");
				int noTitle = regexp.GetNamedGroupNumber("title");

				// match
				MatchResult result = regexp.Match(buff.get_ptr());

				if (result.IsMatched())
				{
					int nStart = result.GetGroupStart(noTitle);
					int nEnd = result.GetGroupEnd(noTitle);

					pfc::string8_fast songTitle(buff.get_ptr() +nStart, nEnd - nStart);

					int levDist = LD(title, title.get_length(), songTitle, songTitle.get_length());

					float good = 1.0f - ((float)levDist / title.get_length());

					if (good < threshold)
						continue;

					nStart = result.GetGroupStart(noGroup);
					nEnd = result.GetGroupEnd(noGroup);

					pfc::string8 lyric(buff.get_ptr() + nStart, nEnd - nStart);

					convert_html_to_plain(lyric);

					if (lyric.get_length() > 0)
					{
						string_helper::remove_end_linebreaks(lyric);

						str_list->add_item(lyric);
						found = true;
						continue;
					}
				}
			}
			if (found)
				continue;
			else
				str_list->add_item("");
		}
	}
	catch (pfc::exception & e)
	{
		console_error(e.what());
		delete str_list;
		return NULL;
	}
	catch (...)
	{
		delete str_list;
		return NULL;
	}

	return str_list;
}
コード例 #7
0
pfc::string8 provider_darklyrics::lookup_one(unsigned p_index, const metadb_handle_ptr & p_meta, threaded_process_status & p_status, abort_callback & p_abort)
{
	TRACK_CALL_TEXT("provider_darklyrics::lookup_one");

	const float threshold = 0.8f;
	
	const pfc::string8 site = "darklyrics.com";

	// Regular Expression Class
	CRegexpT<char> regexp;
	MatchResult match;

	// Buffer
	pfc::string8 buff;

	try
	{
		// Init fetcher
		curl_wrapper_simple fetcher(&m_config_item);

		const metadb_handle_ptr & p = p_meta;

		if (p.is_empty())
		{
			return "";
		}

		pfc::string8_fast artist, title, album, keywords;

		file_info_impl info;
		p->get_info(info);

		// Get count of artists
		t_size count = info.meta_get_count_by_name("album");

		if (count == 0)
			return "";
		// Get Album
		album = info.meta_get("album", 0);

		count = info.meta_get_count_by_name("title");

		if (count == 0)
			return "";

		// Get TITLE
		title = info.meta_get("title", 0);

		count = info.meta_get_count_by_name("artist");

		// Iterate through all artists listed
		for (int j = 0; j < count; j++)
		{
			// Get Artist
			artist = info.meta_get("artist", j);		//Fetching from HTTP

			keywords = artist;
			keywords += "+";
			keywords += album;

			keywords.replace_char(' ', '+');

			// Get it now
			try
			{
				fetcher.fetch_googleluck(site, keywords, buff);
			}
			catch (pfc::exception & e)
			{
				console_error(e.what());
				continue;
			}
			catch (...)
			{
				continue;
			}

			const char * regex_ahref = "<a\\shref=\"#(?P<no>\\d+)\">(?P<text>.+?)</a>";

			// expression for extract lyrics
			regexp.Compile(regex_ahref, IGNORECASE);

			// match
			MatchResult result = regexp.Match(buff.get_ptr());

			int noGroup = regexp.GetNamedGroupNumber("no");
			int textGroup = regexp.GetNamedGroupNumber("text");

			int jump_to = 0;
			pfc::string8_fast compare = title;
			compare.insert_chars(0, ". ");
			float good;
			float best = 0.0f;


			while (result.IsMatched())
			{
				int gStart = result.GetGroupStart(noGroup);
				int gEnd = result.GetGroupEnd(noGroup);
				pfc::string8_fast temp(buff.get_ptr() + gStart, gEnd - gStart);
				int no = StrToIntA(temp);

				gStart = result.GetGroupStart(textGroup);
				gEnd = result.GetGroupEnd(textGroup);

				temp = pfc::string8_fast(buff.get_ptr()+gStart, gEnd - gStart);

				int levDist = LD(compare, compare.get_length(), temp, temp.get_length());

				good = 1.0f - (levDist / (float)compare.get_length());

				if (good >= threshold && good > best)
				{
					jump_to = no;
					best = good;
				}
				result = regexp.Match(buff.get_ptr(),result.GetEnd());
			}

			if (jump_to == 0)
			{
				continue;
			}

			char regex_lyrics[100];

			sprintf(regex_lyrics, "<a\\s+name=%d><font*(.*?)</font*(.*?)>(?P<lyrics>.+?)<font", jump_to);

			// expression for extract lyrics
			regexp.Compile(regex_lyrics, IGNORECASE | SINGLELINE);

			noGroup = regexp.GetNamedGroupNumber("lyrics");

			result = regexp.Match(buff.get_ptr());

			if (result.IsMatched())
			{
				int nStart = result.GetGroupStart(noGroup);
				int nEnd = result.GetGroupEnd(noGroup);
				pfc::string8 lyric(buff.get_ptr() + nStart, nEnd - nStart);

				convert_html_to_plain(lyric);

				if (lyric.get_length() > 0)
				{
					string_helper::remove_beginning_linebreaks(lyric);
					string_helper::remove_end_linebreaks(lyric);
					string_helper::remove_beginning(lyric, ' ');
					string_helper::remove_beginning(lyric, '\t');
					return lyric;
				}
			}
		}
	}
	catch (pfc::exception & e)
	{
		console_error(e.what());
		return "";
	}
	catch (...)
	{
		return "";
	}

	return "";
}
コード例 #8
0
//************************************************************************
//*                             Dark Lyrics                              *
//************************************************************************
pfc::string_list_impl * provider_darklyrics::lookup(unsigned p_index, metadb_handle_list_cref p_meta, threaded_process_status & p_status, abort_callback & p_abort)
{
	TRACK_CALL_TEXT("provider_darklyrics::lookup");

	const float threshold = 0.8f;

	const pfc::string8 site = "darklyrics.com";

	// Regular Expression Class
	CRegexpT<char> regexp;
	MatchResult match;

	// Buffer
	pfc::string8 buff;
	pfc::string_list_impl * str_list = new pfc::string_list_impl;

	try
	{
		// Init fetcher
		curl_wrapper_simple fetcher(&m_config_item);

		for (t_size i = 0; i < p_meta.get_count(); ++i)
		{
			if (p_abort.is_aborting())
				break;

			// Sleep
			how_to_sleep(i);
			// Clear buff
			buff.reset();

			const metadb_handle_ptr & p = p_meta.get_item(i);

			if (p.is_empty())
			{
				str_list->add_item("");
				continue;
			}

			// Set progress
			pfc::string8_fast path = file_path_canonical(p->get_path());

			// add subsong index?
			if (p->get_subsong_index() > 0)
			{
				path.add_string(" /index:");
				path.add_string(pfc::format_uint(p->get_subsong_index()));
			}

			p_status.set_item_path(path);
			p_status.set_progress(i + 1, p_meta.get_count());

			pfc::string8_fast artist, title, album, keywords;

			file_info_impl info;
			p->get_info(info);

			// Get count of artists
			t_size count = info.meta_get_count_by_name("album");

			if (count == 0)
				continue;
			// Get Album
			album = info.meta_get("album", 0);

			count = info.meta_get_count_by_name("title");

			if (count == 0)
				continue;

			// Get TITLE
			title = info.meta_get("title", 0);

			count = info.meta_get_count_by_name("artist");

			bool found = false;

			// Iterate through all artists listed
			for (int j = 0; j < count && !found; j++)
			{
				// Get Artist
				artist = info.meta_get("artist", j);

				keywords = artist;
				keywords += "+";
				keywords += album;

				keywords.replace_char(' ', '+');

				// Get it now
				try
				{
					fetcher.fetch_googleluck(site, keywords, buff);
				}
				catch (pfc::exception & e)
				{
					console_error(e.what());
					continue;
				}
				catch (...)
				{
					continue;
				}

				const char * regex_ahref = "<a\\shref=\"#(?P<no>\\d+)\">(?P<text>.+?)</a>";

				// expression for extract lyrics
				regexp.Compile(regex_ahref, IGNORECASE | SINGLELINE);

				// match
				MatchResult result = regexp.Match(buff.get_ptr());

				int noGroup = regexp.GetNamedGroupNumber("no");
				int textGroup = regexp.GetNamedGroupNumber("text");

				int jump_to = 0;
				pfc::string8_fast compare = title;
				compare.insert_chars(0, ". ");
				float good;
				float best = 0.0f;

				while (result.IsMatched())
				{
					int gStart = result.GetGroupStart(noGroup);
					int gEnd = result.GetGroupEnd(noGroup);
					pfc::string8_fast temp(buff.get_ptr() + gStart, gEnd - gStart);
					int no = StrToIntA(temp);

					gStart = result.GetGroupStart(textGroup);
					gEnd = result.GetGroupEnd(textGroup);

					temp = pfc::string8_fast(buff.get_ptr()+gStart, gEnd - gStart);

					if (temp.find_first(title) != -1)
					{
						jump_to = no;
						break;
					}

					int levDist = LD(compare, compare.get_length(), temp, temp.get_length());

					good = 1.0f - (levDist / (float)compare.get_length());

					if (good >= threshold && good > best)
					{
						jump_to = no;
						best = good;
					}

					result = regexp.Match(buff.get_ptr(),result.GetEnd());
				}

				if (jump_to == 0)
				{
					continue;
				}

				char regex_lyrics[100];

				sprintf(regex_lyrics, "<a\\s+name=%d><font*(.*?)</font*(.*?)>(?P<lyrics>.+?)<font", jump_to);

				// expression for extract lyrics
				regexp.Compile(regex_lyrics, IGNORECASE | SINGLELINE);

				noGroup = regexp.GetNamedGroupNumber("lyrics");

				result = regexp.Match(buff.get_ptr());

				if (result.IsMatched())
				{
					int nStart = result.GetGroupStart(noGroup);
					int nEnd = result.GetGroupEnd(noGroup);
					pfc::string8 lyric(buff.get_ptr() + nStart, nEnd - nStart);

					convert_html_to_plain(lyric);

					if (lyric.get_length() > 0)
					{
						string_helper::remove_beginning_linebreaks(lyric);
						string_helper::remove_end_linebreaks(lyric);
						string_helper::remove_beginning(lyric, ' ');
						string_helper::remove_beginning(lyric, '\t');

						console::print(lyric);

						str_list->add_item(lyric);
						found = true;
						continue;
					}
				}
			}
			if (found)
				continue;
			else
				str_list->add_item("");
		}
	}
	catch (pfc::exception & e)
	{
		console_error(e.what());
		delete str_list;
		return NULL;
	}
	catch (...)
	{
		delete str_list;
		return NULL;
	}

	return str_list;
}
コード例 #9
0
pfc::string8 provider_lyricsplugin::lookup_one(unsigned p_index, const metadb_handle_ptr & p_meta, threaded_process_status & p_status, abort_callback & p_abort)
{
	// Regular Expression Class
	CRegexpT<char> regexp;
	MatchResult match;

	// Buffer
	pfc::string8 buff;

	try
	{
		// Init fetcher
		curl_wrapper_simple fetcher(&m_config_item);

		// Clear buff
		buff.reset();

		const metadb_handle_ptr & p = p_meta;

		if (p.is_empty())
		{
			return "";
		}

		pfc::string8_fast artist, title;
		static_api_ptr_t<titleformat_compiler> compiler;
		service_ptr_t<titleformat_object> script;

		file_info_impl info;
		p->get_info(info);

		// Get count of artists
		t_size count = info.meta_get_count_by_name("artist");

		// Get TITLE
		compiler->compile_safe(script, "[%title%]");
		p->format_title(NULL, title, script, NULL);

		bool found = false;

		// Iterate through all artists listed
		for (int j = 0; j < count && !found; j++)
		{
			// Get Artist
			artist = info.meta_get("artist", j);
			// Fetching from HTTP
			// Set HTTP Address
			pfc::string8_fast url("http://www.squirrelscript.net/mediamonkey/Lyricator/lyrics.php?artist=");

			// URL = http://www.squirrelscript.net/mediamonkey/Lyricator/lyrics.php?artist=<Artist>&title=<Title>

			url += fetcher.quote(artist);
			url += "&title=";
			url += fetcher.quote(title);

			// Get it now
			try
			{
				fetcher.fetch(url, buff);
			}
			catch (pfc::exception & e)
			{
				console_error(e.what());
				continue;
			}
			catch (...)
			{
				continue;
			}

			const char * regex_lyricbox = "<div\\s+id\\s*?=\\s*?\"lyrics\"\\s*?>[\\r\\n]*(.*?)[\\r\\n]*</div>";

			// expression for extract lyrics
			regexp.Compile(regex_lyricbox, SINGLELINE);

			// match
			MatchResult result = regexp.Match(buff.get_ptr());

			// Get Group
			if (result.IsMatched())
			{
				int nStart = result.GetGroupStart(1);
				int nEnd = result.GetGroupEnd(1);
				int index;
				pfc::string8_fast lyric(buff.get_ptr() + nStart, nEnd - nStart);

				convert_html_to_plain(lyric);

				index = lyric.find_first("www.tunerankings.com");

				if (index == 0)
				{
					continue;
				}
				else if (index != -1)
				{
					lyric.remove_chars(index, 20);
				}

				if (string_trim(lyric).get_length() > 0)
				{
					return lyric;
				}
			}
		}
	}
	catch (pfc::exception & e)
	{
		console_error(e.what());
		return "";
	}
	catch (...)
	{
		return "";
	}

	return "";
}
コード例 #10
0
pfc::string8 provider_leoslyrics::lookup_one(unsigned p_index, const metadb_handle_ptr & p_meta, threaded_process_status & p_status, abort_callback & p_abort)
{
	TRACK_CALL_TEXT("provider_leoslyrics::lookup_one");
	// Regular Expression Class
	CRegexpT<char> regexp;

	// Buffer
	pfc::string8 buff;

	try
	{
		// Init fetcher
		curl_wrapper_simple fetcher(&m_config_item);

		const metadb_handle_ptr & p = p_meta;

		if (p.is_empty())
		{
			return "";
		}

		pfc::string8_fast artist, title, album;

		file_info_impl info;
		p->get_info(info);

		// Get count of artists
		t_size count = info.meta_get_count_by_name("artist");

		// Get TITLE
		static_api_ptr_t<titleformat_compiler> compiler;
		service_ptr_t<titleformat_object> script;

		compiler->compile_safe(script, "%title%");
		p->format_title(NULL, title, script, NULL);

		// Iterate through all artists listed
		for (int j = 0; j < count; j++)
		{
			// Get Artist
			artist = info.meta_get("artist", j);

			//Fetching from HTTP
			// Set HTTP Address
			pfc::string8_fast url("http://77.79.210.222/api_search.php?auth=LeosLyrics5&artist=");
			pfc::string8_fast host("api.leoslyrics.com");

			//URL = http://77.79.210.222/api_search.php?auth=LeosLyrics5&artist=<artist>&songtitle=<title>

			url += fetcher.quote(artist);
			url += "&songtitle=";
			url += fetcher.quote(title);


			// Get it now
			try
			{
				fetcher.fetch_host(host, url, buff, p_abort);
			}
			catch (pfc::exception & e)
			{
				console_error(e.what());
				continue;
			}
			catch (...)
			{
				continue;
			}

			const char * regex_hid = "code=\"(?P<code>.).*?hid=\"(?P<hid>.*?)\"";

			// expression for extract lyrics
			regexp.Compile(regex_hid, IGNORECASE | SINGLELINE);

			pfc::string8_fast hid;

			int codeGroup = regexp.GetNamedGroupNumber("code");
			int hidGroup = regexp.GetNamedGroupNumber("hid");

			MatchResult result = regexp.Match(buff.get_ptr());

			if (result.IsMatched())
			{
				int nStart = result.GetGroupStart(codeGroup);
				int nEnd = result.GetGroupEnd(codeGroup);

				pfc::string8_fast code(buff.get_ptr() + nStart, nEnd-nStart);

				if (code.find_first("0") == -1)
					continue;

				nStart = result.GetGroupStart(hidGroup);
				nEnd = result.GetGroupEnd(hidGroup);

				hid = pfc::string8_fast(buff.get_ptr() + nStart, nEnd - nStart);

				url = "http://77.79.210.222/api_search.php?auth=LeosLyrics5&hid=";
				url += hid;

				//URL = http://77.79.210.222/api_search.php?auth=LeosLyrics5&hid=<songID>

				try
				{
					fetcher.fetch_host(host, url, buff, p_abort);
				}
				catch (pfc::exception & e)
				{
					console_error(e.what());
					continue;
				}
				catch (...)
				{
					continue;
				}

				const char * regex_hid = "<text>\\s(?P<lyrics>.*?)\\s</text>";

				// expression for extract lyrics
				regexp.Compile(regex_hid, IGNORECASE | SINGLELINE);

				int lyricsGroup = regexp.GetNamedGroupNumber("lyrics");

				result = regexp.Match(buff.get_ptr());

				if (result.IsMatched())
				{
					nStart = result.GetGroupStart(lyricsGroup);
					nEnd = result.GetGroupEnd(lyricsGroup);

					pfc::string8 lyric(buff.get_ptr() + nStart, nEnd - nStart);

					if (lyric.get_length() > 0)
					{
						string_helper::remove_beginning_linebreaks(lyric);
						string_helper::remove_end_linebreaks(lyric);

						return lyric;
					}
				}
			}
		}
	}
	catch (pfc::exception & e)
	{
		console_error(e.what());
		return "";
	}
	catch (...)
	{
		return "";
	}

	return "";
}
コード例 #11
0
//************************************************************************
//*                           Leo's Lyrics                               *
//************************************************************************
pfc::string_list_impl * provider_leoslyrics::lookup(unsigned p_index, metadb_handle_list_cref p_meta, threaded_process_status & p_status, abort_callback & p_abort)
{
	TRACK_CALL_TEXT("provider_leoslyrics::lookup");

	// Regular Expression Class
	CRegexpT<char> regexp;

	// Buffer
	pfc::string8 buff;
	pfc::string_list_impl * str_list = new pfc::string_list_impl;

	try
	{
		// Init fetcher
		curl_wrapper_simple fetcher(&m_config_item);

		for (t_size i = 0; i < p_meta.get_count(); ++i)
		{
			if (p_abort.is_aborting())
				break;

			// Sleep
			how_to_sleep(i);
			// Clear buff
			buff.reset();

			const metadb_handle_ptr & p = p_meta.get_item(i);

			if (p.is_empty())
			{
				str_list->add_item("");
				continue;
			}

			// Set progress
			pfc::string8_fast path = file_path_canonical(p->get_path());

			// add subsong index?
			if (p->get_subsong_index() > 0)
			{
				path.add_string(" /index:");
				path.add_string(pfc::format_uint(p->get_subsong_index()));
			}

			p_status.set_item_path(path);
			p_status.set_progress(i + 1, p_meta.get_count());

			pfc::string8_fast artist, title;

			file_info_impl info;
			p->get_info(info);

			// Get count of artists
			t_size count = info.meta_get_count_by_name("artist");

			// Get TITLE
			static_api_ptr_t<titleformat_compiler> compiler;
			service_ptr_t<titleformat_object> script;
	
			compiler->compile_safe(script, "%title%");
			p->format_title(NULL, title, script, NULL);

			bool found = false;

			// Iterate through all artists listed
			for (int j = 0; j < count && !found; j++)
			{
				// Get Artist
				artist = info.meta_get("artist", j);


				pfc::string8_fast url("http://77.79.210.222/api_search.php?auth=LeosLyrics5&artist=");
				pfc::string8_fast host("api.leoslyrics.com");

				//URL = http://77.79.210.222/api_search.php?auth=LeosLyrics5&artist=<artist>&songtitle=<title>

				url += fetcher.quote(artist);
				url += "&songtitle=";
				url += fetcher.quote(title);

				// Get it now
				try
				{
					fetcher.fetch_host(host, url, buff, p_abort);
				}
				catch (pfc::exception & e)
				{
					console_error(e.what());
					continue;
				}
				catch (...)
				{
					continue;
				}

				const char * regex_hid = "code=\"(?P<code>.).*?hid=\"(?P<hid>.*?)\"";

				// expression for extract lyrics
				regexp.Compile(regex_hid, IGNORECASE | SINGLELINE);

				pfc::string8_fast hid;

				int codeGroup = regexp.GetNamedGroupNumber("code");
				int hidGroup = regexp.GetNamedGroupNumber("hid");

				MatchResult result = regexp.Match(buff.get_ptr());

				if (result.IsMatched())
				{
					int nStart = result.GetGroupStart(codeGroup);
					int nEnd = result.GetGroupEnd(codeGroup);

					pfc::string8_fast code(buff.get_ptr() + nStart, nEnd-nStart);

					if (code.find_first("0") == -1)
						continue;

					nStart = result.GetGroupStart(hidGroup);
					nEnd = result.GetGroupEnd(hidGroup);

					hid = pfc::string8_fast(buff.get_ptr() + nStart, nEnd - nStart);
				
					url = "http://77.79.210.222/api_search.php?auth=LeosLyrics5&hid=";
					url += hid;

					//URL = http://77.79.210.222/api_search.php?auth=LeosLyrics5&hid=<songID>

					try
					{
						fetcher.fetch_host(host, url, buff, p_abort);
					}
					catch (pfc::exception & e)
					{
						console_error(e.what());
						continue;
					}
					catch (...)
					{
						continue;
					}

					const char * regex_hid = "<text>\\s(?P<lyrics>.*?)\\s</text>";

					// expression for extract lyrics
					regexp.Compile(regex_hid, IGNORECASE | SINGLELINE);

					int lyricsGroup = regexp.GetNamedGroupNumber("lyrics");

					result = regexp.Match(buff.get_ptr());

					if (result.IsMatched())
					{
						nStart = result.GetGroupStart(lyricsGroup);
						nEnd = result.GetGroupEnd(lyricsGroup);

						pfc::string8 lyric(buff.get_ptr() + nStart, nEnd - nStart);

						if (lyric.get_length() > 0)
						{
							found = true;

							string_helper::remove_beginning_linebreaks(lyric);
							string_helper::remove_end_linebreaks(lyric);

							str_list->add_item(lyric);
							continue;
						}
					}
				}
			}
			if (found)
				continue;
			else
				str_list->add_item("");
		}
	}
	catch (pfc::exception & e)
	{
		console_error(e.what());
		delete str_list;
		return NULL;
	}
	catch (...)
	{
		delete str_list;
		return NULL;
	}

	return str_list;
}
コード例 #12
0
pfc::string8 provider_lyricwiki::lookup_one(unsigned p_index, const metadb_handle_ptr & p_meta, threaded_process_status & p_status, abort_callback & p_abort)
{
	TRACK_CALL_TEXT("provider_lyricwiki::lookup_one");
	// Regular Expression Class
	CRegexpT<char> regexp;

	// Buffer
	pfc::string8 buff;

	try
	{
		// Init fetcher
		curl_wrapper_simple fetcher(&m_config_item);

		const metadb_handle_ptr & p = p_meta;

		if (p.is_empty())
		{
			return "";
		}

		pfc::string8_fast artist, title, album;

		file_info_impl info;
		p->get_info(info);

		// Get count of artists
		t_size count = info.meta_get_count_by_name("artist");

		// Get TITLE
		static_api_ptr_t<titleformat_compiler> compiler;
		service_ptr_t<titleformat_object> script;

		compiler->compile_safe(script, "$replace($caps2(%title%),' ','_')");
		p->format_title(NULL, title, script, NULL);

		// Iterate through all artists listed
		for (int j = 0; j < count; j++)
		{
			// Get Artist
			artist = info.meta_get("artist", j);

			artist.replace_char(' ', '_');

			//Fetching from HTTP
			// Set HTTP Address
			pfc::string8_fast url("http://lyrics.wikia.com/index.php?title=");

			//URL = http://lyrics.wikia.com/index.php?title=Blackmore%27s_Night:I_Guess_It_Doesn%27t_Matter_Anymore&action=edit

			url += fetcher.quote(artist);
			url += ":";
			url += fetcher.quote(title);


			// Get it now
			try
			{
				fetcher.fetch(url, buff);
			}
			catch (pfc::exception & e)
			{
				console_error(e.what());
				continue;
			}
			catch (...)
			{
				continue;
			}

			const char * regex_lyrics = "'lyricbox'(?P<instrumental>.*?)</div>(?P<lyrics>.*?)<!--";

			// expression for extract lyrics
			regexp.Compile(regex_lyrics, IGNORECASE | SINGLELINE);

			int noGroup = regexp.GetNamedGroupNumber("lyrics");
			int instGroup = regexp.GetNamedGroupNumber("instrumental");

			MatchResult result = regexp.Match(buff.get_ptr());

			if (result.IsMatched())
			{
				int nStart = result.GetGroupStart(instGroup);
				int nEnd = result.GetGroupEnd(instGroup);

				pfc::string8_fast test(buff.get_ptr() + nStart, nEnd-nStart);

				if (test.find_first("Instrumental") != -1)
				{
					return "[Instrumental]";
				}

				nStart = result.GetGroupStart(noGroup);
				nEnd = result.GetGroupEnd(noGroup);

				pfc::string8 lyric(buff.get_ptr() + nStart, nEnd - nStart);

				convert_html_to_plain(lyric);

				if (lyric.get_length() > 0)
				{
					string_helper::remove_beginning_linebreaks(lyric);
					string_helper::remove_end_linebreaks(lyric);
					return lyric;
				}
			}
		}
	}
	catch (pfc::exception & e)
	{
		console_error(e.what());
		return "";
	}
	catch (...)
	{
		return "";
	}

	return "";
}
コード例 #13
0
//************************************************************************
//*                              LyricWiki                               *
//************************************************************************
pfc::string_list_impl * provider_lyricwiki::lookup(unsigned p_index, metadb_handle_list_cref p_meta, threaded_process_status & p_status, abort_callback & p_abort)
{
	TRACK_CALL_TEXT("provider_lyricwiki::lookup");

	// Regular Expression Class
	CRegexpT<char> regexp;

	// Buffer
	pfc::string8 buff;
	pfc::string_list_impl * str_list = new pfc::string_list_impl;

	try
	{
		// Init fetcher
		curl_wrapper_simple fetcher(&m_config_item);

		for (t_size i = 0; i < p_meta.get_count(); ++i)
		{
			if (p_abort.is_aborting())
				break;

			// Sleep
			how_to_sleep(i);
			// Clear buff
			buff.reset();

			const metadb_handle_ptr & p = p_meta.get_item(i);

			if (p.is_empty())
			{
				str_list->add_item("");
				continue;
			}

			// Set progress
			pfc::string8_fast path = file_path_canonical(p->get_path());

			// add subsong index?
			if (p->get_subsong_index() > 0)
			{
				path.add_string(" /index:");
				path.add_string(pfc::format_uint(p->get_subsong_index()));
			}

			p_status.set_item_path(path);
			p_status.set_progress(i + 1, p_meta.get_count());

			pfc::string8_fast artist, title;

			file_info_impl info;
			p->get_info(info);

			// Get count of artists
			t_size count = info.meta_get_count_by_name("artist");

			// Get TITLE
			static_api_ptr_t<titleformat_compiler> compiler;
			service_ptr_t<titleformat_object> script;
	
			compiler->compile_safe(script, "$replace($caps2(%title%),' ','_')");
			p->format_title(NULL, title, script, NULL);

			bool found = false;

			// Iterate through all artists listed
			for (int j = 0; j < count && !found; j++)
			{
				// Get Artist
				artist = info.meta_get("artist", j);

				artist.replace_char(' ', '_');

				//Fetching from HTTP
				// Set HTTP Address
				pfc::string8_fast url("http://lyrics.wikia.com/index.php?title=");

				//URL = http://lyrics.wikia.com/index.php?title=Blackmore%27s_Night:I_Guess_It_Doesn%27t_Matter_Anymore&action=edit

				url += fetcher.quote(artist);
				url += ":";
				url += fetcher.quote(title);

				// Get it now
				try
				{
					fetcher.fetch(url, buff);
				}
				catch (pfc::exception & e)
				{
					console_error(e.what());
					continue;
				}
				catch (...)
				{
					continue;
				}

				const char * regex_lyrics = "'lyricbox'(?P<instrumental>.*?)</div>(?P<lyrics>.*?)<!--";

				// expression for extract lyrics
				regexp.Compile(regex_lyrics, IGNORECASE | SINGLELINE);

				int noGroup = regexp.GetNamedGroupNumber("lyrics");
				int instGroup = regexp.GetNamedGroupNumber("instrumental");

				MatchResult result = regexp.Match(buff.get_ptr());

				if (result.IsMatched())
				{
					int nStart = result.GetGroupStart(instGroup);
					int nEnd = result.GetGroupEnd(instGroup);

					pfc::string8_fast test(buff.get_ptr() + nStart, nEnd-nStart);

					if (test.find_first("Instrumental") != -1)
					{
						found = true;

						str_list->add_item("[Instrumental]");
						continue;
					}

					nStart = result.GetGroupStart(noGroup);
					nEnd = result.GetGroupEnd(noGroup);

					pfc::string8 lyric(buff.get_ptr() + nStart, nEnd - nStart);

					convert_html_to_plain(lyric);

					if (lyric.get_length() > 0)
					{
						found = true;

						string_helper::remove_beginning_linebreaks(lyric);
						string_helper::remove_end_linebreaks(lyric);

						str_list->add_item(lyric);
						continue;
					}
				}
			}
			if (found)
				continue;
			else
				str_list->add_item("");
		}
	}
	catch (pfc::exception & e)
	{
		console_error(e.what());
		delete str_list;
		return NULL;
	}
	catch (...)
	{
		delete str_list;
		return NULL;
	}

	return str_list;
}