2 * Copyright (C) 2010 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/>.
21 #include <QScriptEngine>
22 #include <QScriptValueIterator>
30 : QObject(), _length (0)
33 Video::Video (const Video
& v
)
34 : QObject(), _length(0)
38 _pageURL
= v
._pageURL
;
47 Video::operator=(const Video
&)
55 Video::fromJSON (const QString
& data
, QString
& error
)
59 QScriptValue v
= e
.evaluate ("(" +data
+ ")");
61 if (e
.hasUncaughtException ())
63 error
= tr ("Uncaught exception at line %1: %2")
64 .arg (e
.uncaughtExceptionLineNumber ())
69 _title
= v
.property ("page_title").toString ().simplified ();
70 _pageURL
= v
.property ("page_url").toString ();
71 _id
= v
.property ("id").toString ();
72 _host
= v
.property ("host").toString ();
74 QScriptValueIterator
i (v
.property ("link"));
78 error
= tr("Expected at least one video link from quvi(1), got none.");
85 _length
= v
.property ("length_bytes").toVariant ().toLongLong ();
86 _ctype
= v
.property ("content_type").toString ();
87 _suffix
= v
.property ("file_suffix").toString ();
88 _link
= v
.property ("url").toString ();
104 Video::get (Detail d
) const
109 return QVariant (_link
);
111 return QVariant (_title
);
113 return QVariant (_pageURL
);
115 return QVariant (_id
);
117 return QVariant (_format
);
119 return QVariant (_length
);
121 return QVariant (_suffix
);
123 return QVariant (_ctype
);
125 return QVariant(_host
);
134 Video::set (Detail d
, const QString
& s
)
136 bool ignored
= false;
155 _length
= s
.toLongLong(&ignored
);
171 // VideoException: ctor.
173 VideoException::VideoException (const QString
& errmsg
)
177 // VideoException: what.
180 VideoException::what() const
185 // vim: set ts=2 sw=2 tw=72 expandtab: