File: parserm3u.cpp

package info (click to toggle)
mixxx 1.4.2-1.1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 10,676 kB
  • ctags: 4,130
  • sloc: ansic: 35,627; cpp: 27,118; xml: 3,691; sh: 417; makefile: 54
file content (98 lines) | stat: -rw-r--r-- 2,051 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
//
// C++ Implementation: parserm3u
//
// Description: module to parse m3u(plaintext) formated playlists
//
//
// Author: Ingo Kossyk <kossyki@cs.tu-berlin.de>, (C) 2004
//
// Copyright: See COPYING file that comes with this distribution
//
//

#include "parserm3u.h"

/**
@author Ingo Kossyk (kossyki@cs.tu-berlin.de)
**/

/**
ToDo:
    - parse ALL informations from the pls file if available ,
	  not only the filepath;
	  
	  Userinformation : 
	  The M3U format is just a headerless plaintext format
	  where every line of text either represents
	  a file location or a comment. comments are being
	  preceeded by a '#'. This parser will try to parse all
	  file information from the given file and add the filepaths
	  to the locations ptrlist when the file is existing locally
	  or on a mounted harddrive.
**/

ParserM3u::ParserM3u()
{
    m_psLocations = new QPtrList<QString>;
}

ParserM3u::~ParserM3u()
{

    //delete m_psLocations;

}


QPtrList<QString> * ParserM3u::parse(QString sFilename)
{


    QFile * file = new QFile(sFilename);

    clearLocations();
    //qDebug("ParserM3u: Starting to parse.");
    if (file->open(IO_ReadOnly) && !isBinary(sFilename)) {

        QTextStream * textstream = new QTextStream( file );



        while(QString * psLine = new QString(getFilepath(textstream))){

            if(psLine->isNull() || (*psLine) == "NULL")
                break;

            //qDebug("ParserM3u: parsed: "+(*psLine));
            m_psLocations->append(psLine);

        }

        file->close();

        if(m_psLocations->count() != 0)
            return m_psLocations;
        else
            return 0;		// NULL pointer returned when no locations were found

    }

    file->close();
    return 0; //if we get here something went wrong
}


QString ParserM3u::getFilepath(QTextStream * stream)
{
    QString textline = "";

    while((textline = stream->readLine()).contains("#"));

    QString filename = textline;

    if(isFilepath(filename))
        return filename;
    else
        return QString("NULL");

}