Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
VideoLAN
medialibrary
Commits
73433d60
Commit
73433d60
authored
Jan 04, 2016
by
Hugo Beauzée-Luyssen
Browse files
Media: Add progress & rating
parent
f879cc72
Changes
4
Hide whitespace changes
Inline
Side-by-side
include/IMedia.h
View file @
73433d60
...
...
@@ -55,6 +55,19 @@ class IMedia
virtual
int
playCount
()
const
=
0
;
virtual
void
increasePlayCount
()
=
0
;
virtual
const
std
::
string
&
mrl
()
const
=
0
;
///
/// \brief progress Returns the progress, in the [0;1] range
///
virtual
float
progress
()
const
=
0
;
virtual
void
setProgress
(
float
progress
)
=
0
;
///
/// \brief rating The media rating, or -1 if unset.
/// It is up to the application to determine the values it wishes to use.
/// No value is enforced, and any positive value (less or equal to INT32_MAX)
/// will be accepted.
///
virtual
int
rating
()
const
=
0
;
virtual
void
setRating
(
int
rating
)
=
0
;
virtual
bool
addLabel
(
LabelPtr
label
)
=
0
;
virtual
bool
removeLabel
(
LabelPtr
label
)
=
0
;
virtual
MoviePtr
movie
()
=
0
;
...
...
src/Media.cpp
View file @
73433d60
...
...
@@ -52,6 +52,8 @@ Media::Media( DBConnection dbConnection, sqlite::Row& row )
>>
m_type
>>
m_duration
>>
m_playCount
>>
m_progress
>>
m_rating
>>
m_showEpisodeId
>>
m_mrl
>>
m_artist
...
...
@@ -71,6 +73,8 @@ Media::Media( const fs::IFile* file, unsigned int folderId, const std::string& t
,
m_type
(
type
)
,
m_duration
(
-
1
)
,
m_playCount
(
0
)
,
m_progress
(
.0
f
)
,
m_rating
(
-
1
)
,
m_showEpisodeId
(
0
)
,
m_mrl
(
isRemovable
==
true
?
file
->
name
()
:
file
->
fullPath
()
)
,
m_movieId
(
0
)
...
...
@@ -179,6 +183,32 @@ void Media::increasePlayCount()
m_changed
=
true
;
}
float
Media
::
progress
()
const
{
return
m_progress
;
}
void
Media
::
setProgress
(
float
progress
)
{
if
(
progress
==
m_progress
||
progress
<
0
||
progress
>
1.0
)
return
;
m_progress
=
progress
;
m_changed
=
true
;
}
int
Media
::
rating
()
const
{
return
m_rating
;
}
void
Media
::
setRating
(
int
rating
)
{
if
(
m_rating
==
rating
)
return
;
m_rating
=
rating
;
m_changed
=
true
;
}
const
std
::
string
&
Media
::
mrl
()
const
{
if
(
m_isRemovable
==
false
)
...
...
@@ -259,12 +289,13 @@ void Media::setSnapshot( const std::string& snapshot )
bool
Media
::
save
()
{
static
const
std
::
string
req
=
"UPDATE "
+
policy
::
MediaTable
::
Name
+
" SET "
"type = ?, duration = ?, play_count = ?, show_episode_id =
?, artist =
?,"
"movie_id = ?, last_modification_date = ?, snapshot = ?, parsed = ?,
title = ?
"
"WHERE id_media = ?"
;
"type = ?, duration = ?, play_count = ?,
progress = ?, rating = ?,
show_episode_id = ?,"
"
artist = ?,
movie_id = ?, last_modification_date = ?, snapshot = ?, parsed = ?,"
"
title = ?
WHERE id_media = ?"
;
if
(
m_changed
==
false
)
return
true
;
if
(
sqlite
::
Tools
::
executeUpdate
(
m_dbConnection
,
req
,
m_type
,
m_duration
,
m_playCount
,
m_progress
,
m_rating
,
sqlite
::
ForeignKey
{
m_showEpisodeId
},
m_artist
,
sqlite
::
ForeignKey
{
m_movieId
},
m_lastModificationDate
,
m_snapshot
,
m_isParsed
,
m_title
,
m_id
)
==
false
)
...
...
@@ -331,6 +362,8 @@ bool Media::createTable( DBConnection connection )
"type INTEGER,"
"duration INTEGER DEFAULT -1,"
"play_count UNSIGNED INTEGER,"
"progress REAL,"
"rating INTEGER DEFAULT -1,"
"show_episode_id UNSIGNED INTEGER,"
"mrl TEXT,"
"artist TEXT,"
...
...
src/Media.h
View file @
73433d60
...
...
@@ -77,6 +77,10 @@ class Media : public IMedia, public DatabaseHelpers<Media, policy::MediaTable>
virtual
std
::
vector
<
LabelPtr
>
labels
()
override
;
virtual
int
playCount
()
const
override
;
virtual
void
increasePlayCount
()
override
;
virtual
float
progress
()
const
override
;
virtual
void
setProgress
(
float
progress
)
override
;
virtual
int
rating
()
const
override
;
virtual
void
setRating
(
int
rating
)
override
;
virtual
const
std
::
string
&
mrl
()
const
override
;
virtual
MoviePtr
movie
()
override
;
void
setMovie
(
MoviePtr
movie
);
...
...
@@ -107,6 +111,8 @@ class Media : public IMedia, public DatabaseHelpers<Media, policy::MediaTable>
Type
m_type
;
int64_t
m_duration
;
unsigned
int
m_playCount
;
float
m_progress
;
int
m_rating
;
unsigned
int
m_showEpisodeId
;
std
::
string
m_mrl
;
std
::
string
m_artist
;
...
...
test/unittest/MediaTests.cpp
View file @
73433d60
...
...
@@ -157,3 +157,34 @@ TEST_F( Medias, PlayCount )
f
=
std
::
static_pointer_cast
<
Media
>
(
ml
->
media
(
f
->
id
()
)
);
ASSERT_EQ
(
1
,
f
->
playCount
()
);
}
TEST_F
(
Medias
,
Progress
)
{
auto
f
=
ml
->
addFile
(
"media.avi"
);
ASSERT_EQ
(
.0
f
,
f
->
progress
()
);
f
->
setProgress
(
123.0
f
);
// Check that a non-sensical value is ignored
ASSERT_EQ
(
.0
f
,
f
->
progress
()
);
f
->
setProgress
(
0.666
f
);
ASSERT_EQ
(
.666
f
,
f
->
progress
()
);
f
->
save
();
Reload
();
f
=
ml
->
media
(
f
->
id
()
);
ASSERT_EQ
(
.666
f
,
f
->
progress
()
);
}
TEST_F
(
Medias
,
Rating
)
{
auto
f
=
ml
->
addFile
(
"media.avi"
);
ASSERT_EQ
(
-
1
,
f
->
rating
()
);
f
->
setRating
(
12345
);
f
->
save
();
ASSERT_EQ
(
12345
,
f
->
rating
()
);
Reload
();
f
=
ml
->
media
(
f
->
id
()
);
ASSERT_EQ
(
12345
,
f
->
rating
()
);
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment