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
37f18569
Commit
37f18569
authored
Dec 24, 2016
by
Hugo Beauzée-Luyssen
Browse files
Media: Add basic support for external MRL
parent
4903e1cd
Changes
9
Hide whitespace changes
Inline
Side-by-side
include/medialibrary/IFile.h
View file @
37f18569
...
...
@@ -48,6 +48,8 @@ public:
Soundtrack
,
/// External subtitles
Subtitles
,
/// External stream, unmanaged by the medialibrary
External
,
};
virtual
~
IFile
()
=
default
;
...
...
include/medialibrary/IMediaLibrary.h
View file @
37f18569
...
...
@@ -162,6 +162,7 @@ class IMediaLibrary
virtual
bool
deleteLabel
(
LabelPtr
label
)
=
0
;
virtual
MediaPtr
media
(
int64_t
mediaId
)
const
=
0
;
virtual
MediaPtr
media
(
const
std
::
string
&
mrl
)
const
=
0
;
virtual
MediaPtr
addMedia
(
const
std
::
string
&
mrl
)
=
0
;
virtual
std
::
vector
<
MediaPtr
>
audioFiles
(
SortingCriteria
sort
=
SortingCriteria
::
Default
,
bool
desc
=
false
)
const
=
0
;
virtual
std
::
vector
<
MediaPtr
>
videoFiles
(
SortingCriteria
sort
=
SortingCriteria
::
Default
,
bool
desc
=
false
)
const
=
0
;
virtual
AlbumPtr
album
(
int64_t
id
)
const
=
0
;
...
...
src/File.cpp
View file @
37f18569
...
...
@@ -66,6 +66,22 @@ File::File( MediaLibraryPtr ml, int64_t mediaId, Type type, const fs::IFile& fil
{
}
File
::
File
(
MediaLibraryPtr
ml
,
int64_t
mediaId
,
IFile
::
Type
type
,
const
std
::
string
&
mrl
)
:
m_ml
(
ml
)
,
m_id
(
0
)
,
m_mediaId
(
mediaId
)
,
m_mrl
(
mrl
)
,
m_type
(
type
)
,
m_lastModificationDate
(
0
)
,
m_size
(
0
)
,
m_parserSteps
(
ParserStep
::
Completed
)
,
m_folderId
(
0
)
,
m_isPresent
(
true
)
,
m_isRemovable
(
false
)
,
m_fullPath
(
mrl
)
{
}
int64_t
File
::
id
()
const
{
return
m_id
;
...
...
@@ -179,6 +195,17 @@ std::shared_ptr<File> File::create( MediaLibraryPtr ml, int64_t mediaId, Type ty
return
self
;
}
std
::
shared_ptr
<
File
>
File
::
create
(
MediaLibraryPtr
ml
,
int64_t
mediaId
,
IFile
::
Type
type
,
const
std
::
string
&
mrl
)
{
auto
self
=
std
::
make_shared
<
File
>
(
ml
,
mediaId
,
type
,
mrl
);
static
const
std
::
string
req
=
"INSERT INTO "
+
policy
::
FileTable
::
Name
+
"(media_id, mrl, type, folder_id, is_removable) VALUES(?, ?, ?, NULL, 0)"
;
if
(
insert
(
ml
,
self
,
req
,
mediaId
,
mrl
,
type
)
==
false
)
return
nullptr
;
return
self
;
}
std
::
shared_ptr
<
File
>
File
::
fromPath
(
MediaLibraryPtr
ml
,
const
std
::
string
&
path
)
{
static
const
std
::
string
req
=
"SELECT * FROM "
+
policy
::
FileTable
::
Name
+
" WHERE mrl = ?"
;
...
...
src/File.h
View file @
37f18569
...
...
@@ -60,6 +60,7 @@ public:
File
(
MediaLibraryPtr
ml
,
sqlite
::
Row
&
row
);
File
(
MediaLibraryPtr
ml
,
int64_t
mediaId
,
Type
type
,
const
fs
::
IFile
&
file
,
int64_t
folderId
,
bool
isRemovable
);
File
(
MediaLibraryPtr
ml
,
int64_t
mediaId
,
Type
type
,
const
std
::
string
&
mrl
);
virtual
int64_t
id
()
const
override
;
virtual
const
std
::
string
&
mrl
()
const
override
;
virtual
Type
type
()
const
override
;
...
...
@@ -81,6 +82,7 @@ public:
static
bool
createTable
(
DBConnection
dbConnection
);
static
std
::
shared_ptr
<
File
>
create
(
MediaLibraryPtr
ml
,
int64_t
mediaId
,
Type
type
,
const
fs
::
IFile
&
file
,
int64_t
folderId
,
bool
isRemovable
);
static
std
::
shared_ptr
<
File
>
create
(
MediaLibraryPtr
ml
,
int64_t
mediaId
,
Type
type
,
const
std
::
string
&
mrl
);
/**
* @brief fromPath Attempts to fetch a file using its full path
* This will only work if the file was stored on a non removable device
...
...
src/Media.cpp
View file @
37f18569
...
...
@@ -370,6 +370,17 @@ std::shared_ptr<File> Media::addFile( const fs::IFile& fileFs, Folder& parentFol
return
file
;
}
std
::
shared_ptr
<
File
>
Media
::
addExternalMrl
(
const
std
::
string
&
mrl
)
{
auto
file
=
File
::
create
(
m_ml
,
m_id
,
File
::
Type
::
External
,
mrl
);
if
(
file
==
nullptr
)
return
nullptr
;
auto
lock
=
m_files
.
lock
();
if
(
m_files
.
isCached
()
)
m_files
.
get
().
push_back
(
file
);
return
file
;
}
void
Media
::
removeFile
(
File
&
file
)
{
file
.
destroy
();
...
...
src/Media.h
View file @
37f18569
...
...
@@ -127,6 +127,7 @@ class Media : public IMedia, public DatabaseHelpers<Media, policy::MediaTable>
bool
save
();
std
::
shared_ptr
<
File
>
addFile
(
const
fs
::
IFile
&
fileFs
,
Folder
&
parentFolder
,
fs
::
IDirectory
&
parentFolderFs
,
IFile
::
Type
type
);
std
::
shared_ptr
<
File
>
addExternalMrl
(
const
std
::
string
&
mrl
);
void
removeFile
(
File
&
file
);
static
std
::
vector
<
MediaPtr
>
listAll
(
MediaLibraryPtr
ml
,
Type
type
,
SortingCriteria
sort
,
bool
desc
);
...
...
src/MediaLibrary.cpp
View file @
37f18569
...
...
@@ -303,6 +303,15 @@ MediaPtr MediaLibrary::media( const std::string& mrl ) const
return
file
->
media
();
}
MediaPtr
MediaLibrary
::
addMedia
(
const
std
::
string
&
mrl
)
{
auto
media
=
Media
::
create
(
this
,
IMedia
::
Type
::
Unknown
,
utils
::
file
::
fileName
(
mrl
)
);
if
(
media
==
nullptr
)
return
nullptr
;
media
->
addExternalMrl
(
mrl
);
return
media
;
}
std
::
vector
<
MediaPtr
>
MediaLibrary
::
audioFiles
(
SortingCriteria
sort
,
bool
desc
)
const
{
return
Media
::
listAll
(
this
,
IMedia
::
Type
::
Audio
,
sort
,
desc
);
...
...
src/MediaLibrary.h
View file @
37f18569
...
...
@@ -67,6 +67,7 @@ class MediaLibrary : public IMediaLibrary, public IDeviceListerCb
virtual
MediaPtr
media
(
int64_t
mediaId
)
const
override
;
virtual
MediaPtr
media
(
const
std
::
string
&
path
)
const
override
;
virtual
MediaPtr
addMedia
(
const
std
::
string
&
mrl
)
override
;
virtual
std
::
vector
<
MediaPtr
>
audioFiles
(
SortingCriteria
sort
,
bool
desc
)
const
override
;
virtual
std
::
vector
<
MediaPtr
>
videoFiles
(
SortingCriteria
sort
,
bool
desc
)
const
override
;
...
...
test/unittest/MediaTests.cpp
View file @
37f18569
...
...
@@ -478,6 +478,27 @@ TEST_F( Medias, MetadataOverride )
ASSERT_EQ
(
"otter"
,
md
.
str
()
);
}
TEST_F
(
Medias
,
ExternalMrl
)
{
auto
m
=
ml
->
addMedia
(
"https://foo.bar/sea-otters.mkv"
);
ASSERT_NE
(
nullptr
,
m
);
ASSERT_EQ
(
m
->
title
(),
"sea-otters.mkv"
);
// External files shouldn't appear in listings
auto
videos
=
ml
->
videoFiles
(
medialibrary
::
SortingCriteria
::
Default
,
false
);
ASSERT_EQ
(
0u
,
videos
.
size
()
);
auto
audios
=
ml
->
audioFiles
(
medialibrary
::
SortingCriteria
::
Default
,
false
);
ASSERT_EQ
(
0u
,
audios
.
size
()
);
Reload
();
auto
m2
=
ml
->
media
(
"https://foo.bar/sea-otters.mkv"
);
ASSERT_NE
(
nullptr
,
m2
);
ASSERT_EQ
(
m
->
id
(),
m2
->
id
()
);
}
class
FetchMedia
:
public
Tests
{
protected:
...
...
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