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 "MusicAlbumInfo.h"
12 #include "MusicArtistInfo.h"
13 #include "addons/Scraper.h"
14 #include "threads/Thread.h"
15 
16 #include <vector>
17 
18 namespace XFILE
19 {
20 class CurlFile;
21 }
22 
23 namespace MUSIC_GRABBER
24 {
25 class CMusicInfoScraper : public CThread
26 {
27 public:
28   explicit CMusicInfoScraper(const ADDON::ScraperPtr &scraper);
29   ~CMusicInfoScraper(void) override;
30   void FindAlbumInfo(const std::string& strAlbum, const std::string& strArtist = "");
31   void LoadAlbumInfo(int iAlbum);
32   void FindArtistInfo(const std::string& strArtist);
33   void LoadArtistInfo(int iArtist, const std::string &strSearch);
34   bool Completed();
35   bool Succeeded();
36   void Cancel();
37   bool IsCanceled();
38   int GetAlbumCount() const;
39   int GetArtistCount() const;
40   CMusicAlbumInfo& GetAlbum(int iAlbum);
41   CMusicArtistInfo& GetArtist(int iArtist);
GetArtists()42   std::vector<CMusicArtistInfo>& GetArtists()
43   {
44     return m_vecArtists;
45   }
GetAlbums()46   std::vector<CMusicAlbumInfo>& GetAlbums()
47   {
48     return m_vecAlbums;
49   }
SetScraperInfo(const ADDON::ScraperPtr & scraper)50   void SetScraperInfo(const ADDON::ScraperPtr& scraper)
51   {
52     m_scraper = scraper;
53   }
54   /*!
55    \brief Checks whether we have a valid scraper.  If not, we try the fallbackScraper
56    First tests the current scraper for validity by loading it.  If it is not valid we
57    attempt to load the fallback scraper.  If this is also invalid we return false.
58    \param fallbackScraper name of scraper to use as a fallback
59    \return true if we have a valid scraper (or the default is valid).
60    */
61   bool CheckValidOrFallback(const std::string &fallbackScraper);
62 protected:
63   void FindAlbumInfo();
64   void LoadAlbumInfo();
65   void FindArtistInfo();
66   void LoadArtistInfo();
67   void OnStartup() override;
68   void Process() override;
69   std::vector<CMusicAlbumInfo> m_vecAlbums;
70   std::vector<CMusicArtistInfo> m_vecArtists;
71   std::string m_strAlbum;
72   std::string m_strArtist;
73   std::string m_strSearch;
74   int m_iAlbum;
75   int m_iArtist;
76   bool m_bSucceeded;
77   bool m_bCanceled;
78   XFILE::CCurlFile* m_http;
79   ADDON::ScraperPtr m_scraper;
80 };
81 
82 }
83