Commit 1a1b30fe892afc0c9c7988c4c928c27521640d02
- Diff rendering mode:
- inline
- side by side
src/scripts/lyrics_lyricwiki/main.js
(31 / 5)
|   | |||
| 27 | 27 | Importer.loadQtBinding( "qt.xml" ); | |
| 28 | 28 | ||
| 29 | 29 | xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?><lyric artist=\"{artist}\" title=\"{title}\">{lyrics}</lyric>"; | |
| 30 | newxml = ""; | ||
| 30 | 31 | ||
| 32 | function onFinished2( response ) | ||
| 33 | { | ||
| 34 | try | ||
| 35 | { | ||
| 36 | if( response.length == 0 ) | ||
| 37 | Amarok.Lyrics.showLyricsError( "Unable to contact server - no website returned" ); // TODO: this should be i18n able | ||
| 38 | else | ||
| 39 | { | ||
| 40 | doc2 = new QDomDocument(); | ||
| 41 | doc2.setContent( response ); | ||
| 42 | textboxtext = doc2.elementsByTagName( "textarea" ).at( 0 ).toElement().text(); | ||
| 43 | lyr = /<lyrics>(.*)<\/lyrics>/.exec(textboxtext)[1]; | ||
| 44 | //Amarok.debug( "matched: " + lyr ); | ||
| 45 | newxml = newxml.replace( "{lyrics}", Amarok.Lyrics.escape( lyr ) ); | ||
| 46 | Amarok.Lyrics.showLyrics( newxml ); | ||
| 47 | } | ||
| 48 | } | ||
| 49 | catch( err ) | ||
| 50 | { | ||
| 51 | Amarok.Lyrics.showLyricsError( "Could not retrieve lyrics: " + err ); | ||
| 52 | Amarok.debug( "error: " + err ); | ||
| 53 | } | ||
| 54 | } | ||
| 55 | |||
| 31 | 56 | function onFinished( dat ) | |
| 32 | 57 | { | |
| 33 | 58 | try | |
| … | … | ||
| 63 | 63 | { | |
| 64 | 64 | doc = new QDomDocument(); | |
| 65 | 65 | doc.setContent( dat ); | |
| 66 | parsedContent = doc.elementsByTagName( "lyrics" ).at( 0 ).toElement().text(); | ||
| 67 | parsedContent = parsedContent.replace( "<lyrics>", "" ).replace( "</lyrics>", "" ); // some lyrics have 2 lyrics in them...wtf? | ||
| 68 | 66 | newxml = xml.replace( "{artist}", Amarok.Lyrics.escape( doc.elementsByTagName( "artist" ).at( 0 ).toElement().text() ) ); | |
| 69 | 67 | newxml = newxml.replace( "{title}", Amarok.Lyrics.escape( doc.elementsByTagName( "song" ).at( 0 ).toElement().text() ) ); | |
| 70 | newxml = newxml.replace( "{lyrics}", Amarok.Lyrics.escape( parsedContent ) ); | ||
| 71 | //Amarok.debug( "showing lyrics:" + newxml ); | ||
| 72 | Amarok.Lyrics.showLyrics( newxml ); | ||
| 68 | Amarok.debug( "returned real lyricwiki URL: " + doc.elementsByTagName( "url" ).at( 0 ).toElement().text()); | ||
| 69 | var url = decodeURI(doc.elementsByTagName( "url" ).at( 0 ).toElement().text()); | ||
| 70 | url = url.replace( /lyricwiki\.org\//, "lyricwiki.org/index.php?action=edit&title=" ); | ||
| 71 | var url2 = new QUrl(url); | ||
| 72 | Amarok.debug( "request-2 URL: " + url2.toString() ); | ||
| 73 | new Downloader( url2, onFinished2 ); | ||
| 73 | 74 | } | |
| 74 | 75 | } | |
| 75 | 76 | catch( err ) |
Comments
Add a new comment:
Login or create an account to post a comment
Add your comment
Please log in to comment

