Browse Source

FEATURE: Download first/last pieces first now applies to all media files in the torrent (Thanks Ahmad)

adaptive-webui-19844
Christophe Dumez 14 years ago
parent
commit
6d1ad28d8c
  1. 2
      Changelog
  2. 4
      src/properties/propertieswidget.cpp
  3. 66
      src/qtlibtorrent/qtorrenthandle.cpp
  4. 4
      src/qtlibtorrent/qtorrenthandle.h

2
Changelog

@ -14,6 +14,8 @@
- FEATURE: Optimized and improved the peer country resolution code - FEATURE: Optimized and improved the peer country resolution code
- FEATURE: Download first/last pieces first when sequential download is - FEATURE: Download first/last pieces first when sequential download is
enabled (Thanks Ahmad) enabled (Thanks Ahmad)
- FEATURE: Download first/last pieces first now applies to all media files
in the torrent (Thanks Ahmad)
- BUGFIX: Fix SOCKS5 proxy authentication in search engine(closes #680072) - BUGFIX: Fix SOCKS5 proxy authentication in search engine(closes #680072)
- BUGFIX: Fix two advanced settings (ignore limits on LAN and protocol - BUGFIX: Fix two advanced settings (ignore limits on LAN and protocol
overhead inclusion in rate limiter) overhead inclusion in rate limiter)

4
src/properties/propertieswidget.cpp

@ -677,10 +677,8 @@ void PropertiesWidget::renameSelectedFile() {
bool PropertiesWidget::applyPriorities() { bool PropertiesWidget::applyPriorities() {
qDebug("Saving files priorities"); qDebug("Saving files priorities");
const std::vector<int> priorities = PropListModel->getFilesPriorities(h.get_torrent_info().num_files()); const std::vector<int> priorities = PropListModel->getFilesPriorities(h.get_torrent_info().num_files());
bool first_last_piece_first = false;
// Save first/last piece first option state // Save first/last piece first option state
if(h.first_last_piece_first()) bool first_last_piece_first = h.first_last_piece_first();
first_last_piece_first = true;
// Prioritize the files // Prioritize the files
qDebug("prioritize files: %d", priorities[0]); qDebug("prioritize files: %d", priorities[0]);
h.prioritize_files(priorities); h.prioritize_files(priorities);

66
src/qtlibtorrent/qtorrenthandle.cpp

@ -122,27 +122,23 @@ int QTorrentHandle::num_pieces() const {
} }
bool QTorrentHandle::first_last_piece_first() const { bool QTorrentHandle::first_last_piece_first() const {
// Detect main file // Detect first media file
int rank=0; torrent_info::file_iterator it;
int main_file_index = 0; int index = 0;
file_entry main_file = torrent_handle::get_torrent_info().file_at(0); for(it = get_torrent_info().begin_files(); it != get_torrent_info().end_files(); it++) {
torrent_info::file_iterator it = torrent_handle::get_torrent_info().begin_files(); const QString ext = misc::toQStringU(it->path.string()).split(".").last();
it++; ++rank; if(misc::isPreviewable(ext) && torrent_handle::file_priority(index) > 0) {
while(it != torrent_handle::get_torrent_info().end_files()) { break;
if(it->size > main_file.size) {
main_file = *it;
main_file_index = rank;
} }
it++; ++index;
++rank;
} }
qDebug() << "Main file in the torrent is" << filepath(main_file); file_entry media_file = torrent_handle::get_torrent_info().file_at(index);
int piece_size = torrent_handle::get_torrent_info().piece_length(); int piece_size = torrent_handle::get_torrent_info().piece_length();
Q_ASSERT(piece_size>0); Q_ASSERT(piece_size>0);
int first_piece = floor((main_file.offset+1)/(double)piece_size); int first_piece = floor((media_file.offset+1)/(double)piece_size);
Q_ASSERT(first_piece >= 0 && first_piece < torrent_handle::get_torrent_info().num_pieces()); Q_ASSERT(first_piece >= 0 && first_piece < torrent_handle::get_torrent_info().num_pieces());
qDebug("First piece of the file is %d/%d", first_piece, torrent_handle::get_torrent_info().num_pieces()-1); qDebug("First piece of the file is %d/%d", first_piece, torrent_handle::get_torrent_info().num_pieces()-1);
int num_pieces_in_file = ceil(main_file.size/(double)piece_size); int num_pieces_in_file = ceil(media_file.size/(double)piece_size);
int last_piece = first_piece+num_pieces_in_file-1; int last_piece = first_piece+num_pieces_in_file-1;
Q_ASSERT(last_piece >= 0 && last_piece < torrent_handle::get_torrent_info().num_pieces()); Q_ASSERT(last_piece >= 0 && last_piece < torrent_handle::get_torrent_info().num_pieces());
qDebug("last piece of the file is %d/%d", last_piece, torrent_handle::get_torrent_info().num_pieces()-1); qDebug("last piece of the file is %d/%d", last_piece, torrent_handle::get_torrent_info().num_pieces()-1);
@ -550,32 +546,18 @@ void QTorrentHandle::add_tracker(const announce_entry& url) const {
#endif #endif
} }
void QTorrentHandle::prioritize_first_last_piece(bool b) const { void QTorrentHandle::prioritize_first_last_piece(int file_index, bool b) const {
// Detect main file
int rank=0;
int main_file_index = 0;
file_entry main_file = torrent_handle::get_torrent_info().file_at(0);
torrent_info::file_iterator it = torrent_handle::get_torrent_info().begin_files();
it++; ++rank;
while(it != torrent_handle::get_torrent_info().end_files()) {
if(it->size > main_file.size) {
main_file = *it;
main_file_index = rank;
}
it++;
++rank;
}
qDebug() << "Main file in the torrent is" << filepath(main_file);
// Determine the priority to set // Determine the priority to set
int prio = 7; // MAX int prio = 7; // MAX
if(!b) prio = torrent_handle::file_priority(main_file_index); if(!b) prio = torrent_handle::file_priority(file_index);
// Determine the first and last piece of the main file file_entry file = get_torrent_info().file_at(file_index);
// Determine the first and last piece of the file
int piece_size = torrent_handle::get_torrent_info().piece_length(); int piece_size = torrent_handle::get_torrent_info().piece_length();
Q_ASSERT(piece_size>0); Q_ASSERT(piece_size>0);
int first_piece = floor((main_file.offset+1)/(double)piece_size); int first_piece = floor((file.offset+1)/(double)piece_size);
Q_ASSERT(first_piece >= 0 && first_piece < torrent_handle::get_torrent_info().num_pieces()); Q_ASSERT(first_piece >= 0 && first_piece < torrent_handle::get_torrent_info().num_pieces());
qDebug("First piece of the file is %d/%d", first_piece, torrent_handle::get_torrent_info().num_pieces()-1); qDebug("First piece of the file is %d/%d", first_piece, torrent_handle::get_torrent_info().num_pieces()-1);
int num_pieces_in_file = ceil(main_file.size/(double)piece_size); int num_pieces_in_file = ceil(file.size/(double)piece_size);
int last_piece = first_piece+num_pieces_in_file-1; int last_piece = first_piece+num_pieces_in_file-1;
Q_ASSERT(last_piece >= 0 && last_piece < torrent_handle::get_torrent_info().num_pieces()); Q_ASSERT(last_piece >= 0 && last_piece < torrent_handle::get_torrent_info().num_pieces());
qDebug("last piece of the file is %d/%d", last_piece, torrent_handle::get_torrent_info().num_pieces()-1); qDebug("last piece of the file is %d/%d", last_piece, torrent_handle::get_torrent_info().num_pieces()-1);
@ -583,6 +565,20 @@ void QTorrentHandle::prioritize_first_last_piece(bool b) const {
torrent_handle::piece_priority(last_piece, prio); torrent_handle::piece_priority(last_piece, prio);
} }
void QTorrentHandle::prioritize_first_last_piece(bool b) const {
// Download first and last pieces first for all media files in the torrent
torrent_info::file_iterator it;
int index = 0;
for(it = get_torrent_info().begin_files(); it != get_torrent_info().end_files(); it++) {
const QString ext = misc::toQStringU(it->path.string()).split(".").last();
if(misc::isPreviewable(ext) && torrent_handle::file_priority(index) > 0) {
qDebug() << "File" << it->path.string().c_str() << "is previewable, toggle downloading of first/last pieces first";
prioritize_first_last_piece(index, b);
}
++index;
}
}
void QTorrentHandle::rename_file(int index, QString name) const { void QTorrentHandle::rename_file(int index, QString name) const {
torrent_handle::rename_file(index, std::string(name.toUtf8().constData())); torrent_handle::rename_file(index, std::string(name.toUtf8().constData()));
} }

4
src/qtlibtorrent/qtorrenthandle.h

@ -135,6 +135,10 @@ class QTorrentHandle : public libtorrent::torrent_handle {
// Operators // Operators
// //
bool operator ==(const QTorrentHandle& new_h) const; bool operator ==(const QTorrentHandle& new_h) const;
private:
void prioritize_first_last_piece(int file_index, bool b) const;
}; };
#endif #endif

Loading…
Cancel
Save