summaryrefslogtreecommitdiff
path: root/mpv.c
blob: e8a200babb21cd8a6aa9be0db177aa2be806a062 (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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
//////////////////////////////////////////////////////////////////////////////
///                                                                        ///
/// This file is part of the VDR mpv plugin and licensed under AGPLv3      ///
///                                                                        ///
/// See the README file for copyright information                          ///
///                                                                        ///
//////////////////////////////////////////////////////////////////////////////

#include <string>
#include <vdr/plugin.h>

// set this define to create the instance of the config class
#define CREATE_CONFIG 1
#include "config.h"
#include "control.h"
#include "setup.h"
#include "playmenu.h"
#include "mpv_service.h"

static const char *VERSION = "0.0.4"
  #ifdef GIT_REV
    "-GIT" GIT_REV
  #endif
  ;

using std::string;

static const char *DESCRIPTION = trNOOP("mpv player plugin");
static const char *MAINMENUENTRY = trNOOP("MPV");

class cMpvPlugin:public cPlugin
{
  private:
    void PlayFile(string Filename, bool Shuffle=false) { cControl::Launch(new cMpvControl(Filename.c_str(), Shuffle)); }
    bool IsIsoImage(string Filename);
    void PlayFileHandleType(string Filename, bool Shuffle=false);

  public:
    cMpvPlugin(void);
    virtual ~cMpvPlugin(void);
    virtual const char *Version(void) { return VERSION; }
    virtual const char *Description(void) { return tr(DESCRIPTION); }
    virtual const char *CommandLineHelp(void) { return MpvPluginConfig->CommandLineHelp(); }
    virtual bool ProcessArgs(int argc, char *argv[]) { return MpvPluginConfig->ProcessArgs(argc, argv); }
    virtual bool Initialize(void) { return true; }
    virtual void MainThreadHook(void) {}
    virtual const char *MainMenuEntry(void) { return MpvPluginConfig->HideMainMenuEntry ? NULL : tr(MAINMENUENTRY); }
    virtual cOsdObject *MainMenuAction(void);
    virtual cMenuSetupPage *SetupMenu(void) { return new cMpvPluginSetup; }
    virtual bool SetupParse(const char *Name, const char *Value) { return MpvPluginConfig->SetupParse(Name, Value); }
    virtual bool Service(const char *Id, void *Data = NULL);
    virtual const char **SVDRPHelpPages(void) { return NULL; }
    virtual cString SVDRPCommand(const char *Command, const char *Option, int &ReplayCode);
};

cMpvPlugin::cMpvPlugin(void)
{
  MpvPluginConfig = new cMpvPluginConfig();
}

cMpvPlugin::~cMpvPlugin(void)
{
  delete MpvPluginConfig;
}

cOsdObject *cMpvPlugin::MainMenuAction(void)
{
  return new cPlayMenu("MPV");
}

bool cMpvPlugin::Service(const char *id, void *data)
{
  if (strcmp(id, "Mpv_PlayFile") == 0)
  {
    Mpv_PlayFile *playFile = (Mpv_PlayFile *)data;
    PlayFileHandleType(playFile->Filename);
    return true;
  }
  if (strcmp(id, "Mpv_PlaylistShuffle") == 0)
  {
    Mpv_PlaylistShuffle *shuffleFile = (Mpv_PlaylistShuffle *)data;
    PlayFileHandleType(shuffleFile->Filename, true);
    return true;
  }
  if (strcmp(id, "Mpv_SetTitle") == 0)
  {
    Mpv_SetTitle *setTitle = (Mpv_SetTitle *) data;
    MpvPluginConfig->TitleOverride = setTitle->Title;
    return true;
  }
  if (strcmp(id, MPV_START_PLAY_SERVICE) == 0)
  {
    Mpv_StartPlayService_v1_0_t *r = (Mpv_StartPlayService_v1_0_t *) data;
    PlayFileHandleType(r->Filename);
    return true;
  }
  if (strcmp(id, MPV_SET_TITLE_SERVICE) == 0)
  {
    Mpv_SetTitleService_v1_0_t *r = (Mpv_SetTitleService_v1_0_t *) data;
    MpvPluginConfig->TitleOverride = r->Title;
    return true;
  }
  return false;
}

cString cMpvPlugin::SVDRPCommand(const char *Command, const char *Option, int &ReplayCode)
{
  dsyslog ("Command %s Option %s\n", Command, Option);
  if (strcasecmp(Command, "PLAY") == 0)
  {
    PlayFileHandleType(Option);
    cControl::Attach();
    return "starting player";
  }
  return NULL;
}

bool cMpvPlugin::IsIsoImage(string Filename)
{
  vector<string> IsoExtensions;
  IsoExtensions.push_back("bin");
  IsoExtensions.push_back("dvd");
  IsoExtensions.push_back("img");
  IsoExtensions.push_back("iso");
  IsoExtensions.push_back("mdf");
  IsoExtensions.push_back("nrg");
  for (unsigned int i=0;i<IsoExtensions.size();i++)
  {
    if (Filename.substr(Filename.find_last_of(".") + 1) == IsoExtensions[i])
      return true;
  }

  return false;
}

void cMpvPlugin::PlayFileHandleType(string Filename, bool Shuffle)
{
  if (IsIsoImage(Filename.c_str())) // handle dvd iso images
  {
    Filename = "dvd://menu/" + Filename;
  }
  PlayFile(Filename, Shuffle);
}

VDRPLUGINCREATOR(cMpvPlugin); // Don't touch this!