Fix InternetLyricsFetcher
[ncmpcpp.git] / src / song.h
blobc80ce11730645133437f2833e4541c55b6020b5b
1 /***************************************************************************
2 * Copyright (C) 2008-2017 by Andrzej Rybczak *
3 * electricityispower@gmail.com *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
19 ***************************************************************************/
21 #ifndef NCMPCPP_SONG_H
22 #define NCMPCPP_SONG_H
24 #include <cstring>
25 #include <functional>
26 #include <memory>
27 #include <string>
28 #include <vector>
30 #include <mpd/client.h>
32 namespace MPD {
34 struct Song
36 struct Hash {
37 size_t operator()(const Song &s) const { return s.m_hash; }
40 typedef std::string (Song::*GetFunction)(unsigned) const;
42 Song() : m_hash(0) { }
43 virtual ~Song() { }
45 Song(mpd_song *s);
47 Song(const Song &rhs) : m_song(rhs.m_song), m_hash(rhs.m_hash) { }
48 Song(Song &&rhs) : m_song(std::move(rhs.m_song)), m_hash(rhs.m_hash) { }
49 Song &operator=(Song rhs)
51 m_song = std::move(rhs.m_song);
52 m_hash = rhs.m_hash;
53 return *this;
56 std::string get(mpd_tag_type type, unsigned idx = 0) const;
58 virtual std::string getURI(unsigned idx = 0) const;
59 virtual std::string getName(unsigned idx = 0) const;
60 virtual std::string getDirectory(unsigned idx = 0) const;
61 virtual std::string getArtist(unsigned idx = 0) const;
62 virtual std::string getTitle(unsigned idx = 0) const;
63 virtual std::string getAlbum(unsigned idx = 0) const;
64 virtual std::string getAlbumArtist(unsigned idx = 0) const;
65 virtual std::string getTrack(unsigned idx = 0) const;
66 virtual std::string getTrackNumber(unsigned idx = 0) const;
67 virtual std::string getDate(unsigned idx = 0) const;
68 virtual std::string getGenre(unsigned idx = 0) const;
69 virtual std::string getComposer(unsigned idx = 0) const;
70 virtual std::string getPerformer(unsigned idx = 0) const;
71 virtual std::string getDisc(unsigned idx = 0) const;
72 virtual std::string getComment(unsigned idx = 0) const;
73 virtual std::string getLength(unsigned idx = 0) const;
74 virtual std::string getPriority(unsigned idx = 0) const;
76 virtual std::string getTags(GetFunction f) const;
78 virtual unsigned getDuration() const;
79 virtual unsigned getPosition() const;
80 virtual unsigned getID() const;
81 virtual unsigned getPrio() const;
82 virtual time_t getMTime() const;
84 virtual bool isFromDatabase() const;
85 virtual bool isStream() const;
87 virtual bool empty() const;
89 bool operator==(const Song &rhs) const
91 if (m_hash != rhs.m_hash)
92 return false;
93 return strcmp(c_uri(), rhs.c_uri()) == 0;
95 bool operator!=(const Song &rhs) const
97 return !(operator==(rhs));
100 const char *c_uri() const { return m_song ? mpd_song_get_uri(m_song.get()) : ""; }
102 static std::string ShowTime(unsigned length);
104 static std::string TagsSeparator;
106 static bool ShowDuplicateTags;
108 private:
109 std::shared_ptr<mpd_song> m_song;
110 size_t m_hash;
115 #endif // NCMPCPP_SONG_H