summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntti Ajanki <antti.ajanki@iki.fi>2010-10-24 20:59:25 +0300
committerAntti Ajanki <antti.ajanki@iki.fi>2010-10-24 20:59:25 +0300
commit439024953d1abe71fd5adce26fac4f17c1aa9f96 (patch)
tree687694e77b2c097955ea5c62fb6dc817e47931a8
parent1dc2ecb06b87c71aa22544b563ca6137bca71418 (diff)
downloadvdr-plugin-webvideo-439024953d1abe71fd5adce26fac4f17c1aa9f96.tar.gz
vdr-plugin-webvideo-439024953d1abe71fd5adce26fac4f17c1aa9f96.tar.bz2
SVDRP commands for downloading and playing video streams
-rw-r--r--src/vdr-plugin/common.c42
-rw-r--r--src/vdr-plugin/common.h4
-rw-r--r--src/vdr-plugin/config.c14
-rw-r--r--src/vdr-plugin/webvideo.c47
4 files changed, 100 insertions, 7 deletions
diff --git a/src/vdr-plugin/common.c b/src/vdr-plugin/common.c
index 12a5204..5ad2747 100644
--- a/src/vdr-plugin/common.c
+++ b/src/vdr-plugin/common.c
@@ -39,6 +39,36 @@ char *extensionFromUrl(const char *url) {
return NULL;
}
+cString parseDomain(const char *url) {
+ const char *schemesep = strstr(url, "://");
+ if (!schemesep)
+ return "";
+
+ const char *domainstart = schemesep+3;
+ const char *domainend = strchr(domainstart, '/');
+
+ int len = domainend-domainstart;
+ char *domain = (char *)malloc((len+1)*sizeof(char));
+ strncpy(domain, domainstart, len);
+ domain[len] = '\0';
+
+ const char *user = strchr(domain, '@');
+ if (user) {
+ len -= user+1 - domain;
+ memmove(domain, user+1, len+1);
+ }
+
+ const char *port = strchr(domain, ':');
+ if (port) {
+ len = port - domain;
+ domain[len] = '\0';
+ }
+
+ strlower(domain);
+
+ return cString(domain, true);
+}
+
char *validateFileName(const char *filename) {
if (!filename)
return NULL;
@@ -203,3 +233,15 @@ cString shellEscape(const char *s) {
return cString(buffer, true);
}
+
+char *strlower(char *s) {
+ if (!s) return NULL;
+
+ char *p = s;
+ while (*p) {
+ *p = tolower(*p);
+ p++;
+ }
+
+ return s;
+}
diff --git a/src/vdr-plugin/common.h b/src/vdr-plugin/common.h
index bbdb8c2..90dfb5f 100644
--- a/src/vdr-plugin/common.h
+++ b/src/vdr-plugin/common.h
@@ -24,6 +24,8 @@
// Return the extension of the url or NULL, if the url has no
// extension. The caller must free the returned string.
char *extensionFromUrl(const char *url);
+// Return the domain part from url.
+cString parseDomain(const char *url);
// Returns a "safe" version of filename. Currently just removes / from
// the name. The caller must free the returned string.
char *validateFileName(const char *filename);
@@ -40,5 +42,7 @@ char *URLdecode(const char *s);
char *safeFilename(char *filename);
// Escape s so that it can be passed as parameter to a shell command.
cString shellEscape(const char *s);
+// Convert string s to lower case
+char *strlower(char *s);
#endif // __WEBVIDEO_COMMON_H
diff --git a/src/vdr-plugin/config.c b/src/vdr-plugin/config.c
index 23a6feb..5428188 100644
--- a/src/vdr-plugin/config.c
+++ b/src/vdr-plugin/config.c
@@ -120,11 +120,17 @@ bool cWebvideoConfig::ReadConfigFile(const char *inifile) {
for (int i=0; i<iniparser_getnsec(conf); i++) {
const char *section = iniparser_getsecname(conf, i);
- if (strncmp(section, "site-", 5) == 0) {
- const char *sitename = section+5;
- const int maxsectionlen = 40;
- char key[64];
+ if (strcmp(section, "webvi") != 0) {
+ const int maxsectionlen = 100;
+ char key[128];
char *keyname;
+ const char *sitename;
+
+ cString domain = parseDomain(section);
+ if (domain == "")
+ sitename = section;
+ else
+ sitename = domain;
strncpy(key, section, maxsectionlen);
key[maxsectionlen] = '\0';
diff --git a/src/vdr-plugin/webvideo.c b/src/vdr-plugin/webvideo.c
index 9f79c5e..cb19b4c 100644
--- a/src/vdr-plugin/webvideo.c
+++ b/src/vdr-plugin/webvideo.c
@@ -46,6 +46,7 @@ private:
bool StartStreaming(const cString &streamurl);
void ExecuteTimers(void);
void HandleFinishedRequests(void);
+ cString CreateWvtRef(const char *url);
public:
cPluginWebvideo(void);
@@ -399,16 +400,56 @@ bool cPluginWebvideo::Service(const char *Id, void *Data)
const char **cPluginWebvideo::SVDRPHelpPages(void)
{
- // Return help text for SVDRP commands this plugin implements
- return NULL;
+ static const char *HelpPages[] = {
+ "PLAY <file>\n"
+ " Stream a media file.",
+ "DWLD <file>\n"
+ " Download a media file.",
+ NULL
+ };
+ return HelpPages;
}
cString cPluginWebvideo::SVDRPCommand(const char *Command, const char *Option, int &ReplyCode)
{
- // Process SVDRP commands this plugin implements
+ if(strcasecmp(Command, "PLAY") == 0 || strcasecmp(Command, "DWLD") == 0) {
+ if(*Option) {
+ debug("SVDRP(%s, %s)", Command, Option);
+ cString twvtref = CreateWvtRef(Option);
+ if (twvtref != "") {
+ cMenuRequest *req;
+ if (strcasecmp(Command, "PLAY") == 0)
+ req = new cStreamUrlRequest(0, twvtref);
+ else
+ req = new cFileDownloadRequest(0, twvtref, summaries.NewDownload());
+ cWebviThread::Instance().AddRequest(req);
+ ReplyCode = 250; // Ok
+ return cString("Downloading video file");
+ } else {
+ ReplyCode = 550; // Requested action not taken
+ return cString("Unable to parse URL");
+ }
+ } else {
+ ReplyCode = 550; // Requested action not taken
+ return cString("File name missing");
+ }
+ }
+
return NULL;
}
+cString cPluginWebvideo::CreateWvtRef(const char *url) {
+ cString domain = parseDomain(url);
+ if (domain == "")
+ return "";
+
+ char *encoded = URLencode(url);
+ cString res = cString::sprintf("wvt:///%s/videopage.xsl?srcurl=%s",
+ (const char *)domain, encoded);
+ free(encoded);
+ return res;
+}
+
void cPluginWebvideo::UpdateOSDFromHistory(const char *statusmsg) {
if (menuPointers.navigationMenu) {
cHistoryObject *hist = history.Current();