kodi
cddb.h
1 /*
2  * Copyright (C) 2005-2018 Team Kodi
3  * This file is part of Kodi - https://kodi.tv
4  *
5  * SPDX-License-Identifier: GPL-2.0-or-later
6  * See LICENSES/README.md for more information.
7  */
8 
9 #pragma once
10 
11 #include <string>
12 #include <sstream>
13 #include <iostream>
14 #include <map>
15 #ifndef TARGET_POSIX
16 #include <strstream>
17 #endif
18 #include "storage/cdioSupport.h"
19 
20 #include "utils/ScopeGuard.h"
21 
22 namespace CDDB
23 {
24 
25 //Can be removed if/when removing Xcddb::queryCDinfo(int real_track_count, toc cdtoc[])
26 //#define IN_PROGRESS -1
27 //#define QUERY_OK 7
28 //#define E_INEXACT_MATCH_FOUND 211
29 //#define W_CDDB_already_shook_hands 402
30 //#define E_CDDB_Handshake_not_successful 431
31 
32 #define E_TOC_INCORRECT 2
33 #define E_NETWORK_ERROR_OPEN_SOCKET 3
34 #define E_NETWORK_ERROR_SEND 4
35 #define E_WAIT_FOR_INPUT 5
36 #define E_PARAMETER_WRONG 6
37 #define E_NO_MATCH_FOUND 202
38 
39 #define CDDB_PORT 8880
40 
41 
42 struct toc
43 {
44  int min;
45  int sec;
46  int frame;
47 };
48 
49 
50 class Xcddb
51 {
52 public:
53  Xcddb();
54  virtual ~Xcddb();
55  void setCDDBIpAddress(const std::string& ip_address);
56  void setCacheDir(const std::string& pCacheDir );
57 
58 // int queryCDinfo(int real_track_count, toc cdtoc[]);
59  bool queryCDinfo(MEDIA_DETECT::CCdInfo* pInfo, int inexact_list_select);
60  bool queryCDinfo(MEDIA_DETECT::CCdInfo* pInfo);
61  int getLastError() const;
62  const char * getLastErrorText() const;
63  const std::string& getYear() const;
64  const std::string& getGenre() const;
65  const std::string& getTrackArtist(int track) const;
66  const std::string& getTrackTitle(int track) const;
67  void getDiskArtist(std::string& strdisk_artist) const;
68  void getDiskTitle(std::string& strdisk_title) const;
69  const std::string& getTrackExtended(int track) const;
70  uint32_t calc_disc_id(int nr_of_tracks, toc cdtoc[]);
71  const std::string& getInexactArtist(int select) const;
72  const std::string& getInexactTitle(int select) const;
73  bool queryCache( uint32_t discid );
74  bool writeCacheFile( const char* pBuffer, uint32_t discid );
75  bool isCDCached( int nr_of_tracks, toc cdtoc[] );
76  bool isCDCached( MEDIA_DETECT::CCdInfo* pInfo );
77 
78 protected:
79  std::string m_strNull;
80 #if defined(TARGET_WINDOWS)
82 #else
83  using CAutoPtrSocket = KODI::UTILS::CScopeGuard<int, -1, decltype(close)>;
84 #endif
85  CAutoPtrSocket m_cddb_socket;
86  const static int recv_buffer = 4096;
87  int m_lastError;
88  std::map<int, std::string> m_mapTitles;
89  std::map<int, std::string> m_mapArtists;
90  std::map<int, std::string> m_mapExtended_track;
91 
92  std::map<int, std::string> m_mapInexact_cddb_command_list;
93  std::map<int, std::string> m_mapInexact_artist_list;
94  std::map<int, std::string> m_mapInexact_title_list;
95 
96 
97  std::string m_strDisk_artist;
98  std::string m_strDisk_title;
99  std::string m_strYear;
100  std::string m_strGenre;
101 
102  void addTitle(const char *buffer);
103  void addExtended(const char *buffer);
104  void parseData(const char *buffer);
105  bool Send( const void *buffer, int bytes );
106  bool Send( const char *buffer);
107  std::string Recv(bool wait4point);
108  bool openSocket();
109  bool closeSocket();
110  struct toc cdtoc[100];
111  int cddb_sum(int n);
112  void addInexactList(const char *list);
113  void addInexactListLine(int line_cnt, const char *line, int len);
114  const std::string& getInexactCommand(int select) const;
115  std::string GetCacheFile(uint32_t disc_id) const;
120  std::string TrimToUTF8(const std::string &untrimmed);
121 
122  std::string m_cddb_ip_address;
123  std::string cCacheDir;
124 };
125 }
Definition: cddb.h:50
Definition: cdioSupport.h:114
Definition: cddb.h:22
Definition: cddb.h:42
Definition: visualization.h:21