Merge pull request #4314 from MartijnKaijser/beta1
[vuplus_xbmc] / xbmc / music / tags / MusicInfoTagLoaderFactory.cpp
1 /*
2  *      Copyright (C) 2005-2013 Team XBMC
3  *      http://xbmc.org
4  *
5  *  This Program is free software; you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation; either version 2, or (at your option)
8  *  any later version.
9  *
10  *  This Program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with XBMC; see the file COPYING.  If not, see
17  *  <http://www.gnu.org/licenses/>.
18  *
19  */
20
21 #include "system.h"
22 #include "MusicInfoTagLoaderFactory.h"
23 #include "TagLoaderTagLib.h"
24 #include "MusicInfoTagLoaderCDDA.h"
25 #include "MusicInfoTagLoaderShn.h"
26 #ifdef HAS_MOD_PLAYER
27 #include "cores/ModPlayer.h"
28 #endif
29 #include "MusicInfoTagLoaderNSF.h"
30 #include "MusicInfoTagLoaderSPC.h"
31 #include "MusicInfoTagLoaderYM.h"
32 #include "MusicInfoTagLoaderDatabase.h"
33 #include "MusicInfoTagLoaderASAP.h"
34 #include "MusicInfoTagLoaderMidi.h"
35 #include "utils/StringUtils.h"
36 #include "utils/URIUtils.h"
37 #include "FileItem.h"
38
39 #ifdef HAS_ASAP_CODEC
40 #include "cores/paplayer/ASAPCodec.h"
41 #endif
42
43 using namespace MUSIC_INFO;
44
45 CMusicInfoTagLoaderFactory::CMusicInfoTagLoaderFactory()
46 {}
47
48 CMusicInfoTagLoaderFactory::~CMusicInfoTagLoaderFactory()
49 {}
50
51 IMusicInfoTagLoader* CMusicInfoTagLoaderFactory::CreateLoader(const CStdString& strFileName)
52 {
53   // dont try to read the tags for streams & shoutcast
54   CFileItem item(strFileName, false);
55   if (item.IsInternetStream())
56     return NULL;
57
58   if (item.IsMusicDb())
59     return new CMusicInfoTagLoaderDatabase();
60
61   CStdString strExtension = URIUtils::GetExtension(strFileName);
62   StringUtils::ToLower(strExtension);
63   StringUtils::TrimLeft(strExtension, ".");
64
65   if (strExtension.empty())
66     return NULL;
67
68   if (strExtension == "aac" ||
69       strExtension == "ape" || strExtension == "mac" ||
70       strExtension == "mp3" || 
71       strExtension == "wma" || 
72       strExtension == "flac" || 
73       strExtension == "m4a" || strExtension == "mp4" ||
74       strExtension == "mpc" || strExtension == "mpp" || strExtension == "mp+" ||
75       strExtension == "ogg" || strExtension == "oga" || strExtension == "oggstream" ||
76       strExtension == "aif" || strExtension == "aiff" ||
77       strExtension == "wav" ||
78 #ifdef HAS_MOD_PLAYER
79       ModPlayer::IsSupportedFormat(strExtension) ||
80       strExtension == "mod" || strExtension == "nsf" || strExtension == "nsfstream" ||
81       strExtension == "s3m" || strExtension == "it" || strExtension == "xm" ||
82 #endif
83       strExtension == "wv")
84   {
85     CTagLoaderTagLib *pTagLoader = new CTagLoaderTagLib();
86     return (IMusicInfoTagLoader*)pTagLoader;
87   }
88 #ifdef HAS_DVD_DRIVE
89   else if (strExtension == "cdda")
90   {
91     CMusicInfoTagLoaderCDDA *pTagLoader = new CMusicInfoTagLoaderCDDA();
92     return (IMusicInfoTagLoader*)pTagLoader;
93   }
94 #endif
95   else if (strExtension == "shn")
96   {
97     CMusicInfoTagLoaderSHN *pTagLoader = new CMusicInfoTagLoaderSHN();
98     return (IMusicInfoTagLoader*)pTagLoader;
99   }
100   else if (strExtension == "spc")
101   {
102     CMusicInfoTagLoaderSPC *pTagLoader = new CMusicInfoTagLoaderSPC();
103     return (IMusicInfoTagLoader*)pTagLoader;
104   }
105   else if (strExtension == "ym")
106   {
107     CMusicInfoTagLoaderYM *pTagLoader = new CMusicInfoTagLoaderYM();
108     return (IMusicInfoTagLoader*)pTagLoader;
109   }
110 #ifdef HAS_ASAP_CODEC
111   else if (ASAPCodec::IsSupportedFormat(strExtension) || strExtension == "asapstream")
112   {
113     CMusicInfoTagLoaderASAP *pTagLoader = new CMusicInfoTagLoaderASAP();
114     return (IMusicInfoTagLoader*)pTagLoader;
115   }
116 #endif
117   else if ( TimidityCodec::IsSupportedFormat( strExtension ) )
118   {
119     CMusicInfoTagLoaderMidi * pTagLoader = new CMusicInfoTagLoaderMidi();
120     return (IMusicInfoTagLoader*)pTagLoader;
121   }
122
123   return NULL;
124 }