Commit 4b32c226 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

Media: Don't url encode the filename

Media.filename is only used for sorting purposes. Having it url encoded
would cause unexpected results from the users' point of view, and
inconsistencies when title & filename are expected to be equal
parent c3b8bd64
......@@ -443,7 +443,8 @@ MediaPtr MediaLibrary::addExternalMedia( const std::string& mrl, IMedia::Type ty
{
return sqlite::Tools::withRetries( 3, [this, &mrl, type]() -> MediaPtr {
auto t = m_dbConnection->newTransaction();
auto media = Media::create( this, type, utils::file::fileName( mrl ) );
auto fileName = utils::file::fileName( mrl );
auto media = Media::create( this, type, utils::url::decode( fileName ) );
if ( media == nullptr )
return nullptr;
if ( media->addExternalMrl( mrl, IFile::Type::Main ) == nullptr )
......@@ -1170,6 +1171,17 @@ void MediaLibrary::migrateModel13to14()
Show::createTriggers( dbConn );
Playlist::createTriggers( dbConn );
Folder::createTriggers( dbConn );
const std::string req = "SELECT * FROM " + Media::Table::Name +
" WHERE filename LIKE '%#%%' ESCAPE '#'";
auto media = Media::fetchAll<Media>( this, req );
for ( const auto& m : media )
{
// We must not call mrl() from here. We might not have all devices yet,
// and calling mrl would crash for files stored on removable devices.
auto newFileName = utils::url::decode( m->fileName() );
LOG_INFO( "Converting ", m->fileName(), " to ", newFileName );
m->setFileName( std::move( newFileName ) );
}
t->commit();
}
......
......@@ -129,7 +129,7 @@ Status MetadataAnalyzer::run( IItem& item )
auto t = m_ml->getConn()->newTransaction();
LOG_INFO( "Adding ", mrl );
auto m = Media::create( m_ml, isAudio ? IMedia::Type::Audio : IMedia::Type::Video,
utils::file::fileName( mrl ) );
utils::url::decode( utils::file::fileName( mrl ) ) );
if ( m == nullptr )
{
LOG_ERROR( "Failed to add media ", mrl, " to the media library" );
......@@ -315,8 +315,8 @@ void MetadataAnalyzer::addPlaylistElement( IItem& item,
if ( fsFactory == nullptr ) // Media not supported by any FsFactory, registering it as external
{
auto t2 = m_ml->getConn()->newTransaction();
auto externalMedia = Media::create( m_ml, IMedia::Type::External, utils::url::encode(
subitem.meta( IItem::Metadata::Title ) ) );
auto externalMedia = Media::create( m_ml, IMedia::Type::External,
subitem.meta( IItem::Metadata::Title ) );
if ( externalMedia == nullptr )
{
LOG_ERROR( "Failed to create external media for ", mrl, " in the playlist ", item.mrl() );
......
......@@ -25,7 +25,7 @@
"index": 3
},
{
"title": "fast%20gold%20fast%20banshee.mp4",
"title": "fast gold fast banshee.mp4",
"index": 4
}
]
......
......@@ -187,6 +187,7 @@ TEST_F( DbModel, Upgrade13to14 )
auto m = media[0];
ASSERT_EQ( m->thumbnail(), "/path/to/thumbnail" );
ASSERT_TRUE( m->isThumbnailGenerated() );
ASSERT_EQ( m->fileName(), "file with space.avi" );
m = media[1];
ASSERT_EQ( m->thumbnail(), "" );
......
......@@ -73,7 +73,7 @@ CREATE TRIGGER add_album_track AFTER INSERT ON AlbumTrack BEGIN UPDATE Album SET
INSERT INTO `Settings` (db_model_version) VALUES (12);
INSERT INTO `Artist` (id_artist,name,shortbio,artwork_mrl,nb_albums,nb_tracks,mb_id,is_present) VALUES (1,NULL,NULL,NULL,0,0,NULL,1);
INSERT INTO `Artist` (id_artist,name,shortbio,artwork_mrl,nb_albums,nb_tracks,mb_id,is_present) VALUES (2,NULL,NULL,NULL,0,0,NULL,1);
INSERT INTO `Media` (id_media,type,subtype,duration,play_count,last_played_date,insertion_date,release_date,thumbnail,title,filename,is_favorite,is_present) VALUES (1,3,NULL,-1,NULL,NULL,1522231538,NULL,'/path/to/thumbnail','media.avi','media.avi',0,1);
INSERT INTO `Media` (id_media,type,subtype,duration,play_count,last_played_date,insertion_date,release_date,thumbnail,title,filename,is_favorite,is_present) VALUES (1,3,NULL,-1,NULL,NULL,1522231538,NULL,'/path/to/thumbnail','Cool media','file%20with%20space.avi',0,1);
INSERT INTO `File` (id_file,media_id,playlist_id,mrl,type,last_modification_date,size,folder_id,is_present,is_removable,is_external) VALUES (1,1,NULL,'media.avi',1,NULL,NULL,NULL,1,0,1);
INSERT INTO `Media` (id_media,type,subtype,duration,play_count,last_played_date,insertion_date,release_date,thumbnail,title,filename,is_favorite,is_present) VALUES (2,3,NULL,-1,NULL,NULL,1522231538,NULL,'','media2.avi','media2.avi',0,1);
INSERT INTO `File` (id_file,media_id,playlist_id,mrl,type,last_modification_date,size,folder_id,is_present,is_removable,is_external) VALUES (2,2,NULL,'media2.avi',1,NULL,NULL,NULL,1,0,1);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment