0

I have trouble loading *m3u-playlistfiles with UTF-8-encoding with QMediaPlaylist. The path of the first entry is not loaded correctly.

As you can see in the screenshot the path of the first entry starts with D:/D/Media/New folder/ , which is the path to the playlist, followed by , followed by the relative path to the mediafile as it iis saved in the *m3u-file.

With *m3u-files with ANSI-encoding I do not have those troubles.

Also characters like "ü" in this case (second entry) aren't encoded properly.

Is there anyway to fix that without coding my own playlist-parser?

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    QDirIterator it("D:/D/Media/New folder", QStringList() << "*.m3u", QDir::Files, QDirIterator::Subdirectories);
    while (it.hasNext())
    {
        it.next();
        QMediaPlaylist currentPlaylist;
        currentPlaylist.clear();
        currentPlaylist.load(QUrl::fromLocalFile(it.filePath()));
        currentPlaylist.setCurrentIndex(0);
        int x = 1;
        ui->textBrowser->append(it.fileName());
        ui->textBrowser->append("-----");
        while(currentPlaylist.mediaCount() > 0)
        {
            ui->textBrowser->append(QString::number(x) + QString(": ") + currentPlaylist.currentMedia().canonicalUrl().toString());
            x++;
            currentPlaylist.removeMedia(0);
        }
        ui->textBrowser->append("");
    }
}

enter image description here

*m3u-content

..\Musik\Mittelalter Party\Mittelalter Party Volume 1\Tanzwut - Meer.mp3
..\Musik\ASP\Humility\ASP - Küss mich (Chamber version).mp3
..\Musik\Disturbed\Ten Thousand Fists\Disturbed - Ten Thousand Fists.mp3
honiahaka10
  • 772
  • 4
  • 9
  • 29

1 Answers1

1

Wikipedia says that UTF-8 encoded playlists should have a .m3u8 extension. Have you tried changing the file extension to .m3u8?

  • Thank you that works. But problem is of cource that I can not expect the users to change their playlist extensions when I publish my program later. My playlist is created with MediaMonkey for example, whish seems to save UTF8-Playlists as *m3u. Is there maybe anyway to check for the encoding of the file and create something like a virtual *m3u8 which i can load into QMediaPlaylist? – honiahaka10 Jan 05 '17 at 15:35
  • 1
    I think you could probably just assume that playlists are UTF-8 encoded and always make a temporary copy of the m3u (and change the extension to m3u8, so that when you pass it to QMediaPlaylist it will cope with any UTF-8 characters). I don't think you can do any better than that really. – Stuart Fisher Jan 06 '17 at 08:54
  • There's some more info here with some options if you wanted to try: http://stackoverflow.com/questions/910793/detect-encoding-and-make-everything-utf-8?rq=1, but that is all for php and not C++ / Qt – Stuart Fisher Jan 06 '17 at 09:05
  • Creating a temporary copy is a good idea but has two problems. I cannot guarantee that I have write access in the playlist folder and if I create the copy in the application folder relative paths in the playlist are corrupted.I guess I have to write my own parser... at least with copying I only have to change the relative paths to absolute. Thanks! Or do you have any other idea? – honiahaka10 Jan 06 '17 at 15:40
  • 1
    You should put temporary files in a temporary directory anyway. I'm fairly sure Qt has a function to provide you with the path to the system tmp folder. I see your point about the relative file names though, that does seem to be a show stopper. – Stuart Fisher Jan 09 '17 at 08:47
  • I think I created a working parser for my problem now, I will add it to your answer! – honiahaka10 Jan 10 '17 at 22:49