Problem in saving fetched sound/images in Parley

Xin Huang xinhuang.abc at gmail.com
Mon Mar 6 23:29:00 UTC 2017


Hi All,

When I am using Parley, I find that the FetchSound plugin has some
problems. I am using Ubuntu 16.10 and everything from the official package
repository. (I noticed there are some update, but the problem seems still)


1. The mwclient package, used by wikitionary, requires to be upgraded since
Wikipedia deprecated API via http request. (should be https)

After upgrading mwclient, an extra package request_oauthlib is also
required. Because mwclient is distributed by source code, it might be
required adding request_oauthlib source. (Or adding by using pip
dependencies?)



2. After mwclient is upgraded, there is a problem during saving sound file
url/path in keduvockvtml2writer.

( The code on GitHub can be found here: https://github.com/KDE/
libkeduvocdocument/blob/ddb743b7e312e69d7f1eee9a3f4c25
ef8031b27b/keduvocdocument/keduvockvtml2writer.cpp#L549 )

bool KEduVocKvtml2Writer::writeTranslation( QDomElement
&translationElement, KEduVocTranslation* translation )
{
    // ...
    // sound
    if ( !translation->soundUrl().isEmpty() ) {
        QString urlString;
        qDebug() << "soundUrl" << translation->soundUrl();
        if ( KIO::upUrl(m_doc->url().adjusted(QUrl::RemoveFilename)).isParentOf(
translation->soundUrl()) ) {
            // try to save as relative url
            urlString = m_doc->url().toString(QUrl::RemoveFilename) + '/' +
translation->soundUrl().toString();     // <------------ HERE
        } else {
            urlString =  translation->soundUrl().url();
        }
        qDebug() << "urlString" << urlString;
        translationElement.appendChild( newTextElement( KVTML_SOUND,
urlString ) );
    }

Notice the line marked: The soundUrl of a translation parley passed in is
"file:///path/to/kvtml/kvtmlfilename_files/File:En-us-Word.ogg", and the
m_doc->url() is "file:///path/to/kvtml/kvtmlfilename.kvtml". By the logic
saving as relative url, the result will be "file:///path/to/kvtml/file://
/path/to/kvtml/kvtmlfilename_files/Files:En-us-word.ogg".

To fix the saving to relative url, the code should be:

            QDir dir(m_doc->url().adjusted(QUrl::RemoveFilename).
toLocalFile());
            qDebug() << m_doc->url().toString(QUrl::RemoveFilename);
            urlString = dir.relativeFilePath(translation->soundUrl().
toLocalFile());

Similar code for saving image to relative path is also incorrect. (Lines
above saving sound)


I have submitted a patch (https://git.reviewboard.kde.org/r/129992/) for
the second issue. For the first issue requires update mwclient package, I
don't know what would be a proper solution.

Thanks,
Xin Huang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/kde-edu/attachments/20170306/c141e1ef/attachment.html>


More information about the kde-edu mailing list