[cstdstring] removal of Trim/TrimLeft/TrimRight
[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 #include "MusicInfoTagLoaderWav.h"
27 #ifdef HAS_MOD_PLAYER
28 #include "cores/ModPlayer.h"
29 #endif
30 #include "MusicInfoTagLoaderNSF.h"
31 #include "MusicInfoTagLoaderSPC.h"
32 #include "MusicInfoTagLoaderYM.h"
33 #include "MusicInfoTagLoaderDatabase.h"
34 #include "MusicInfoTagLoaderASAP.h"
35 #include "MusicInfoTagLoaderMidi.h"
36 #include "utils/StringUtils.h"
37 #include "utils/URIUtils.h"
38 #include "FileItem.h"
39
40 #ifdef HAS_ASAP_CODEC
41 #include "cores/paplayer/ASAPCodec.h"
42 #endif
43
44 using namespace MUSIC_INFO;
45
46 CMusicInfoTagLoaderFactory::CMusicInfoTagLoaderFactory()
47 {}
48
49 CMusicInfoTagLoaderFactory::~CMusicInfoTagLoaderFactory()
50 {}
51
52 IMusicInfoTagLoader* CMusicInfoTagLoaderFactory::CreateLoader(const CStdString& strFileName)
53 {
54   // dont try to read the tags for streams & shoutcast
55   CFileItem item(strFileName, false);
56   if (item.IsInternetStream())
57     return NULL;
58
59   if (item.IsMusicDb())
60     return new CMusicInfoTagLoaderDatabase();
61
62   CStdString strExtension = URIUtils::GetExtension(strFileName);
63   StringUtils::ToLower(strExtension);
64   StringUtils::TrimLeft(strExtension, ".");
65
66   if (strExtension.empty())
67     return NULL;
68
69   if (strExtension == "aac" ||
70       strExtension == "ape" || strExtension == "mac" ||
71       strExtension == "mp3" || 
72       strExtension == "wma" || 
73       strExtension == "flac" || 
74       strExtension == "m4a" || strExtension == "mp4" ||
75       strExtension == "mpc" || strExtension == "mpp" || strExtension == "mp+" ||
76       strExtension == "ogg" || strExtension == "oga" || strExtension == "oggstream" ||
77 #ifdef HAS_MOD_PLAYER
78       ModPlayer::IsSupportedFormat(strExtension) ||
79       strExtension == "mod" || strExtension == "nsf" || strExtension == "nsfstream" ||
80       strExtension == "s3m" || strExtension == "it" || strExtension == "xm" ||
81 #endif
82       strExtension == "wv")
83   {
84     CTagLoaderTagLib *pTagLoader = new CTagLoaderTagLib();
85     return (IMusicInfoTagLoader*)pTagLoader;
86   }
87 #ifdef HAS_DVD_DRIVE
88   else if (strExtension == "cdda")
89   {
90     CMusicInfoTagLoaderCDDA *pTagLoader = new CMusicInfoTagLoaderCDDA();
91     return (IMusicInfoTagLoader*)pTagLoader;
92   }
93 #endif
94   else if (strExtension == "shn")
95   {
96     CMusicInfoTagLoaderSHN *pTagLoader = new CMusicInfoTagLoaderSHN();
97     return (IMusicInfoTagLoader*)pTagLoader;
98   }
99   else if (strExtension == "wav")
100   {
101     CMusicInfoTagLoaderWAV *pTagLoader = new CMusicInfoTagLoaderWAV();
102     return (IMusicInfoTagLoader*)pTagLoader;
103   }
104   else if (strExtension == "spc")
105   {
106     CMusicInfoTagLoaderSPC *pTagLoader = new CMusicInfoTagLoaderSPC();
107     return (IMusicInfoTagLoader*)pTagLoader;
108   }
109   else if (strExtension == "ym")
110   {
111     CMusicInfoTagLoaderYM *pTagLoader = new CMusicInfoTagLoaderYM();
112     return (IMusicInfoTagLoader*)pTagLoader;
113   }
114 #ifdef HAS_ASAP_CODEC
115   else if (ASAPCodec::IsSupportedFormat(strExtension) || strExtension == "asapstream")
116   {
117     CMusicInfoTagLoaderASAP *pTagLoader = new CMusicInfoTagLoaderASAP();
118     return (IMusicInfoTagLoader*)pTagLoader;
119   }
120 #endif
121   else if ( TimidityCodec::IsSupportedFormat( strExtension ) )
122   {
123     CMusicInfoTagLoaderMidi * pTagLoader = new CMusicInfoTagLoaderMidi();
124     return (IMusicInfoTagLoader*)pTagLoader;
125   }
126
127   return NULL;
128 }