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
d5d2d7a5
Commit
d5d2d7a5
authored
May 10, 2014
by
Hugo Beauzée-Luyssen
Browse files
Add album fetching from a file
parent
fe1de73f
Changes
4
Hide whitespace changes
Inline
Side-by-side
src/Album.cpp
View file @
d5d2d7a5
...
...
@@ -51,3 +51,18 @@ bool Album::CreateTable(sqlite3* dbConnection)
"TEXT artwork_url, UNSIGNED INTEGER last_sync_date)"
;
return
SqliteTools
::
CreateTable
(
dbConnection
,
req
);
}
Album
*
Album
::
Fetch
(
sqlite3
*
dbConnection
,
unsigned
int
albumTrackId
)
{
const
char
*
req
=
"SELECT * FROM Album WHERE id_album = ?"
;
sqlite3_stmt
*
stmt
;
int
res
=
sqlite3_prepare_v2
(
dbConnection
,
req
,
-
1
,
&
stmt
,
NULL
);
if
(
res
!=
SQLITE_OK
)
return
NULL
;
sqlite3_bind_int
(
stmt
,
1
,
albumTrackId
);
if
(
sqlite3_step
(
stmt
)
!=
SQLITE_ROW
)
return
NULL
;
Album
*
album
=
new
Album
(
dbConnection
,
stmt
);
sqlite3_finalize
(
stmt
);
return
album
;
}
src/Album.h
View file @
d5d2d7a5
...
...
@@ -18,6 +18,7 @@ class Album : public IAlbum
virtual
time_t
lastSyncDate
();
static
bool
CreateTable
(
sqlite3
*
dbConnection
);
static
Album
*
Fetch
(
sqlite3
*
dbConnection
,
unsigned
int
albumTrackId
)
protected:
sqlite3
*
m_dbConnection
;
...
...
src/File.cpp
View file @
d5d2d7a5
#include <cassert>
#include "File.h"
#include "SqliteTools.h"
File
::
File
(
sqlite3
*
dbConnection
,
sqlite3_stmt
*
stmt
)
:
m_dbConnection
(
dbConnection
)
,
m_albumTrack
(
NULL
)
,
m_showEpisode
(
NULL
)
,
m_labels
(
NULL
)
{
m_id
=
sqlite3_column_int
(
stmt
,
0
);
m_type
=
(
Type
)
sqlite3_column_int
(
stmt
,
1
);
m_duration
=
sqlite3_column_int
(
stmt
,
2
);
m_albumTrackId
=
sqlite3_column_int
(
stmt
,
3
);
}
File
::
File
(
sqlite3
*
dbConnection
)
:
m_dbConnection
(
dbConnection
)
File
::
File
()
:
m_dbConnection
(
NULL
)
,
m_id
(
0
)
{
}
bool
File
::
insert
()
bool
File
::
insert
(
sqlite3
*
dbConnection
)
{
assert
(
m_dbConnection
==
NULL
);
m_dbConnection
=
dbConnection
;
sqlite3_stmt
*
stmt
;
std
::
string
req
=
"INSERT INTO File VALUES(NULL, ?, ?)"
;
std
::
string
req
=
"INSERT INTO File VALUES(NULL, ?,
?,
?)"
;
if
(
sqlite3_prepare_v2
(
m_dbConnection
,
req
.
c_str
(),
-
1
,
&
stmt
,
NULL
)
!=
SQLITE_OK
)
return
false
;
sqlite3_bind_int
(
stmt
,
1
,
m_type
);
sqlite3_bind_int
(
stmt
,
2
,
m_duration
);
sqlite3_bind_int
(
stmt
,
3
,
m_albumTrackId
);
if
(
sqlite3_step
(
stmt
)
!=
SQLITE_DONE
)
return
false
;
m_id
=
sqlite3_last_insert_rowid
(
m_dbConnection
);
...
...
@@ -31,6 +40,11 @@ bool File::insert()
IAlbumTrack
*
File
::
albumTrack
()
{
if
(
m_albumTrack
==
NULL
&&
m_albumTrackId
!=
0
)
{
m_albumTrack
=
AlbumTrack
::
fetch
(
m_albumTrackId
);
}
return
m_albumTrack
;
}
const
std
::
string
&
File
::
artworkUrl
()
...
...
@@ -54,6 +68,7 @@ bool File::CreateTable(sqlite3* connection)
{
std
::
string
req
=
"CREATE TABLE IF NOT EXISTS File("
"id_media INTEGER PRIMARY KEY AUTOINCREMENT,"
"type INTEGER, duration UNSIGNED INTEGER)"
;
"type INTEGER, duration UNSIGNED INTEGER,"
"album_track_id UNSIGNED INTEGER)"
;
return
SqliteTools
::
CreateTable
(
connection
,
req
);
}
src/File.h
View file @
d5d2d7a5
...
...
@@ -5,21 +5,25 @@
#include "IFile.h"
class
Album
;
class
ShowEpisode
;
class
AlbumTrack
;
class
File
:
public
IFile
{
public:
enum
Type
{
Video
,
// Any video file, not being a tv show episode
Audio
,
// Any kind of audio file, not being an album track
ShowEpisode
,
AlbumTrack
,
Video
Type
,
// Any video file, not being a tv show episode
Audio
Type
,
// Any kind of audio file, not being an album track
ShowEpisode
Type
,
AlbumTrack
Type
,
};
File
(
sqlite3
*
dbConnection
,
sqlite3_stmt
*
stmt
);
File
(
sqlite3
*
dbConnection
);
File
();
bool
insert
();
bool
insert
(
sqlite3
*
dbConnection
);
virtual
IAlbumTrack
*
albumTrack
();
virtual
const
std
::
string
&
artworkUrl
();
...
...
@@ -36,8 +40,13 @@ class File : public IFile
unsigned
int
m_id
;
Type
m_type
;
unsigned
int
m_duration
;
unsigned
int
m_albumTrackId
;
// Auto fetched related properties
Album
*
m_album
;
AlbumTrack
*
m_albumTrack
;
ShowEpisode
*
m_showEpisode
;
std
::
vector
<
ILabel
*>*
m_labels
;
};
#endif // FILE_H
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