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 "Episode.h" 12 #include "VideoInfoTag.h" 13 #include "addons/Scraper.h" 14 #include "filesystem/CurlFile.h" 15 #include "threads/Thread.h" 16 17 #include <string> 18 #include <vector> 19 20 // forward declarations 21 class CXBMCTinyXML; 22 class CGUIDialogProgress; 23 24 namespace ADDON 25 { 26 class CScraperError; 27 } 28 29 typedef std::vector<CScraperUrl> MOVIELIST; 30 31 class CVideoInfoDownloader : public CThread 32 { 33 public: 34 explicit CVideoInfoDownloader(const ADDON::ScraperPtr &scraper); 35 ~CVideoInfoDownloader() override; 36 37 // threaded lookup functions 38 39 /*! \brief Do a search for matching media items (possibly asynchronously) with our scraper 40 \param movieTitle title of the media item to look for 41 \param movieYear year of the media item to look for (-1 if not known) 42 \param movielist [out] list of results to fill. May be empty on success. 43 \param pProgress progress bar to update as we go. If NULL we run on thread, if non-NULL we run off thread. 44 \return 1 on success, -1 on a scraper-specific error, 0 on some other error 45 */ 46 int FindMovie(const std::string& movieTitle, int movieYear, MOVIELIST& movielist, CGUIDialogProgress *pProgress = NULL); 47 48 /*! \brief Fetch art URLs for an item with our scraper 49 \param details the video info tag structure to fill with art. 50 \return true on success, false on failure. 51 */ 52 bool GetArtwork(CVideoInfoTag &details); 53 54 bool GetDetails(const CScraperUrl& url, CVideoInfoTag &movieDetails, CGUIDialogProgress *pProgress = NULL); 55 bool GetEpisodeDetails(const CScraperUrl& url, CVideoInfoTag &movieDetails, CGUIDialogProgress *pProgress = NULL); 56 bool GetEpisodeList(const CScraperUrl& url, VIDEO::EPISODELIST& details, CGUIDialogProgress *pProgress = NULL); 57 58 static void ShowErrorDialog(const ADDON::CScraperError &sce); 59 60 protected: 61 enum LOOKUP_STATE { DO_NOTHING = 0, 62 FIND_MOVIE = 1, 63 GET_DETAILS = 2, 64 GET_EPISODE_LIST = 3, 65 GET_EPISODE_DETAILS = 4 }; 66 67 XFILE::CCurlFile* m_http; 68 std::string m_movieTitle; 69 int m_movieYear; 70 MOVIELIST m_movieList; 71 CVideoInfoTag m_movieDetails; 72 CScraperUrl m_url; 73 VIDEO::EPISODELIST m_episode; 74 LOOKUP_STATE m_state; 75 int m_found; 76 ADDON::ScraperPtr m_info; 77 78 // threaded stuff 79 void Process() override; 80 void CloseThread(); 81 82 int InternalFindMovie(const std::string& movieTitle, int movieYear, MOVIELIST& movielist, bool cleanChars = true); 83 }; 84 85