Merge pull request #4775 from jmarshallnz/empty_episode_playcount
[vuplus_xbmc] / xbmc / network / cddb.h
1 #pragma once
2 /*
3  *      Copyright (C) 2005-2013 Team XBMC
4  *      http://xbmc.org
5  *
6  *  This Program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; either version 2, or (at your option)
9  *  any later version.
10  *
11  *  This Program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with XBMC; see the file COPYING.  If not, see
18  *  <http://www.gnu.org/licenses/>.
19  *
20  */
21
22 #include "system.h" // for HAS_DVD_DRIVE
23
24 #ifdef HAS_DVD_DRIVE
25
26 #include <sstream>
27 #include <iostream>
28 #include <map>
29 #ifndef TARGET_POSIX
30 #include <strstream>
31 #endif
32 #include "storage/cdioSupport.h"
33
34 #include "utils/AutoPtrHandle.h"
35
36 namespace CDDB
37 {
38
39 //Can be removed if/when removing Xcddb::queryCDinfo(int real_track_count, toc cdtoc[])
40 //#define IN_PROGRESS           -1
41 //#define QUERRY_OK             7
42 //#define E_INEXACT_MATCH_FOUND      211
43 //#define W_CDDB_already_shook_hands      402
44 //#define E_CDDB_Handshake_not_successful 431
45
46 #define E_TOC_INCORRECT           2
47 #define E_NETWORK_ERROR_OPEN_SOCKET     3
48 #define E_NETWORK_ERROR_SEND       4
49 #define E_WAIT_FOR_INPUT         5
50 #define E_PARAMETER_WRONG         6
51 #define E_NO_MATCH_FOUND        202
52
53 #define CDDB_PORT 8880
54
55
56 struct toc
57 {
58   int min;
59   int sec;
60   int frame;
61 };
62
63
64 class Xcddb
65 {
66 public:
67   Xcddb();
68   virtual ~Xcddb();
69   void setCDDBIpAdress(const CStdString& ip_adress);
70   void setCacheDir(const CStdString& pCacheDir );
71
72 //  int queryCDinfo(int real_track_count, toc cdtoc[]);
73   bool queryCDinfo(MEDIA_DETECT::CCdInfo* pInfo, int inexact_list_select);
74   bool queryCDinfo(MEDIA_DETECT::CCdInfo* pInfo);
75   int getLastError() const;
76   const char * getLastErrorText() const;
77   const CStdString& getYear() const;
78   const CStdString& getGenre() const;
79   const CStdString& getTrackArtist(int track) const;
80   const CStdString& getTrackTitle(int track) const;
81   void getDiskArtist(CStdString& strdisk_artist) const;
82   void getDiskTitle(CStdString& strdisk_title) const;
83   const CStdString& getTrackExtended(int track) const;
84   uint32_t calc_disc_id(int nr_of_tracks, toc cdtoc[]);
85   const CStdString& getInexactArtist(int select) const;
86   const CStdString& getInexactTitle(int select) const;
87   bool queryCache( uint32_t discid );
88   bool writeCacheFile( const char* pBuffer, uint32_t discid );
89   bool isCDCached( int nr_of_tracks, toc cdtoc[] );
90   bool isCDCached( MEDIA_DETECT::CCdInfo* pInfo );
91
92 protected:
93   CStdString m_strNull;
94   AUTOPTR::CAutoPtrSocket m_cddb_socket;
95   const static int recv_buffer = 4096;
96   int m_lastError;
97   std::map<int, CStdString> m_mapTitles;
98   std::map<int, CStdString> m_mapArtists;
99   std::map<int, CStdString> m_mapExtended_track;
100
101   std::map<int, CStdString> m_mapInexact_cddb_command_list;
102   std::map<int, CStdString> m_mapInexact_artist_list;
103   std::map<int, CStdString> m_mapInexact_title_list;
104
105
106   CStdString m_strDisk_artist;
107   CStdString m_strDisk_title;
108   CStdString m_strYear;
109   CStdString m_strGenre;
110
111   void addTitle(const char *buffer);
112   void addExtended(const char *buffer);
113   void parseData(const char *buffer);
114   bool Send( const void *buffer, int bytes );
115   bool Send( const char *buffer);
116   std::string Recv(bool wait4point);
117   bool openSocket();
118   bool closeSocket();
119   struct toc cdtoc[100];
120   int cddb_sum(int n);
121   void addInexactList(const char *list);
122   void addInexactListLine(int line_cnt, const char *line, int len);
123   const CStdString& getInexactCommand(int select) const;
124   CStdString GetCacheFile(uint32_t disc_id) const;
125   /*! \brief Trim and convert some text to UTF8
126    \param untrimmedText original text to trim and convert
127    \return a utf8 version of the trimmed text
128    */
129   CStdString TrimToUTF8(const CStdString &untrimmed);
130
131   CStdString m_cddb_ip_adress;
132   CStdString cCacheDir;
133 };
134 }
135
136 #endif