Added bitrate(), duration() and framerate() to Easy::Attachment
This commit is contained in:
parent
67da294d1d
commit
168f55a791
|
@ -1,6 +1,6 @@
|
|||
cmake_minimum_required (VERSION 3.7)
|
||||
project (mastodon-cpp
|
||||
VERSION 0.7.17
|
||||
VERSION 0.7.18
|
||||
LANGUAGES CXX
|
||||
)
|
||||
|
||||
|
|
|
@ -143,7 +143,7 @@ Run `make package` from the build directory to generate a tar.gz archive.
|
|||
|
||||
# Status of implementation
|
||||
|
||||
Feature complete as of Mastodon 2.2.0
|
||||
Feature complete as of Mastodon 2.3.0
|
||||
|
||||
* [x] GET /api/v1/accounts/:id
|
||||
* [x] GET /api/v1/accounts/verify_credentials
|
||||
|
|
|
@ -39,27 +39,60 @@ const double Attachment::aspect_small() const
|
|||
return get_double("meta.small.aspect");
|
||||
}
|
||||
|
||||
const uint_fast64_t Attachment::bitrate() const
|
||||
{
|
||||
return get_uint64("meta.original.bitrate");
|
||||
}
|
||||
|
||||
const string Attachment::description() const
|
||||
{
|
||||
return get_string("description");
|
||||
}
|
||||
|
||||
const std::array<uint_fast64_t, 2> Attachment::focus() const
|
||||
const std::chrono::duration<double> Attachment::duration() const
|
||||
{
|
||||
const double sec = get_double("meta.original.duration");
|
||||
|
||||
if (sec > 0.0)
|
||||
{
|
||||
return std::chrono::duration<double>(sec);
|
||||
}
|
||||
}
|
||||
|
||||
const std::array<double, 2> Attachment::focus() const
|
||||
{
|
||||
const Json::Value x = get("meta.focus.x");
|
||||
const Json::Value y = get("meta.focus.y");
|
||||
if (x.isUInt64() && y.isUInt64())
|
||||
if (x.isDouble() && y.isDouble())
|
||||
{
|
||||
return
|
||||
{{
|
||||
x.asUInt64(),
|
||||
y.asUInt64()
|
||||
x.asDouble(),
|
||||
y.asDouble()
|
||||
}};
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
const double Attachment::framerate() const
|
||||
{
|
||||
string strframes = get_string("meta.original.frame_rate");
|
||||
|
||||
if (!strframes.empty())
|
||||
{
|
||||
std::size_t pos = strframes.find('/');
|
||||
if (pos != std::string::npos)
|
||||
{
|
||||
std::uint_fast16_t frames = std::stoul(strframes.substr(0, pos));
|
||||
std::uint_fast16_t divider = std::stoul(strframes.substr(pos + 1));
|
||||
|
||||
return frames / divider;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
const uint_fast64_t Attachment::height() const
|
||||
{
|
||||
return get_uint64("meta.original.height");
|
||||
|
|
|
@ -32,7 +32,6 @@
|
|||
#endif
|
||||
|
||||
using std::string;
|
||||
using std::uint16_t;
|
||||
using std::uint_fast64_t;
|
||||
|
||||
namespace Mastodon
|
||||
|
@ -65,16 +64,29 @@ namespace Mastodon
|
|||
*/
|
||||
const double aspect_small() const;
|
||||
|
||||
/*!
|
||||
* @brief Returns the bitrate of a video
|
||||
*/
|
||||
const uint_fast64_t bitrate() const;
|
||||
/*!
|
||||
* @brief Returns the image description
|
||||
*/
|
||||
const string description() const;
|
||||
|
||||
/*!
|
||||
* @brief Returns the duration of a video in seconds
|
||||
*/
|
||||
const std::chrono::duration<double> duration() const;
|
||||
|
||||
/*!
|
||||
* @brief Returns the focus point (x, y)
|
||||
*/
|
||||
// TODO: find attachment with focus
|
||||
const std::array<uint_fast64_t, 2> focus() const;
|
||||
const std::array<double, 2> focus() const;
|
||||
|
||||
/*!
|
||||
* @brief Returns the framerate of a video in frames per second
|
||||
*/
|
||||
const double framerate() const;
|
||||
|
||||
/*!
|
||||
* @brief Returns the height of the original image
|
||||
|
@ -137,10 +149,6 @@ namespace Mastodon
|
|||
const uint_fast64_t width_small() const;
|
||||
|
||||
|
||||
// TODO: find an attachment with framerate, duration or bitrate set
|
||||
// const uint16_t framerate() const;
|
||||
// const std::chrono::seconds duration() const;
|
||||
// const uint_fast64_t bitrate() const;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Reference in New Issue