Skip to content

Commit

Permalink
V2 Services API: Adds Dvr/UpdateRecordedMetadata
Browse files Browse the repository at this point in the history
Provides a way to change a subset of a recording's
metadata.

Always required:

    RecordedId          uint, selects the recording to update

Select one or more of these:

    AutoExpire          true/false
    BookmarkOffset      uint
    BookmarkOffsetType  position, duration or not even sent
                        (requires BookmarkOffset)
    Damaged             true/false
    Description         string
    Episode             uint
    Inetref             string
    OriginalAirDate     yyyy/mm/dd
    Preserve            true/false
    Season              uint
    Stars               0-10
    SubTitle            string
    Title               string
    Watched             true/false

Dvr/SetSavedBookmark and Dvr/UpdateWatchedStatus will log a
warning announcing that they're deprecated.
  • Loading branch information
Bill Meek committed Jul 16, 2022
1 parent 0496527 commit 66bb838
Show file tree
Hide file tree
Showing 2 changed files with 159 additions and 2 deletions.
142 changes: 142 additions & 0 deletions mythtv/programs/mythbackend/servicesv2/v2dvr.cpp
Expand Up @@ -740,6 +740,8 @@ bool V2Dvr::UpdateRecordedWatchedStatus ( int RecordedId,
const QDateTime &StartTime,
bool watched)
{
LOG(VB_GENERAL, LOG_WARNING, "Deprecated, use Dvr/UpdateRecordedMetadata.");

if ((RecordedId <= 0) &&
(chanid <= 0 || !StartTime.isValid()))
throw QString("Recorded ID or Channel ID and StartTime appears invalid.");
Expand Down Expand Up @@ -854,6 +856,8 @@ bool V2Dvr::SetSavedBookmark( int RecordedId,
const QString &offsettype,
long Offset )
{
LOG(VB_GENERAL, LOG_WARNING, "Deprecated, use Dvr/UpdateRecordedMetadata.");

if ((RecordedId <= 0) &&
(chanid <= 0 || !StartTime.isValid()))
throw QString("Recorded ID or Channel ID and StartTime appears invalid.");
Expand Down Expand Up @@ -2066,3 +2070,141 @@ int V2Dvr::ManageJobQueue( const QString &sAction,
return JobQueue::GetJobID(jobType, ri.GetChanID(),
ri.GetRecordingStartTime());
}

/////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////

bool V2Dvr::UpdateRecordedMetadata ( uint RecordedId,
bool AutoExpire,
long BookmarkOffset,
const QString BookmarkOffsetType,
bool Damaged,
const QString &Description,
uint Episode,
const QString &Inetref,
const QDate &OriginalAirDate,
bool Preserve,
uint Season,
uint Stars,
const QString &SubTitle,
const QString &Title,
bool Watched )

{
if (m_request->m_queries.size() < 2 || !HAS_PARAMv2("RecordedId"))
{
LOG(VB_GENERAL, LOG_ERR, "No RecordedId, or no parameters to change.");
return false;
}

auto pi = ProgramInfo(RecordedId);
auto ri = RecordingInfo(RecordedId);

if (!ri.GetChanID())
return false;

if (HAS_PARAMv2("AutoExpire"))
pi.SaveAutoExpire(AutoExpire ? kNormalAutoExpire :
kDisableAutoExpire, false);

if (HAS_PARAMv2("BookmarkOffset"))
{
uint64_t position;

if (BookmarkOffsetType.toLower() == "position")
{
if (!ri.QueryPositionKeyFrame(&position, BookmarkOffset, true))
return false;
}
else if (BookmarkOffsetType.toLower() == "duration")
{
if (!ri.QueryDurationKeyFrame(&position, BookmarkOffset, true))
return false;
}
else
position = BookmarkOffset;

ri.SaveBookmark(position);
}

if (HAS_PARAMv2("Damaged"))
pi.SaveVideoProperties(VID_DAMAGED, Damaged ? VID_DAMAGED : 0);

if (HAS_PARAMv2("Description") ||
HAS_PARAMv2("SubTitle") ||
HAS_PARAMv2("Title"))
{

QString tmp_description;
QString tmp_subtitle;
QString tmp_title;

if (HAS_PARAMv2("Description"))
tmp_description = Description;
else
tmp_description = ri.GetDescription();

if (HAS_PARAMv2("SubTitle"))
tmp_subtitle = SubTitle;
else
tmp_subtitle = ri.GetSubtitle();

if (HAS_PARAMv2("Title"))
tmp_title = Title;
else
tmp_title = ri.GetTitle();

ri.ApplyRecordRecTitleChange(tmp_title, tmp_subtitle, tmp_description);
}

if (HAS_PARAMv2("Episode") ||
HAS_PARAMv2("Season"))
{
int tmp_episode;
int tmp_season;

if (HAS_PARAMv2("Episode"))
tmp_episode = Episode;
else
tmp_episode = ri.GetEpisode();

if (HAS_PARAMv2("Season"))
tmp_season = Season;
else
tmp_season = ri.GetSeason();

pi.SaveSeasonEpisode(tmp_season, tmp_episode);
}

if (HAS_PARAMv2("Inetref"))
pi.SaveInetRef(Inetref);

if (HAS_PARAMv2("OriginalAirDate"))
{
if (!OriginalAirDate.isValid())
{
LOG(VB_GENERAL, LOG_ERR, "Need valid OriginalAirDate yyyy-mm-dd.");
return false;
}
ri.ApplyOriginalAirDateChange(OriginalAirDate);
}

if (HAS_PARAMv2("Preserve"))
pi.SavePreserve(Preserve);

if (HAS_PARAMv2("Stars"))
{
if (Stars > 10)
{
LOG(VB_GENERAL, LOG_ERR, "Recording stars can be 0 to 10.");
return false;
}
ri.ApplyStarsChange(Stars * 0.1);
}

if (HAS_PARAMv2("Watched"))
pi.SaveWatched(Watched);

return true;
}
19 changes: 17 additions & 2 deletions mythtv/programs/mythbackend/servicesv2/v2dvr.h
Expand Up @@ -42,7 +42,7 @@
class V2Dvr : public MythHTTPService
{
Q_OBJECT
Q_CLASSINFO("Version", "7.0")
Q_CLASSINFO("Version", "7.1")
Q_CLASSINFO("AddRecordedCredits", "methods=POST;name=bool")
Q_CLASSINFO("AddRecordedProgram", "methods=POST;name=int")
Q_CLASSINFO("RemoveRecorded", "methods=POST;name=bool")
Expand Down Expand Up @@ -75,6 +75,7 @@ class V2Dvr : public MythHTTPService
Q_CLASSINFO("DupInToString", "methods=GET,POST,HEAD;name=String")
Q_CLASSINFO("DupInToDescription", "methods=GET,POST,HEAD;name=String")
Q_CLASSINFO("ManageJobQueue", "methods=POST;name=int")
Q_CLASSINFO("UpdateRecordedMetadata", "methods=POST")

public:
V2Dvr();
Expand Down Expand Up @@ -364,7 +365,21 @@ class V2Dvr : public MythHTTPService
QString RemoteHost,
QString JobArgs );


bool UpdateRecordedMetadata ( uint RecordedId,
bool AutoExpire,
long BookmarkOffset,
const QString BookmarkOffsetType,
bool Damaged,
const QString &Description,
uint Episode,
const QString &Inetref,
const QDate &OriginalAirDate,
bool Preserve,
uint Season,
uint Stars,
const QString &SubTitle,
const QString &Title,
bool Watched );

private:
Q_DISABLE_COPY(V2Dvr)
Expand Down

0 comments on commit 66bb838

Please sign in to comment.