~ubuntu-branches/ubuntu/saucy/clementine/saucy

« back to all changes in this revision

Viewing changes to src/scripting/python/playlistparser.sip

  • Committer: Package Import Robot
  • Author(s): Thomas PIERSON
  • Date: 2012-01-01 20:43:39 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20120101204339-lsb6nndwhfy05sde
Tags: 1.0.1+dfsg-1
New upstream release. (Closes: #653926, #651611, #657391)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
class PlaylistParser : QObject {
2
 
%TypeHeaderCode
3
 
  #include "playlistparsers/playlistparser.h"
4
 
%End
5
 
 
6
 
%Docstring
7
 
Utility class to read and write playlist files.
8
 
 
9
 
The PlaylistParser supports a number of different playlist formats - these are
10
 
implemeted by subclasses of L{ParserBase}.  Usually you don't need to worry
11
 
about finding the right parser for your file - PlaylistParser will do that
12
 
automatically based on the filename you give it (for example, it will use the
13
 
PlsParser if you ask it to load a file called C{playlist.pls}).
14
 
 
15
 
If you don't know the filename because you're reading data directly from the
16
 
network, PlaylistParser can also guess the type of parser to use by looking for
17
 
magic strings in the first few bytes of the file.  The constant C{kMagicSize}
18
 
tells you how many bytes the PlaylistParser will take when using magic.
19
 
 
20
 
PlaylistParser deals with loading and saving lists of L{Song} objects.
21
 
 
22
 
  >>> parser = clementine.PlaylistParser(clementine.library)
23
 
  ... songlist = parser.LoadFromFile("songs.xspf")
24
 
  ... print songlist[0].title()
25
 
  ... parser.Save(songlist, "songs.asx")
26
 
 
27
 
Notice that this class' constructor takes a L{LibraryBackend}.  Why does a
28
 
playlist parser need access to the library?  When loading a list of songs the
29
 
parser will check whether a song exists already in the library, and will use
30
 
the metadata that's already been loaded instead of loading it again.  You can
31
 
get Clementine's library by using C{clementine.library}.
32
 
 
33
 
@warning: The L{LoadFromFile()}, L{LoadFromDevice()} and L{Save()} methods in
34
 
  this class are B{blocking} and should not be called from the main thread.
35
 
  For a higher level interface to loading songs from playlists you should use
36
 
  the L{SongLoader} class which works in a background thread.
37
 
%End
38
 
 
39
 
public:
40
 
  PlaylistParser(LibraryBackend* library, QObject* parent /TransferThis/ = 0);
41
 
 
42
 
  static const int kMagicSize;
43
 
 
44
 
  QStringList file_extensions() const;
45
 
%Docstring
46
 
file_extensions() -> list of str
47
 
Returns the list of file extensions that the PlaylistParser knows how to parse.
48
 
%End
49
 
 
50
 
  QString filters() const;
51
 
%Docstring
52
 
filters() -> str
53
 
Returns a filter string suitable for use in L{PyQt4.QtGui.QFileDialog}.
54
 
%End
55
 
 
56
 
  QString default_extension() const;
57
 
%Docstring
58
 
default_extension() -> str
59
 
Returns the recommended extension to use when saving playlists.  Currently this
60
 
is C{xspf}.
61
 
%End
62
 
 
63
 
  QString default_filter() const;
64
 
%Docstring
65
 
default_filter() -> str
66
 
Returns the recommended default filter string suitable for use in
67
 
L{PyQt4.QtGui.QFileDialog}.
68
 
%End
69
 
 
70
 
  ParserBase* ParserForMagic(const QByteArray& data,
71
 
                             const QString& mime_type = QString()) const;
72
 
%Docstring
73
 
ParserForMagic(data, mime_type="") -> L{ParserBase}
74
 
Tries to guess the file type of a playlist based on the first few bytes of its
75
 
contents or (optionally) a mime type.
76
 
 
77
 
@param data: should be at least L{kMagicSize} bytes long.
78
 
@type data: str
79
 
@param mime_type: (optional) the mime type of the data obtained through (for
80
 
  example) and HTTP response header.
81
 
@type mime_type: str
82
 
@return: a parser for this file format, or None if it was not possible to guess.
83
 
 
84
 
@note: only use this method if you need direct access to the parser.  If you
85
 
  just want to load a list of songs from some data use L{LoadFromDevice()}.
86
 
%End
87
 
 
88
 
  ParserBase* ParserForExtension(const QString& suffix) const;
89
 
%Docstring
90
 
ParserForExtension(suffix) -> L{ParserBase}
91
 
Tried to guess the file type of a playlist based on its file extension.
92
 
 
93
 
@param suffix: the file extension, not including the C{.} character.
94
 
@type suffix: str
95
 
@return: a parser for this file format, or None if the extension wasn't
96
 
  recognised.
97
 
 
98
 
@note: only use this method if you need direct access to the parser.  If you
99
 
  just want to load a list of songs from a file use L{LoadFromFile()}.
100
 
%End
101
 
 
102
 
  SongList LoadFromFile(const QString& filename) const;
103
 
%Docstring
104
 
LoadFromFile(filename) -> list of L{Song}
105
 
Loads a playlist from a file and returns the list of songs that it contained.
106
 
Determines the type of the playlist based on the file extension by calling
107
 
L{ParserForExtension}.
108
 
 
109
 
@return: the list of songs in the playlist, or an empty list if the playlist
110
 
  couldn't be loaded.
111
 
%End
112
 
 
113
 
  SongList LoadFromDevice(QIODevice* device, const QString& path_hint = "",
114
 
                          const QDir& dir_hint = QDir()) const;
115
 
%Docstring
116
 
LoadFromDevice(device, path_hint="", dir_hint="") -> list of L{Song}
117
 
Loads a playlist from a L{PyQt4.QtCore.QIODevice} and returns the list of songs
118
 
that it contained.  Determines the type of the playlist by peeking at the first
119
 
L{kMagicSize} bytes of the device and using L{ParserForMagic}.
120
 
 
121
 
@param device: an open device on a playlist file.  You can use any device here,
122
 
  including L{PyQt4.QtNetwork.QTcpSocket}, L{PyQt4.QtCore.QFile} or
123
 
  L{PyQt4.QtCore.QBuffer}.
124
 
@type device: L{PyQt4.QtCore.QIODevice}
125
 
@param path_hint: (optional) the filename of the playlist.  Some parsers may
126
 
  use this filename to add additional information to the L{Song}s returned, for
127
 
  example the cue parser fills out the L{Song.cue_path()} field.
128
 
@type path_hint: str
129
 
@param dir_hint: (optional) the directory containing the playlist.  Parsers will
130
 
  use this directory to resolve any relative filenames in the playlist.
131
 
@type dir_hint: L{PyQt4.QtCore.QDir}
132
 
@return: the list of songs in the playlist, or an empty list if the playlist
133
 
  couldn't be loaded.
134
 
%End
135
 
 
136
 
  void Save(const SongList& songs, const QString& filename) const;
137
 
%Docstring
138
 
Save(songs, filename)
139
 
Saves a list of songs to a new playlist.  Determines the type of the playlist
140
 
to create based on the file extension by calling L{ParserForExtension}.
141
 
 
142
 
@type songs: list of L{Song}
143
 
@type filename: str
144
 
%End
145
 
};