00001 /*MT* 00002 00003 MediaTomb - http://www.mediatomb.cc/ 00004 00005 play_hook.cc - this file is part of MediaTomb. 00006 00007 Copyright (C) 2005 Gena Batyan <bgeradz@mediatomb.cc>, 00008 Sergey 'Jin' Bostandzhyan <jin@mediatomb.cc> 00009 00010 Copyright (C) 2006-2010 Gena Batyan <bgeradz@mediatomb.cc>, 00011 Sergey 'Jin' Bostandzhyan <jin@mediatomb.cc>, 00012 Leonhard Wimmer <leo@mediatomb.cc> 00013 00014 MediaTomb is free software; you can redistribute it and/or modify 00015 it under the terms of the GNU General Public License version 2 00016 as published by the Free Software Foundation. 00017 00018 MediaTomb is distributed in the hope that it will be useful, 00019 but WITHOUT ANY WARRANTY; without even the implied warranty of 00020 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00021 GNU General Public License for more details. 00022 00023 You should have received a copy of the GNU General Public License 00024 version 2 along with MediaTomb; if not, write to the Free Software 00025 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. 00026 00027 $Id: play_hook.cc 2081 2010-03-23 20:18:00Z lww $ 00028 */ 00029 00032 // 00033 // \todo this should be solved via an observer model 00034 00035 #ifdef HAVE_CONFIG_H 00036 #include "autoconfig.h" 00037 #endif 00038 00039 #include "play_hook.h" 00040 #include "config_manager.h" 00041 #include "content_manager.h" 00042 00043 #ifdef HAVE_LASTFMLIB 00044 #include "lastfm_scrobbler.h" 00045 #endif 00046 00047 using namespace zmm; 00048 00049 SINGLETON_MUTEX(PlayHook, false); 00050 00051 void PlayHook::trigger(zmm::Ref<CdsObject> obj) 00052 { 00053 Ref<ConfigManager> cfg = ConfigManager::getInstance(); 00054 00055 if (cfg->getBoolOption(CFG_SERVER_EXTOPTS_MARK_PLAYED_ITEMS_ENABLED) && !obj->getFlag(OBJECT_FLAG_PLAYED)) 00056 { 00057 Ref<Array<StringBase> > mark_list = cfg->getStringArrayOption(CFG_SERVER_EXTOPTS_MARK_PLAYED_ITEMS_CONTENT_LIST); 00058 00059 for (int i = 0; i < mark_list->size(); i++) 00060 { 00061 if (RefCast(obj, CdsItem)->getMimeType().startsWith(mark_list->get(i))) 00062 { 00063 obj->setFlag(OBJECT_FLAG_PLAYED); 00064 00065 bool supress = cfg->getBoolOption(CFG_SERVER_EXTOPTS_MARK_PLAYED_ITEMS_SUPPRESS_CDS_UPDATES); 00066 00067 Ref<ContentManager> cm = ContentManager::getInstance(); 00068 log_debug("Marking object %s as played\n", obj->getTitle().c_str()); 00069 cm->updateObject(obj, !supress); 00070 break; 00071 } 00072 } 00073 } 00074 00075 #ifdef HAVE_LASTFMLIB 00076 if (cfg->getBoolOption(CFG_SERVER_EXTOPTS_LASTFM_ENABLED) && 00077 (RefCast(obj, CdsItem)->getMimeType().startsWith("audio"))) 00078 LastFm::getInstance()->startedPlaying(RefCast(obj, CdsItem)); 00079 #endif 00080 00081 }
1.6.1