Update change log and spec for wrt-plugins-tizen_0.4.57
[platform/framework/web/wrt-plugins-tizen.git] / src / Content / AudioLyricsUtil.cpp
1 //
2 // Tizen Web Device API
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 #include "AudioLyricsUtil.h"
19 #include <dpl/singleton_impl.h>
20 #include <metadata_extractor.h>
21 #include <Logger.h>
22
23
24  
25 IMPLEMENT_SINGLETON(DeviceAPI::Content::MediaLyricsUtil)
26
27 namespace DeviceAPI {
28 namespace Content {
29
30 metadata_extractor_h m_extractor = NULL;
31 MediaLyricsUtil::MediaLyricsUtil()
32 {
33         if ( METADATA_EXTRACTOR_ERROR_NONE != metadata_extractor_create(&m_extractor))
34         {
35                 LoggerD("MetaData Extractor create Fail...");
36         }
37 }
38
39 MediaLyricsUtil::~MediaLyricsUtil()
40 {
41         if ( m_extractor && METADATA_EXTRACTOR_ERROR_NONE != metadata_extractor_destroy(m_extractor))
42         {
43                 LoggerD("Metadata extractor destory Fail...");
44         }
45 }
46
47 MediacontentLyricsPtr MediaLyricsUtil::fetchLyrics(string filepath)
48 {
49         MediacontentLyricsPtr result;
50         //MediacontentLyricsPtr lyricsPtr(new MediacontentLyrics());
51         //set path.
52
53         if (m_extractor)
54         {
55                 if ( METADATA_EXTRACTOR_ERROR_NONE == metadata_extractor_set_path(m_extractor, filepath.c_str()) )
56                 {                               
57                         char* strSyncTextNum=NULL;
58                         metadata_extractor_attr_e attr = METADATA_SYNCLYRICS_NUM;
59                         if ( METADATA_EXTRACTOR_ERROR_NONE == metadata_extractor_get_metadata(m_extractor, attr, &strSyncTextNum) 
60                                 && strSyncTextNum )
61                         {
62                                 int nSyncTextNum = 0;
63                                 istringstream(strSyncTextNum) >> nSyncTextNum;
64                                 free(strSyncTextNum);
65                                 strSyncTextNum = NULL;
66                                 if ( nSyncTextNum > 0)
67                                 {
68                                 MediacontentLyricsPtr lyricsPtr(new MediacontentLyrics());
69                                 lyricsPtr->setMediaLyricsType("SYNCHRONIZED");
70                                 for(int i=0; i < nSyncTextNum; i++)
71                                 {
72                                     unsigned long time_info = 0;
73                                     char * lyrics = NULL;
74                                     if ( METADATA_EXTRACTOR_ERROR_NONE == 
75                                     metadata_extractor_get_synclyrics(m_extractor, i, &time_info, &lyrics))
76                                     {
77                                         lyricsPtr->addMediaLyricsTimeStamp(time_info);
78                                         if(lyrics != NULL)
79                                         {
80                                             lyricsPtr->addMediaLyricsText(lyrics);
81                                             //LoggerI( "[" << time_info << "]"<< "lyrics : " << lyrics);
82                                         }
83                                         else
84                                         {
85                                             lyricsPtr->addMediaLyricsText("");
86                                         }
87                                     }
88                                     if(lyrics != NULL)
89                                     {
90                                         free(lyrics);
91                                     }
92                                 }
93                                 result = lyricsPtr;
94                                 }
95                                 else
96                                 {       
97                                         char* unSyncText = NULL;
98                                         attr = METADATA_UNSYNCLYRICS;
99
100                                         if ( METADATA_EXTRACTOR_ERROR_NONE == metadata_extractor_get_metadata(m_extractor, attr, &unSyncText) )
101                                         {
102                                                 if (unSyncText)
103                                                 {
104                                                         MediacontentLyricsPtr lyricsPtr(new MediacontentLyrics());
105                                                         lyricsPtr->setMediaLyricsType("UNSYNCHRONIZED");
106                                                         lyricsPtr->addMediaLyricsTimeStamp(0);
107                                                         lyricsPtr->addMediaLyricsText(unSyncText);
108                                                         
109                                                         result = lyricsPtr;
110                                                         
111                                                         free(unSyncText);
112                                                         unSyncText = NULL;
113                                                 }
114                                         }
115                                         
116                                 }
117                                 
118                         }
119                         else
120                         {       
121                                 LoggerD("extractor Error!!!");
122                         }
123
124                 }
125
126         }
127         else
128         {
129                 LoggerD(" extractor is invaild ");
130         }
131         
132         return result;
133 }
134
135 }
136 }
137
138   
139
140
141