1
0
mirror of https://github.com/clementine-player/Clementine synced 2025-01-18 20:40:43 +01:00

use unique_ptr instead

This commit is contained in:
Chocobozzz 2014-06-05 17:42:55 +02:00
parent 2595df9779
commit ef6dd38d0d

View File

@ -945,41 +945,40 @@ bool TagReader::ReadCloudFile(const QUrl& download_url, const QString& title,
pb::tagreader::SongMetadata* song) const { pb::tagreader::SongMetadata* song) const {
qLog(Debug) << "Loading tags from" << title; qLog(Debug) << "Loading tags from" << title;
CloudStream* stream = new CloudStream(download_url, title, size, std::unique_ptr<CloudStream> stream(
authorisation_header, network_); new CloudStream(download_url, title, size, authorisation_header, network_));
stream->Precache(); stream->Precache();
std::unique_ptr<TagLib::File> tag; std::unique_ptr<TagLib::File> tag;
if (mime_type == "audio/mpeg" && title.endsWith(".mp3")) { if (mime_type == "audio/mpeg" && title.endsWith(".mp3")) {
tag.reset(new TagLib::MPEG::File(stream, // Doesn't take ownership. tag.reset(new TagLib::MPEG::File(stream.get(),
TagLib::ID3v2::FrameFactory::instance(), TagLib::ID3v2::FrameFactory::instance(),
TagLib::AudioProperties::Accurate)); TagLib::AudioProperties::Accurate));
} else if (mime_type == "audio/mp4" || } else if (mime_type == "audio/mp4" ||
(mime_type == "audio/mpeg" && title.endsWith(".m4a"))) { (mime_type == "audio/mpeg" && title.endsWith(".m4a"))) {
tag.reset( tag.reset(
new TagLib::MP4::File(stream, true, TagLib::AudioProperties::Accurate)); new TagLib::MP4::File(stream.get(), true, TagLib::AudioProperties::Accurate));
} }
#ifdef TAGLIB_HAS_OPUS #ifdef TAGLIB_HAS_OPUS
else if ((mime_type == "application/opus" || mime_type == "audio/opus" || else if ((mime_type == "application/opus" || mime_type == "audio/opus" ||
mime_type == "application/ogg" || mime_type == "audio/ogg") && mime_type == "application/ogg" || mime_type == "audio/ogg") &&
title.endsWith(".opus")) { title.endsWith(".opus")) {
tag.reset(new TagLib::Ogg::Opus::File(stream, true, tag.reset(new TagLib::Ogg::Opus::File(stream.get(), true,
TagLib::AudioProperties::Accurate)); TagLib::AudioProperties::Accurate));
} }
#endif #endif
else if (mime_type == "application/ogg" || mime_type == "audio/ogg") { else if (mime_type == "application/ogg" || mime_type == "audio/ogg") {
tag.reset(new TagLib::Ogg::Vorbis::File(stream, true, tag.reset(new TagLib::Ogg::Vorbis::File(stream.get(), true,
TagLib::AudioProperties::Accurate)); TagLib::AudioProperties::Accurate));
} else if (mime_type == "application/x-flac" || mime_type == "audio/flac" || } else if (mime_type == "application/x-flac" || mime_type == "audio/flac" ||
mime_type == "audio/x-flac") { mime_type == "audio/x-flac") {
tag.reset(new TagLib::FLAC::File(stream, tag.reset(new TagLib::FLAC::File(stream.get(),
TagLib::ID3v2::FrameFactory::instance(), TagLib::ID3v2::FrameFactory::instance(),
true, TagLib::AudioProperties::Accurate)); true, TagLib::AudioProperties::Accurate));
} else if (mime_type == "audio/x-ms-wma") { } else if (mime_type == "audio/x-ms-wma") {
tag.reset( tag.reset(
new TagLib::ASF::File(stream, true, TagLib::AudioProperties::Accurate)); new TagLib::ASF::File(stream.get(), true, TagLib::AudioProperties::Accurate));
} else { } else {
qLog(Debug) << "Unknown mime type for tagging:" << mime_type; qLog(Debug) << "Unknown mime type for tagging:" << mime_type;
delete stream;
return false; return false;
} }
@ -1007,12 +1006,9 @@ bool TagReader::ReadCloudFile(const QUrl& download_url, const QString& title,
if (tag->audioProperties()) { if (tag->audioProperties()) {
song->set_length_nanosec(tag->audioProperties()->length() * kNsecPerSec); song->set_length_nanosec(tag->audioProperties()->length() * kNsecPerSec);
} }
delete stream;
return true; return true;
} }
delete stream;
return false; return false;
} }
#endif // HAVE_GOOGLE_DRIVE #endif // HAVE_GOOGLE_DRIVE