Switch to QtNetwork
[maelyrica:maelyrica.git] / LyricsManiaDownloader.cpp
1 #include "LyricsManiaDownloader.h"
2 #include <QTextDocument>
3
4 const QString LyricsManiaDownloader::rooturl("http://www.lyricsmania.com/%1_lyrics_%2.html");
5 const QString LyricsManiaDownloader::startMarker("<div id='songlyrics_h' class='dn'>");
6 const QString LyricsManiaDownloader::endMarker("</div>");
7
8 QString LyricsManiaDownloader::toProviderCode(const QString &artist, const QString &track) const
9 {
10     QString artist_www = artist.trimmed().toLower().replace(' ', '_');
11     QString track_www = track.trimmed().toLower().replace(' ', '_').replace('\'','_');
12     return rooturl.arg(track_www, artist_www);
13 }
14
15 bool LyricsManiaDownloader::parse()
16 {
17     int startpos = lyrics_qstr.indexOf(startMarker) + startMarker.length();
18     if (startpos < 0) return false;
19
20     lyrics_qstr = QTextDocument(lyrics_qstr.remove(0, startpos).mid(0, lyrics_qstr.indexOf(endMarker))).toPlainText();
21
22     return true;
23
24     /*istringstream temp(buff.str());
25     buff.str("");
26     string line;
27     QString line_QStr, lyrics_QStr;
28     while (temp.good())
29     {
30         getline(temp, line);
31         if (QString::fromUtf8(line.c_str()).contains(startMarker)) break; // we don't need utf8 yet
32     }
33     if (!temp.good()) return false; // something went wrong
34
35     while (temp.good())
36     {
37         getline(temp, line);
38         if ((line_QStr = QString::fromUtf8(line.c_str())).contains(endMarker))
39         {
40             lyrics_QStr += line_QStr.remove(endMarker); // remove the </div>
41             break;
42         }
43         else
44         {
45             lyrics_QStr += line_QStr;
46         }
47     }
48
49     if (!temp.good()) return false;
50
51     QTextDocument lyricsHtml;
52     lyricsHtml.setHtml(lyrics_QStr);
53     lyrics_qstr = lyricsHtml.toPlainText();*/
54 }