diff options
author | thlo <smarttv640@gmail.com> | 2013-04-04 21:05:33 +0200 |
---|---|---|
committer | thlo <t.lohmar@gmx.de> | 2013-04-04 21:05:33 +0200 |
commit | 4c2f508b616652c05288aef8c11cfe10c9502d24 (patch) | |
tree | d79396cb2cfb4bde345a4c8339d38098ff5b3eb0 /mngurls.c | |
parent | afb4d3bebf5e4ecbaba0cee23a66bd745e07ef4c (diff) | |
download | vdr-plugin-smarttvweb-4c2f508b616652c05288aef8c11cfe10c9502d24.tar.gz vdr-plugin-smarttvweb-4c2f508b616652c05288aef8c11cfe10c9502d24.tar.bz2 |
New urls manager for YouTube URLs. New http client class. Various bug fixes.
Diffstat (limited to 'mngurls.c')
-rw-r--r-- | mngurls.c | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/mngurls.c b/mngurls.c new file mode 100644 index 0000000..e9f18d0 --- /dev/null +++ b/mngurls.c @@ -0,0 +1,106 @@ +/* + * mgnurls.c: VDR on Smart TV plugin + * + * Copyright (C) 2012, 2013 T. Lohmar + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Or, point your browser to http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * + */ + +#include "mngurls.h" + + +cManageUrls::cManageUrls(string dir): mLog(), mFile(NULL), mEntries() { + mLog = Log::getInstance(); + + loadEntries(dir); + mFile = new ofstream((dir +"/urls.txt").c_str(), ios::out | ios::app); + mFile->seekp(ios_base::end); +}; + +cManageUrls::~cManageUrls() { + if (mFile != NULL) { + mFile->close(); + delete mFile; + } + //TODO: delete entries +}; + +//called from outside to add an entry +void cManageUrls::appendEntry(string type, string url) { + // iter through entries + *(mLog->log()) << " cManageUrls::appendEntry: type= " << type << "url= " << url << endl; + + bool found = false; + if (type.compare("YT") !=0) { + return; + } + for (int i = 0; i < mEntries.size(); i ++) { + if (url.compare(mEntries[i]->mEntry) == 0) { + found = true; + break; + } + } + if (!found) { + *(mLog->log()) << " cManageUrls::appendEntry: Appending... " << endl; + mEntries.push_back (new sUrlEntry (type, url)); + appendToFile(type+"|"+url); + } +} + +size_t cManageUrls::size() { + return mEntries.size(); +} + +sUrlEntry* cManageUrls::getEntry( int index) { + return mEntries[index]; +}; + +void cManageUrls::loadEntries(string dir) { + ifstream myfile ((dir +"/urls.txt").c_str()); + string line; + + string type; + + while ( myfile.good() ) { + getline (myfile, line); + + if ((line == "") or (line[0] == '#')) + continue; + + size_t pos = line.find('|'); + string type = line.substr(0, pos); + string value = line.substr(pos+1); + + // sUrlEntry* entry = new sUrlEntry(type, value); + mEntries.push_back(new sUrlEntry(type, value)); + } + myfile.close(); +}; + +void cManageUrls::appendToFile(string s_line) { + if (mFile == NULL) { + *(mLog->log()) << " ERROR in cManageUrls::appendToFile: no file open... " << endl; + return; + } + *(mLog->log()) << " cManageUrls::appendToFile: writing " << s_line << endl; + *mFile << s_line; + // mFile->write(s_line.c_str(), s_line.size()); + + mFile->flush(); + +} + |