Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Open sidebar
VideoLAN
medialibrary
Commits
dc8f288d
Commit
dc8f288d
authored
May 24, 2014
by
Hugo Beauzée-Luyssen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add basic Show functionnalities
parent
87f40f8a
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
218 additions
and
33 deletions
+218
-33
include/IMediaLibrary.h
include/IMediaLibrary.h
+4
-0
include/IShow.h
include/IShow.h
+10
-6
src/Album.h
src/Album.h
+1
-1
src/MediaLibrary.cpp
src/MediaLibrary.cpp
+12
-0
src/MediaLibrary.h
src/MediaLibrary.h
+3
-0
src/Show.cpp
src/Show.cpp
+77
-18
src/Show.h
src/Show.h
+16
-8
test/CMakeLists.txt
test/CMakeLists.txt
+1
-0
test/Shows.cpp
test/Shows.cpp
+94
-0
No files found.
include/IMediaLibrary.h
View file @
dc8f288d
...
...
@@ -10,11 +10,13 @@ class IAlbumTrack;
class
IFile
;
class
ILabel
;
class
IMetadataService
;
class
IShow
;
typedef
std
::
shared_ptr
<
IFile
>
FilePtr
;
typedef
std
::
shared_ptr
<
ILabel
>
LabelPtr
;
typedef
std
::
shared_ptr
<
IAlbum
>
AlbumPtr
;
typedef
std
::
shared_ptr
<
IAlbumTrack
>
AlbumTrackPtr
;
typedef
std
::
shared_ptr
<
IShow
>
ShowPtr
;
class
IMediaLibrary
{
...
...
@@ -31,6 +33,8 @@ class IMediaLibrary
virtual
bool
files
(
std
::
vector
<
FilePtr
>&
res
)
=
0
;
virtual
AlbumPtr
album
(
const
std
::
string
&
id3Tag
)
=
0
;
virtual
AlbumPtr
createAlbum
(
const
std
::
string
&
id3Tag
)
=
0
;
virtual
ShowPtr
show
(
const
std
::
string
&
name
)
=
0
;
virtual
ShowPtr
createShow
(
const
std
::
string
&
name
)
=
0
;
virtual
void
addMetadataService
(
IMetadataService
*
service
)
=
0
;
};
...
...
include/IShow.h
View file @
dc8f288d
...
...
@@ -7,12 +7,16 @@ class IShow
{
public:
virtual
~
IShow
()
{}
virtual
const
std
::
string
&
name
()
=
0
;
virtual
unsigned
int
releaseYear
()
=
0
;
virtual
const
std
::
string
&
shortSummary
()
=
0
;
virtual
const
std
::
string
&
artworkUrl
()
=
0
;
virtual
time_t
lastSyncDate
()
=
0
;
virtual
unsigned
int
id
()
const
=
0
;
virtual
const
std
::
string
&
name
()
const
=
0
;
virtual
time_t
releaseDate
()
const
=
0
;
virtual
bool
setReleaseDate
(
time_t
date
)
=
0
;
virtual
const
std
::
string
&
shortSummary
()
const
=
0
;
virtual
bool
setShortSummary
(
const
std
::
string
&
summary
)
=
0
;
virtual
const
std
::
string
&
artworkUrl
()
const
=
0
;
virtual
bool
setArtworkUrl
(
const
std
::
string
&
artworkUrl
)
=
0
;
virtual
const
std
::
string
&
tvdbId
()
=
0
;
virtual
bool
setTvdbId
(
const
std
::
string
&
id
)
=
0
;
};
#endif // ISHOW_H
src/Album.h
View file @
dc8f288d
...
...
@@ -29,7 +29,7 @@ class Album : public IAlbum, public Cache<Album, IAlbum, policy::AlbumTable>
Album
(
sqlite3
*
dbConnection
,
sqlite3_stmt
*
stmt
);
Album
(
const
std
::
string
&
id3tag
);
unsigned
int
id
()
const
;
virtual
unsigned
int
id
()
const
;
virtual
const
std
::
string
&
name
()
const
;
virtual
bool
setName
(
const
std
::
string
&
name
);
virtual
time_t
releaseDate
()
const
;
...
...
src/MediaLibrary.cpp
View file @
dc8f288d
...
...
@@ -95,6 +95,18 @@ AlbumPtr MediaLibrary::createAlbum( const std::string& id3Tag )
return
Album
::
create
(
m_dbConnection
,
id3Tag
);
}
ShowPtr
MediaLibrary
::
show
(
const
std
::
string
&
name
)
{
static
const
std
::
string
req
=
"SELECT * FROM "
+
policy
::
ShowTable
::
Name
+
" WHERE name = ?"
;
return
SqliteTools
::
fetchOne
<
Show
>
(
m_dbConnection
,
req
,
name
);
}
ShowPtr
MediaLibrary
::
createShow
(
const
std
::
string
&
name
)
{
return
Show
::
create
(
m_dbConnection
,
name
);
}
void
MediaLibrary
::
addMetadataService
(
IMetadataService
*
service
)
{
typedef
std
::
unique_ptr
<
IMetadataService
>
MdsPtr
;
...
...
src/MediaLibrary.h
View file @
dc8f288d
...
...
@@ -25,6 +25,9 @@ class MediaLibrary : public IMediaLibrary
virtual
AlbumPtr
album
(
const
std
::
string
&
id3Tag
);
virtual
AlbumPtr
createAlbum
(
const
std
::
string
&
id3Tag
);
virtual
ShowPtr
show
(
const
std
::
string
&
name
);
virtual
ShowPtr
createShow
(
const
std
::
string
&
name
);
virtual
void
addMetadataService
(
IMetadataService
*
service
);
private:
sqlite3
*
m_dbConnection
;
...
...
src/Show.cpp
View file @
dc8f288d
...
...
@@ -8,43 +8,79 @@ unsigned int Show::* const policy::ShowTable::PrimaryKey = &Show::m_id;
Show
::
Show
(
sqlite3
*
dbConnection
,
sqlite3_stmt
*
stmt
)
:
m_dbConnection
(
dbConnection
)
{
m_id
=
sqlite3_column_int
(
stmt
,
0
);
m_name
=
(
const
char
*
)
sqlite3_column_text
(
stmt
,
1
);
m_release
Year
=
sqlite3_column_int
(
stmt
,
2
);
m_shortSummary
=
(
const
char
*
)
sqlite3_column_text
(
stmt
,
3
);
m_artworkUrl
=
(
const
char
*
)
sqlite3_column_text
(
stmt
,
4
);
m_lastSyncDate
=
sqlite3_column_int
(
stmt
,
5
);
m_tvdbId
=
(
const
char
*
)
sqlite3_column_text
(
stmt
,
6
);
m_id
=
Traits
<
unsigned
int
>::
Load
(
stmt
,
0
);
m_name
=
Traits
<
std
::
string
>::
Load
(
stmt
,
1
);
m_release
Date
=
Traits
<
unsigned
int
>::
Load
(
stmt
,
2
);
m_shortSummary
=
Traits
<
std
::
string
>::
Load
(
stmt
,
3
);
m_artworkUrl
=
Traits
<
std
::
string
>::
Load
(
stmt
,
4
);
m_lastSyncDate
=
Traits
<
unsigned
int
>::
Load
(
stmt
,
5
);
m_tvdbId
=
Traits
<
std
::
string
>::
Load
(
stmt
,
6
);
}
Show
::
Show
(
sqlite3
*
dbConnection
)
:
m_dbConnection
(
dbConnection
)
,
m_id
(
0
)
Show
::
Show
(
const
std
::
string
&
name
)
:
m_id
(
0
)
,
m_name
(
name
)
,
m_releaseDate
(
0
)
,
m_lastSyncDate
(
0
)
{
}
const
std
::
string
&
Show
::
name
()
unsigned
int
Show
::
id
()
const
{
return
m_id
;
}
const
std
::
string
&
Show
::
name
()
const
{
return
m_name
;
}
unsigned
in
t
Show
::
release
Year
()
time_
t
Show
::
release
Date
()
const
{
return
m_release
Year
;
return
m_release
Date
;
}
const
std
::
string
&
Show
::
shortSummary
()
bool
Show
::
setReleaseDate
(
time_t
date
)
{
static
const
std
::
string
&
req
=
"UPDATE "
+
policy
::
ShowTable
::
Name
+
" SET release_date = ? WHERE id_show = ?"
;
if
(
SqliteTools
::
executeUpdate
(
m_dbConnection
,
req
,
date
,
m_id
)
==
false
)
return
false
;
m_releaseDate
=
date
;
return
true
;
}
const
std
::
string
&
Show
::
shortSummary
()
const
{
return
m_shortSummary
;
}
const
std
::
string
&
Show
::
artworkUrl
()
bool
Show
::
setShortSummary
(
const
std
::
string
&
summary
)
{
static
const
std
::
string
&
req
=
"UPDATE "
+
policy
::
ShowTable
::
Name
+
" SET short_summary = ? WHERE id_show = ?"
;
if
(
SqliteTools
::
executeUpdate
(
m_dbConnection
,
req
,
summary
,
m_id
)
==
false
)
return
false
;
m_shortSummary
=
summary
;
return
true
;
}
const
std
::
string
&
Show
::
artworkUrl
()
const
{
return
m_artworkUrl
;
}
bool
Show
::
setArtworkUrl
(
const
std
::
string
&
artworkUrl
)
{
static
const
std
::
string
&
req
=
"UPDATE "
+
policy
::
ShowTable
::
Name
+
" SET artwork_url = ? WHERE id_show = ?"
;
if
(
SqliteTools
::
executeUpdate
(
m_dbConnection
,
req
,
artworkUrl
,
m_id
)
==
false
)
return
false
;
m_artworkUrl
=
artworkUrl
;
return
true
;
}
time_t
Show
::
lastSyncDate
()
time_t
Show
::
lastSyncDate
()
const
{
return
m_lastSyncDate
;
}
...
...
@@ -54,14 +90,37 @@ const std::string& Show::tvdbId()
return
m_tvdbId
;
}
bool
Show
::
setTvdbId
(
const
std
::
string
&
tvdbId
)
{
static
const
std
::
string
&
req
=
"UPDATE "
+
policy
::
ShowTable
::
Name
+
" SET tvdb_id = ? WHERE id_show = ?"
;
if
(
SqliteTools
::
executeUpdate
(
m_dbConnection
,
req
,
tvdbId
,
m_id
)
==
false
)
return
false
;
m_tvdbId
=
tvdbId
;
return
true
;
}
bool
Show
::
createTable
(
sqlite3
*
dbConnection
)
{
const
char
*
req
=
"CREATE TABLE IF NOT EXISTS
Show
("
const
std
::
string
req
=
"CREATE TABLE IF NOT EXISTS
"
+
policy
::
ShowTable
::
Name
+
"
("
"id_show INTEGER PRIMARY KEY AUTOINCREMENT,"
"name TEXT, UNSIGNED INTEGER release_year, TEXT short_summary,"
"name TEXT, "
"release_date UNSIGNED INTEGER,"
"short_summary TEXT,"
"artwork_url TEXT,"
"last_sync_date UNSIGNED INTEGER,"
"tvdb_id TEXT"
")"
;
return
SqliteTools
::
executeRequest
(
dbConnection
,
req
);
}
ShowPtr
Show
::
create
(
sqlite3
*
dbConnection
,
const
std
::
string
&
name
)
{
auto
show
=
std
::
make_shared
<
Show
>
(
name
);
static
const
std
::
string
req
=
"INSERT INTO "
+
policy
::
ShowTable
::
Name
+
"(name) VALUES(?)"
;
if
(
_Cache
::
insert
(
dbConnection
,
show
,
req
,
name
)
==
false
)
return
nullptr
;
show
->
m_dbConnection
=
dbConnection
;
return
show
;
}
src/Show.h
View file @
dc8f288d
...
...
@@ -4,6 +4,7 @@
#include <sqlite3.h>
#include "Cache.h"
#include "IMediaLibrary.h"
#include "IShow.h"
class
Show
;
...
...
@@ -22,22 +23,28 @@ class Show : public IShow, public Cache<Show, IShow, policy::ShowTable>
{
public:
Show
(
sqlite3
*
dbConnection
,
sqlite3_stmt
*
stmt
);
Show
(
sqlite3
*
dbConnection
);
virtual
const
std
::
string
&
name
();
virtual
unsigned
int
releaseYear
();
virtual
const
std
::
string
&
shortSummary
();
virtual
const
std
::
string
&
artworkUrl
();
virtual
time_t
lastSyncDate
();
Show
(
const
std
::
string
&
name
);
virtual
unsigned
int
id
()
const
;
virtual
const
std
::
string
&
name
()
const
;
virtual
time_t
releaseDate
()
const
;
virtual
bool
setReleaseDate
(
time_t
date
);
virtual
const
std
::
string
&
shortSummary
()
const
;
virtual
bool
setShortSummary
(
const
std
::
string
&
summary
);
virtual
const
std
::
string
&
artworkUrl
()
const
;
virtual
bool
setArtworkUrl
(
const
std
::
string
&
artworkUrl
);
virtual
time_t
lastSyncDate
()
const
;
virtual
const
std
::
string
&
tvdbId
();
virtual
bool
setTvdbId
(
const
std
::
string
&
summary
);
static
bool
createTable
(
sqlite3
*
dbConnection
);
static
ShowPtr
create
(
sqlite3
*
dbConnection
,
const
std
::
string
&
name
);
protected:
sqlite3
*
m_dbConnection
;
unsigned
int
m_id
;
std
::
string
m_name
;
unsigned
in
t
m_release
Year
;
time_
t
m_release
Date
;
std
::
string
m_shortSummary
;
std
::
string
m_artworkUrl
;
time_t
m_lastSyncDate
;
...
...
@@ -45,6 +52,7 @@ class Show : public IShow, public Cache<Show, IShow, policy::ShowTable>
friend
class
Cache
<
Show
,
IShow
,
policy
::
ShowTable
>
;
friend
struct
policy
::
ShowTable
;
typedef
Cache
<
Show
,
IShow
,
policy
::
ShowTable
>
_Cache
;
};
#endif // SHOW_H
test/CMakeLists.txt
View file @
dc8f288d
...
...
@@ -35,6 +35,7 @@ list(APPEND TEST_SRCS
Labels.cpp
Albums.cpp
Tests.cpp
Shows.cpp
)
add_executable
(
unittest
${
TEST_SRCS
}
)
...
...
test/Shows.cpp
0 → 100644
View file @
dc8f288d
#include "gtest/gtest.h"
#include "IFile.h"
#include "IMediaLibrary.h"
#include "IShow.h"
class
Shows
:
public
testing
::
Test
{
public:
static
IMediaLibrary
*
ml
;
protected:
virtual
void
SetUp
()
{
ml
=
MediaLibraryFactory
::
create
();
bool
res
=
ml
->
initialize
(
"test.db"
);
ASSERT_TRUE
(
res
);
}
virtual
void
TearDown
()
{
delete
ml
;
ml
=
nullptr
;
unlink
(
"test.db"
);
}
};
IMediaLibrary
*
Shows
::
ml
;
TEST_F
(
Shows
,
Create
)
{
auto
s
=
ml
->
createShow
(
"show"
);
ASSERT_NE
(
s
,
nullptr
);
auto
s2
=
ml
->
show
(
"show"
);
ASSERT_EQ
(
s
,
s2
);
}
TEST_F
(
Shows
,
Fetch
)
{
auto
s
=
ml
->
createShow
(
"show"
);
// Clear the cache
delete
ml
;
SetUp
();
auto
s2
=
ml
->
show
(
"show"
);
// The shared pointers are expected to point to different instances
ASSERT_NE
(
s
,
s2
);
ASSERT_EQ
(
s
->
id
(),
s2
->
id
()
);
}
TEST_F
(
Shows
,
SetReleaseDate
)
{
auto
s
=
ml
->
createShow
(
"show"
);
s
->
setReleaseDate
(
1234
);
ASSERT_EQ
(
s
->
releaseDate
(),
1234
);
delete
ml
;
SetUp
();
auto
s2
=
ml
->
show
(
"show"
);
ASSERT_EQ
(
s
->
releaseDate
(),
s2
->
releaseDate
()
);
}
TEST_F
(
Shows
,
SetShortSummary
)
{
auto
s
=
ml
->
createShow
(
"show"
);
s
->
setShortSummary
(
"summary"
);
ASSERT_EQ
(
s
->
shortSummary
(),
"summary"
);
delete
ml
;
SetUp
();
auto
s2
=
ml
->
show
(
"show"
);
ASSERT_EQ
(
s
->
shortSummary
(),
s2
->
shortSummary
()
);
}
TEST_F
(
Shows
,
SetArtworkUrl
)
{
auto
s
=
ml
->
createShow
(
"show"
);
s
->
setArtworkUrl
(
"artwork"
);
ASSERT_EQ
(
s
->
artworkUrl
(),
"artwork"
);
delete
ml
;
SetUp
();
auto
s2
=
ml
->
show
(
"show"
);
ASSERT_EQ
(
s
->
artworkUrl
(),
s2
->
artworkUrl
()
);
}
Write
Preview
Markdown
is supported
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