|
|
@ -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())); |
|
|
|
} |
|
|
|
} |
|
|
|