PR #17454. Closes #907.
@ -2502,7 +2502,15 @@ bool Session::addTorrent_impl(const std::variant<MagnetUri, TorrentInfo> &source
TorrentImpl *const torrent = m_torrents.value(id);
if (torrent)
{
if (hasMetadata)
// Trying to set metadata to existing torrent in case if it has none
torrent->setMetadata(std::get<TorrentInfo>(source));
}
return false;
LoadTorrentParams loadTorrentParams = initLoadTorrentParams(addTorrentParams);
lt::add_torrent_params &p = loadTorrentParams.ltAddTorrentParams;
@ -298,6 +298,7 @@ namespace BitTorrent
virtual void removeUrlSeeds(const QVector<QUrl> &urlSeeds) = 0;
virtual bool connectPeer(const PeerAddress &peerAddress) = 0;
virtual void clearPeers() = 0;
virtual bool setMetadata(const TorrentInfo &torrentInfo) = 0;
virtual QString createMagnetURI() const = 0;
virtual nonstd::expected<QByteArray, QString> exportToBuffer() const = 0;
@ -2126,6 +2126,19 @@ lt::torrent_handle TorrentImpl::nativeHandle() const
return m_nativeHandle;
bool TorrentImpl::setMetadata(const TorrentInfo &torrentInfo)
if (hasMetadata())
#ifdef QBT_USES_LIBTORRENT2
return m_nativeHandle.set_metadata(torrentInfo.nativeInfo()->info_section());
#else
const std::shared_ptr<lt::torrent_info> nativeInfo = torrentInfo.nativeInfo();
return m_nativeHandle.set_metadata(lt::span<const char>(nativeInfo->metadata().get(), nativeInfo->metadata_size()));
#endif
bool TorrentImpl::isMoveInProgress() const
return m_storageIsMoving;
@ -225,6 +225,7 @@ namespace BitTorrent
void removeUrlSeeds(const QVector<QUrl> &urlSeeds) override;
bool connectPeer(const PeerAddress &peerAddress) override;
void clearPeers() override;
bool setMetadata(const TorrentInfo &torrentInfo) override;
QString createMagnetURI() const override;
nonstd::expected<QByteArray, QString> exportToBuffer() const override;
@ -435,6 +435,9 @@ bool AddNewTorrentDialog::loadTorrentImpl()
BitTorrent::Torrent *const torrent = BitTorrent::Session::instance()->findTorrent(torrentID);
torrent->setMetadata(m_torrentInfo);
if (torrent->isPrivate() || m_torrentInfo.isPrivate())
RaisedMessageBox::warning(this, tr("Torrent is already present"), tr("Torrent '%1' is already in the transfer list. Trackers cannot be merged because it is a private torrent.").arg(torrent->name()), QMessageBox::Ok);