summaryrefslogtreecommitdiff
path: root/scraper2vdr.c
blob: 26fd9db934fb70301e1ac77f5a43b322b8d11062 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/**
 *  GraphTFTng plugin for the Video Disk Recorder 
 * 
 *  scraper2vdr.c
 *
 *  (c) 2006-2015 Jörg Wendel
 *
 * This code is distributed under the terms and conditions of the
 * GNU GENERAL PUBLIC LICENSE. See the file COPYING for details.
 * 
 **/

//***************************************************************************
// Includes
//***************************************************************************

#include <vdr/plugin.h>

#include <common.h>
#include <scraper2vdr.h>

//***************************************************************************
// Get Scraper Plugin
//***************************************************************************

cPlugin* GetScraperPlugin() 
{
   static cPlugin* pScraper = cPluginManager::GetPlugin("scraper2vdr");

   if (!pScraper)
      pScraper = cPluginManager::GetPlugin("tvscraper");

   return pScraper;
}

//***************************************************************************
// Get Media Path
//***************************************************************************

int getScraperMediaPath(const cEventCopy* event, const cRecording* recording,
                        std::string& bannerPath, std::string& posterPath)
{
   static cPlugin* pScraper = GetScraperPlugin();
   const cEvent* evt = 0;
   const cSchedule* s = 0;
   ScraperGetPosterBannerV2 call;

   bannerPath = "";
   posterPath = "";

   if (!pScraper)
   {
      tell(0, "Warning: Plugin scraper2vdr not found");
      return fail;
   }

#if defined (APIVERSNUM) && (APIVERSNUM >= 20301)
   LOCK_SCHEDULES_READ;
   const cSchedules* schedules = Schedules;
#else
   cSchedulesLock schedulesLock;
   const cSchedules* schedules = (cSchedules*)cSchedules::Schedules(schedulesLock);
#endif

   if (recording)
   {
      event = 0;
      call.recording = recording;
   }
   else if (event)
   {
      // lock und schedule (channel) holen
      
      if (!schedules ||
          !(s = (cSchedule*)schedules->GetSchedule(event->ChannelID())) ||
          !(evt = s->GetEvent(event->EventID())))
      {
         tell(0, "Error, can't get lock on schedules or cant find event, aborting!");
         return fail;
      }

      call.event = evt;
   }

   if (pScraper->Service("GetPosterBannerV2", &call)) 
   {
      if (call.type == tSeries && call.banner.path.size() > 0) 
      {
         ScraperGetPoster callPoster;

         bannerPath = call.banner.path;

         callPoster.event = evt;                     // only one is set
         callPoster.recording = recording;           //  "    "   "  "

         if (pScraper->Service("GetPoster", &callPoster)) 
            posterPath = callPoster.poster.path;
      } 
      else if (call.type == tMovie && call.poster.path.size() > 0 && call.poster.height > 0) 
      {
         posterPath = call.poster.path;
      } 
   }

   return bannerPath.size() || posterPath.size() ? success : fail;
}