Skip to content

Commit

Permalink
remove unnecessary list wraps
Browse files Browse the repository at this point in the history
  • Loading branch information
hauxir committed Nov 6, 2019
1 parent d994de0 commit 8a2aeb8
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions app/torrent.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def get_torrent_info(h):


def get_index_and_file_from_files(h, filename):
files = list(get_torrent_info(h).files())
files = get_torrent_info(h).files()
try:
return next((i, f) for (i, f) in enumerate(files) if f.path.endswith(filename))
except StopIteration:
Expand All @@ -33,13 +33,13 @@ def torrent_is_finished(h):


def prioritize_files(h, priorities):
piece_priorities_before = list(h.piece_priorities())
piece_priorities_before = h.piece_priorities()
h.prioritize_files(priorities)

while h.file_priorities() != priorities:
time.sleep(1)

piece_priorities_after = list(h.piece_priorities())
piece_priorities_after = h.piece_priorities()

for i, priority in enumerate(piece_priorities_before):
if priority == HIGHEST_PRIORITY:
Expand All @@ -50,7 +50,7 @@ def prioritize_files(h, priorities):

def prioritize_pieces(h, priorities):
h.prioritize_pieces(priorities)
while list(h.piece_priorities()) != priorities:
while h.piece_priorities() != priorities:
time.sleep(1)


Expand All @@ -66,7 +66,7 @@ def get_hash(magnet_link):

def get_file_piece_indexes(h, f):
torrent_info = get_torrent_info(h)
total_pieces = len(list(h.piece_priorities()))
total_pieces = len(h.piece_priorities())
bytes_per_piece = torrent_info.piece_length()
total_torrent_size = torrent_info.total_size()

Expand All @@ -84,7 +84,7 @@ def get_file_piece_indexes(h, f):
def prioritize_first_n_pieces(h, f, n):
first_piece_index, _last_piece_index = get_file_piece_indexes(h, f)

piece_priorities = list(h.piece_priorities())
piece_priorities = h.piece_priorities()
n = min(n, len(piece_priorities) - first_piece_index)

for i in range(first_piece_index, first_piece_index + n):
Expand All @@ -95,7 +95,7 @@ def prioritize_first_n_pieces(h, f, n):
def prioritize_last_n_pieces(h, f, n):
_first_piece_index, last_piece_index = get_file_piece_indexes(h, f)

piece_priorities = list(h.piece_priorities())
piece_priorities = h.piece_priorities()
n = min(n, len(piece_priorities))

for i in range((last_piece_index - n) + 1, last_piece_index + 1):
Expand Down Expand Up @@ -217,7 +217,7 @@ def _add_magnet_link_to_downloads(self, magnet_link):
)
files = get_torrent_info(h).files()
prioritize_files(h, [0] * len(files))
prioritize_pieces(h, [0] * len(list(h.piece_priorities())))
prioritize_pieces(h, [0] * len(h.piece_priorities()))
self.torrents[magnet_hash] = h
return h

Expand Down

0 comments on commit 8a2aeb8

Please sign in to comment.