diff options
author | thlo <smarttv640@gmail.com> | 2013-09-02 18:53:27 +0200 |
---|---|---|
committer | thlo <smarttv640@gmail.com> | 2013-09-02 18:53:27 +0200 |
commit | c8990cb5fcb0837ded0ba5281b086d44c904d18f (patch) | |
tree | 411474a073c2d0b9b73928dcb2b270f4f1a761d9 | |
parent | b67fdbd19781ea9a5c00e5ce2332ae80aa4e2647 (diff) | |
download | vdr-plugin-smarttvweb-c8990cb5fcb0837ded0ba5281b086d44c904d18f.tar.gz vdr-plugin-smarttvweb-c8990cb5fcb0837ded0ba5281b086d44c904d18f.tar.bz2 |
Provide correct MIME types for media.xml
-rw-r--r-- | responsebase.c | 27 | ||||
-rw-r--r-- | responsebase.h | 2 | ||||
-rw-r--r-- | responsefile.c | 27 | ||||
-rw-r--r-- | responsefile.h | 2 | ||||
-rwxr-xr-x | responsememblk.c | 18 | ||||
-rwxr-xr-x | responsememblk.h | 5 | ||||
-rwxr-xr-x | stvw_cfg.c | 1 |
7 files changed, 43 insertions, 39 deletions
diff --git a/responsebase.c b/responsebase.c index 633b922..5297700 100644 --- a/responsebase.c +++ b/responsebase.c @@ -125,6 +125,33 @@ void cResponseBase::sendHeaders(int status, const char *title, const char *extra strcpy(mBlkData, hdr.c_str()); } +const char *cResponseBase::getMimeType(const char *name) { + char *ext = strrchr((char*)name, '.'); + if (!ext) + return "application/octet-stream"; + + if (strcmp(ext, ".html") == 0 || strcmp(ext, ".htm") == 0) return "text/html"; + if (strcmp(ext, ".jpg") == 0 || strcmp(ext, ".jpeg") == 0) return "image/jpeg"; + if (strcmp(ext, ".gif") == 0) return "image/gif"; + if (strcmp(ext, ".png") == 0) return "image/png"; + if (strcmp(ext, ".xml") == 0) return "application/xml"; + if (strcmp(ext, ".css") == 0) return "text/css"; + if (strcmp(ext, ".js") == 0) return "text/javascript"; + if (strcmp(ext, ".au") == 0) return "audio/basic"; + if (strcmp(ext, ".wav") == 0) return "audio/wav"; + if (strcmp(ext, ".avi") == 0) return "video/x-msvideo"; + if (strcmp(ext, ".mp4") == 0) return "video/mp4"; + if (strcmp(ext, ".3gp") == 0) return "video/3gp"; + if (strcmp(ext, ".vdr") == 0) return "video/mpeg"; + if (strcmp(ext, ".ts") == 0) return "video/mpeg"; + if (strcmp(ext, ".mpeg") == 0 || strcmp(ext, ".mpg") == 0) return "video/mpeg"; + if (strcmp(ext, ".mp3") == 0) return "audio/mpeg"; + if (strcmp(ext, ".mpd") == 0) return "application/dash+xml"; + if (strcmp(ext, ".m3u8") == 0) return "application/x-mpegURL"; + + return "application/octet-stream"; +} + int cResponseBase::fillDataBlk() { diff --git a/responsebase.h b/responsebase.h index 18ea439..5600866 100644 --- a/responsebase.h +++ b/responsebase.h @@ -50,6 +50,8 @@ class cResponseBase { void sendHeaders(int status, const char *title, const char *extra, const char *mime, long long int length, time_t date); + const char *getMimeType(const char *name) ; + Log* mLog; cHttpResource* mRequest; uint64_t mRemLength; diff --git a/responsefile.c b/responsefile.c index 4fed5e4..90fa97b 100644 --- a/responsefile.c +++ b/responsefile.c @@ -47,33 +47,6 @@ cResponseFile::~cResponseFile() { } -const char *cResponseFile::getMimeType(const char *name) { - char *ext = strrchr((char*)name, '.'); - if (!ext) - return NULL; - // if (ext.compare(".html") || ext.compare(".htm")) return "text/html"; - if (strcmp(ext, ".html") == 0 || strcmp(ext, ".htm") == 0) return "text/html"; - if (strcmp(ext, ".jpg") == 0 || strcmp(ext, ".jpeg") == 0) return "image/jpeg"; - if (strcmp(ext, ".gif") == 0) return "image/gif"; - if (strcmp(ext, ".png") == 0) return "image/png"; - if (strcmp(ext, ".xml") == 0) return "application/xml"; - if (strcmp(ext, ".css") == 0) return "text/css"; - if (strcmp(ext, ".js") == 0) return "text/javascript"; - if (strcmp(ext, ".au") == 0) return "audio/basic"; - if (strcmp(ext, ".wav") == 0) return "audio/wav"; - if (strcmp(ext, ".avi") == 0) return "video/x-msvideo"; - if (strcmp(ext, ".mp4") == 0) return "video/mp4"; - if (strcmp(ext, ".vdr") == 0) return "video/mpeg"; - if (strcmp(ext, ".ts") == 0) return "video/mpeg"; - if (strcmp(ext, ".mpeg") == 0 || strcmp(ext, ".mpg") == 0) return "video/mpeg"; - if (strcmp(ext, ".mp3") == 0) return "audio/mpeg"; - if (strcmp(ext, ".mpd") == 0) return "application/dash+xml"; - if (strcmp(ext, ".m3u8") == 0) return "application/x-mpegURL"; - - return NULL; -} - - int cResponseFile::sendFile() { // Send the First Datachunk, incl all headers diff --git a/responsefile.h b/responsefile.h index b4a1b36..2133b83 100644 --- a/responsefile.h +++ b/responsefile.h @@ -40,8 +40,6 @@ class cResponseFile : public cResponseBase { int sendFile(); private: - const char *getMimeType(const char *name) ; - int openFile(const char *name); FILE *mFile; diff --git a/responsememblk.c b/responsememblk.c index 292dabb..563167f 100755 --- a/responsememblk.c +++ b/responsememblk.c @@ -1275,7 +1275,7 @@ uint64_t cResponseMemBlk::getVdrFileSize() { // common for all create xml file modules -int cResponseMemBlk::writeXmlItem(string name, string link, string programme, string desc, string guid, int no, time_t start, int dur, double fps, int is_pes, int is_new) { +int cResponseMemBlk::writeXmlItem(string name, string link, string programme, string desc, string guid, int no, time_t start, int dur, double fps, int is_pes, int is_new, string mime) { string hdr = ""; char f[400]; @@ -1283,7 +1283,8 @@ int cResponseMemBlk::writeXmlItem(string name, string link, string programme, st // snprintf(f, sizeof(f), "%s - %s", ); hdr += "<title>" + name +"</title>\n"; hdr += "<link>" +link + "</link>\n"; - hdr += "<enclosure url=\"" +link + "\" type=\"video/mpeg\" />\n"; + // hdr += "<enclosure url=\"" +link + "\" type=\"video/mpeg\" />\n"; + hdr += "<enclosure url=\"" +link + "\" type=\""+mime+"\" />\n"; hdr += "<guid>" + guid + "</guid>\n"; @@ -1478,7 +1479,7 @@ int cResponseMemBlk::parseFiles(vector<sFileEntry> *entries, string prefix, stri << " Vdr Folder Found: " << pathbuf << " start= " << start << endl; #endif - entries->push_back(sFileEntry(dir_name, pathbuf, start)); + entries->push_back(sFileEntry(dir_name, pathbuf, start, "video/mpeg")); } else { // regular file @@ -1486,8 +1487,9 @@ int cResponseMemBlk::parseFiles(vector<sFileEntry> *entries, string prefix, stri } } else { - if ((de->d_name)[0] != '.' ) - entries->push_back(sFileEntry(prefix+de->d_name, pathbuf, 1)); + if ((de->d_name)[0] != '.' ) { + entries->push_back(sFileEntry(prefix+de->d_name, pathbuf, 1, getMimeType(de->d_name))); + } } } closedir(dir); @@ -1538,7 +1540,7 @@ int cResponseMemBlk::sendMediaXml (struct stat *statbuf) { snprintf(pathbuf, sizeof(pathbuf), "http://%s:%d%s", own_ip.c_str(), mRequest->mServerPort, cUrlEncode::doUrlSaveEncode(entries[i].sPath).c_str()); if (writeXmlItem(cUrlEncode::doXmlSaveEncode(entries[i].sName), pathbuf, "NA", "NA", "-", - -1, entries[i].sStart, -1, -1, -1, -1) == ERROR) + -1, entries[i].sStart, -1, -1, -1, -1, entries[i].sMime) == ERROR) return ERROR; } @@ -1872,7 +1874,7 @@ int cResponseMemBlk::sendChannelsXml (struct stat *statbuf) { string c_name = (group_sep != "") ? (group_sep + "~" + cUrlEncode::doXmlSaveEncode(channel->Name())) : cUrlEncode::doXmlSaveEncode(channel->Name()); // if (writeXmlItem(channel->Name(), link, title, desc, *(channel->GetChannelID()).ToString(), start_time, duration) == ERROR) - if (writeXmlItem(c_name, link, title, desc, *(channel->GetChannelID()).ToString(), channel->Number(), start_time, duration, -1, -1, -1) == ERROR) + if (writeXmlItem(c_name, link, title, desc, *(channel->GetChannelID()).ToString(), channel->Number(), start_time, duration, -1, -1, -1, "video/mpeg") == ERROR) return ERROR; } @@ -2244,7 +2246,7 @@ int cResponseMemBlk::sendRecordingsXml(struct stat *statbuf) { cUrlEncode::doUrlSaveEncode(recording->FileName()).c_str(), -1, recording->Start(), rec_dur, recording->FramesPerSecond(), - (recording->IsPesRecording() ? 0: 1), (recording->IsNew() ? 0: 1)) == ERROR) { + (recording->IsPesRecording() ? 0: 1), (recording->IsNew() ? 0: 1), "video/mpeg") == ERROR) { *mResponseMessage = ""; sendError(500, "Internal Server Error", NULL, "005 writeXMLItem returned an error"); return OKAY; diff --git a/responsememblk.h b/responsememblk.h index f0b1174..ce17989 100755 --- a/responsememblk.h +++ b/responsememblk.h @@ -38,8 +38,9 @@ struct sFileEntry { string sName; string sPath; int sStart; + string sMime; -sFileEntry(string n, string l, int s) : sName(n), sPath(l), sStart(s) { +sFileEntry(string n, string l, int s, string m) : sName(n), sPath(l), sStart(s), sMime(m) { }; }; @@ -91,7 +92,7 @@ class cResponseMemBlk : public cResponseBase { int parseResume(cResumeEntry &entry, string &id); int parseFiles(vector<sFileEntry> *entries, string prefix, string dir_base, string dir_name, struct stat *statbuf); int sendDir(struct stat *statbuf); - int writeXmlItem(string title, string link, string programme, string desc, string guid, int no, time_t start, int dur, double fps, int is_pes, int is_new); + int writeXmlItem(string title, string link, string programme, string desc, string guid, int no, time_t start, int dur, double fps, int is_pes, int is_new, string mime); uint64_t getVdrFileSize(); private: @@ -106,6 +106,7 @@ void cSmartTvConfig::readConfig() { // cout << " Found mMediaFolder= " << mMediaFolder << endl; continue; } + if (strcmp(attr, "SegmentDuration") == 0) { mSegmentDuration = atoi(value); // cout << " Found mSegmentDuration= " << mSegmentDuration << endl; |