From d5c26eb7a9c51e82be0ac41bd04f4433043776cd Mon Sep 17 00:00:00 2001 From: thlo Date: Thu, 4 Apr 2013 21:05:33 +0200 Subject: New urls manager for YouTube URLs. New http client class. Various bug fixes. --- mngurls.c | 106 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 mngurls.c (limited to 'mngurls.c') 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(); + +} + -- cgit v1.2.3