2 * Copyright (C) 2010-2011 Toni Gundogdu.
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #include <QScriptValueIterator>
19 #include <QScriptEngine>
33 : QObject(), _length (0)
36 Media::Media (const Media
& v
)
37 : QObject(), _length(0)
41 _pageURL
= v
._pageURL
;
50 Media::operator=(const Media
&)
58 Media::fromJSON (const QString
& data
, QString
& error
)
62 QScriptValue v
= e
.evaluate ("(" +data
+ ")");
64 if (e
.hasUncaughtException ())
66 error
= tr ("Uncaught exception at line %1: %2")
67 .arg (e
.uncaughtExceptionLineNumber ())
72 _title
= v
.property ("page_title").toString ().simplified ();
73 _pageURL
= v
.property ("page_url").toString ();
74 _id
= v
.property ("id").toString ();
75 _host
= v
.property ("host").toString ();
77 QScriptValueIterator
i (v
.property ("link"));
81 error
= tr("Expected at least one media link from quvi(1), got none.");
88 _length
= v
.property ("length_bytes").toVariant ().toLongLong ();
89 _ctype
= v
.property ("content_type").toString ();
90 _suffix
= v
.property ("file_suffix").toString ();
91 _link
= v
.property ("url").toString ();
107 Media::get (Detail d
) const
112 return QVariant (_link
);
114 return QVariant (_title
);
116 return QVariant (_pageURL
);
118 return QVariant (_id
);
120 return QVariant (_format
);
122 return QVariant (_length
);
124 return QVariant (_suffix
);
126 return QVariant (_ctype
);
128 return QVariant(_host
);
137 Media::set (Detail d
, const QString
& s
)
139 bool ignored
= false;
158 _length
= s
.toLongLong(&ignored
);
174 // MediaException: ctor.
176 MediaException::MediaException (const QString
& errmsg
)
180 // MediaException: what.
183 MediaException::what() const
188 // vim: set ts=2 sw=2 tw=72 expandtab: