00001 #include <stdio.h>
00002 #include <stdlib.h>
00003 #include <iostream>
00004 #include <sys/stat.h>
00005 using namespace std;
00006
00007 #include "metaioavfcomment.h"
00008 #include "metadata.h"
00009
00010 extern "C" {
00011 #include <mythtv/ffmpeg/avformat.h>
00012 #include <mythtv/ffmpeg/avcodec.h>
00013 }
00014
00015
00016 MetaIOAVFComment::MetaIOAVFComment(void)
00017 : MetaIO(".wma")
00018 {
00019 av_register_all();
00020 }
00021
00022
00023 MetaIOAVFComment::~MetaIOAVFComment(void)
00024 {
00025 }
00026
00027
00028
00038 bool MetaIOAVFComment::write(Metadata* mdata, bool exclusive)
00039 {
00040
00041 mdata = mdata;
00042 exclusive = exclusive;
00043 return false;
00044 }
00045
00046
00047
00054 Metadata* MetaIOAVFComment::read(QString filename)
00055 {
00056 QString artist = "", compilation_artist = "", album = "", title = "", genre = "";
00057 int year = 0, tracknum = 0, length = 0;
00058
00059 AVFormatContext* p_context = NULL;
00060 AVFormatParameters* p_params = NULL;
00061 AVInputFormat* p_inputformat = NULL;
00062
00063 if (av_open_input_file(&p_context, filename.local8Bit(),
00064 p_inputformat, 0, p_params) < 0
00065 && av_open_input_file(&p_context, filename.ascii(),
00066 p_inputformat, 0, p_params) < 0)
00067 return NULL;
00068
00069 if (av_find_stream_info(p_context) < 0)
00070 return NULL;
00071
00072
00073 title += (char *)p_context->title;
00074 if (title.isEmpty())
00075 {
00076 readFromFilename(filename, artist, album, title, genre, tracknum);
00077 }
00078 else
00079 {
00080 artist += (char *)p_context->author;
00081
00082 album += (char *)p_context->album;
00083 genre += (char *)p_context->genre;
00084 year = p_context->year;
00085 tracknum = p_context->track;
00086 }
00087
00088 length = getTrackLength(p_context);
00089
00090 Metadata *retdata = new Metadata(filename, artist, compilation_artist, album,
00091 title, genre, year, tracknum, length);
00092
00093 retdata->determineIfCompilation();
00094
00095 av_close_input_file(p_context);
00096
00097 return retdata;
00098 }
00099
00100
00101
00108 int MetaIOAVFComment::getTrackLength(QString filename)
00109 {
00110 AVFormatContext* p_context = NULL;
00111 AVFormatParameters* p_params = NULL;
00112 AVInputFormat* p_inputformat = NULL;
00113
00114
00115 if (av_open_input_file(&p_context, filename.local8Bit(),
00116 p_inputformat, 0, p_params) < 0
00117 && av_open_input_file(&p_context, filename.ascii(),
00118 p_inputformat, 0, p_params) < 0)
00119 return 0;
00120
00121 if (av_find_stream_info(p_context) < 0)
00122 return 0;
00123
00124 int rv = getTrackLength(p_context);
00125
00126 av_close_input_file(p_context);
00127
00128 return rv;
00129 }
00130
00131
00132
00139 int MetaIOAVFComment::getTrackLength(AVFormatContext* pContext)
00140 {
00141 if (!pContext)
00142 return 0;
00143
00144 av_estimate_timings(pContext, 0);
00145
00146 return (pContext->duration / AV_TIME_BASE) * 1000;
00147 }