aboutsummaryrefslogtreecommitdiff
path: root/src/plugins/Input/ffmpeg/decoderffmpegfactory.cpp
blob: 3a69a814437c32cc13e24602480fc71f4aa5eac5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include <QtGui>

extern "C"{
#include <ffmpeg/avformat.h>
#include <ffmpeg/avcodec.h>
}

#include "detailsdialog.h"
#include "decoder_ffmpeg.h"
#include "decoderffmpegfactory.h"


// DecoderFFmpegFactory

bool DecoderFFmpegFactory::supports(const QString &source) const
{

    return (source.right(4).toLower() == ".wma");
}

bool DecoderFFmpegFactory::canDecode(QIODevice *) const
{
    return FALSE;
}

const DecoderProperties DecoderFFmpegFactory::properties() const
{
    DecoderProperties properties;
    properties.name = tr("FFMPEG Plugin");
    properties.filter = "*.wma";
    properties.description = tr("WMA Files");
    //properties.contentType = "";
    properties.hasAbout = TRUE;
    properties.hasSettings = FALSE;
    return properties;
}

Decoder *DecoderFFmpegFactory::create(QObject *parent, QIODevice *input,
                                      Output *output)
{
    return new DecoderFFmpeg(parent, this, input, output);
}

FileTag *DecoderFFmpegFactory::createTag(const QString &source)
{
    FileTag *ftag = new FileTag();
    avcodec_init();
    avcodec_register_all();
    av_register_all();
    AVFormatContext *in;

    if (av_open_input_file(&in, source.toLocal8Bit(), NULL,0, NULL) < 0)
        return ftag;
    av_find_stream_info(in);
    ftag->setValue(FileTag::ALBUM, QString::fromUtf8(in->album).trimmed());
    ftag->setValue(FileTag::ARTIST, QString::fromUtf8(in->author).trimmed());
    ftag->setValue(FileTag::COMMENT, QString::fromUtf8(in->comment).trimmed());
    ftag->setValue(FileTag::GENRE, QString::fromUtf8(in->genre).trimmed());
    ftag->setValue(FileTag::TITLE, QString::fromUtf8(in->title).trimmed());
    ftag->setValue(FileTag::YEAR, in->year);
    ftag->setValue(FileTag::TRACK, in->track);
    ftag->setValue(FileTag::LENGTH ,int(in->duration/AV_TIME_BASE));
    av_close_input_file(in);
    return ftag;
}

QObject* DecoderFFmpegFactory::showDetails(QWidget *parent, const QString &path)
{
    DetailsDialog *d = new DetailsDialog(parent, path);
    d -> show();
    return d;
}

void DecoderFFmpegFactory::showSettings(QWidget *)
{}

void DecoderFFmpegFactory::showAbout(QWidget *parent)
{
    QMessageBox::about (parent, tr("About FFmpeg Audio Plugin"),
                        tr("Qmmp FFmpeg Audio Plugin")+"\n"+
                        tr("Suppored formats: WMA")+"\n"+
                        tr("Writen by: Ilya Kotov <forkotov02@hotmail.ru>"));
}

QTranslator *DecoderFFmpegFactory::createTranslator(QObject *parent)
{
    QTranslator *translator = new QTranslator(parent);
    QString locale = QLocale::system().name();
    translator->load(QString(":/ffmpeg_plugin_") + locale);
    return translator;
}

Q_EXPORT_PLUGIN(DecoderFFmpegFactory)