def update_with_download_info(self, download): if len(download["files"]) > 0 and not self.window( ).left_menu_playlist.loaded_list: self.window().left_menu_playlist.set_files(download["files"]) # Play the video with the largest file index largest_file = None for file_info in download["files"]: if is_video_file(file_info["name"]) and ( largest_file is None or file_info["size"] > largest_file["size"]): largest_file = file_info if not largest_file: # We don't have a media file in this torrent. Reset everything and show an error ConfirmationDialog.show_error( self.window(), "No media files", "This download contains no media files.") self.window().hide_left_menu_playlist() return self.window().left_menu_playlist.set_active_index( largest_file["index"]) self.change_playing_index(largest_file["index"], largest_file["name"]) self.window().video_player_info_button.popup.update(download)
def set_files(self, files): self.clear() self.files_data = [] for file_info in files: if is_video_file(file_info['name']): self.addItem(file_info['name']) self.files_data.append(file_info)
def on_right_click_file_item(self, pos): num_selected = len(self.window().download_files_list.selectedItems()) if num_selected == 0: return item_infos = [] # Array of (item, included, is_selected) selected_files_info = [] for i in range(self.window().download_files_list.topLevelItemCount()): item = self.window().download_files_list.topLevelItem(i) is_selected = item in self.window( ).download_files_list.selectedItems() item_infos.append((item, item.file_info["included"], is_selected)) if is_selected: selected_files_info.append(item.file_info) item_clicked = self.window().download_files_list.itemAt(pos) if not item_clicked or not item_clicked in self.window( ).download_files_list.selectedItems(): return # Check whether we should enable the 'exclude' button num_excludes = 0 num_includes_selected = 0 for item_info in item_infos: if item_info[1] and item_info[0] in self.window( ).download_files_list.selectedItems(): num_includes_selected += 1 if not item_info[1]: num_excludes += 1 menu = TriblerActionMenu(self) include_action = QAction( 'Include file' + ('(s)' if num_selected > 1 else ''), self) exclude_action = QAction( 'Exclude file' + ('(s)' if num_selected > 1 else ''), self) include_action.triggered.connect( lambda: self.on_files_included(selected_files_info)) include_action.setEnabled(True) exclude_action.triggered.connect( lambda: self.on_files_excluded(selected_files_info)) exclude_action.setEnabled(not ( num_excludes + num_includes_selected == len(item_infos))) menu.addAction(include_action) menu.addAction(exclude_action) if len(selected_files_info) == 1 and is_video_file(selected_files_info[0]['name'])\ and self.window().vlc_available: play_action = QAction('Play', self) play_action.triggered.connect( lambda: self.on_play_file(selected_files_info[0])) menu.addAction(play_action) menu.exec_(self.window().download_files_list.mapToGlobal(pos))
def get_largest_file(self): largest_file = None largest_index = None for index, file_info in enumerate(self.files_data): if is_video_file(file_info["name"]) and \ (largest_file is None or file_info["size"] > largest_file["size"]): largest_file = file_info largest_index = index return largest_index, largest_file
def set_files(self, files): self.clear() self.files_data = [] for file_info in files: if is_video_file(file_info['name']): self.addItem(file_info['name']) self.files_data.append((file_info['index'], file_info['name'])) self.loaded_list = True
def on_right_click_file_item(self, pos): num_selected = len(self.window().download_files_list.selectedItems()) if num_selected == 0: return item_infos = [] # Array of (item, included, is_selected) selected_files_info = [] for i in range(self.window().download_files_list.topLevelItemCount()): item = self.window().download_files_list.topLevelItem(i) is_selected = item in self.window().download_files_list.selectedItems() item_infos.append((item, item.file_info["included"], is_selected)) if is_selected: selected_files_info.append(item.file_info) item_clicked = self.window().download_files_list.itemAt(pos) if not item_clicked or not item_clicked in self.window().download_files_list.selectedItems(): return # Check whether we should enable the 'exclude' button num_excludes = 0 num_includes_selected = 0 for item_info in item_infos: if item_info[1] and item_info[0] in self.window().download_files_list.selectedItems(): num_includes_selected += 1 if not item_info[1]: num_excludes += 1 menu = TriblerActionMenu(self) include_action = QAction('Include file' + ('(s)' if num_selected > 1 else ''), self) exclude_action = QAction('Exclude file' + ('(s)' if num_selected > 1 else ''), self) include_action.triggered.connect(lambda: self.on_files_included(selected_files_info)) include_action.setEnabled(True) exclude_action.triggered.connect(lambda: self.on_files_excluded(selected_files_info)) exclude_action.setEnabled(not (num_excludes + num_includes_selected == len(item_infos))) menu.addAction(include_action) menu.addAction(exclude_action) if len(selected_files_info) == 1 and is_video_file(selected_files_info[0]['name'])\ and self.window().vlc_available: play_action = QAction('Play', self) play_action.triggered.connect(lambda: self.on_play_file(selected_files_info[0])) menu.addAction(play_action) menu.exec_(self.window().download_files_list.mapToGlobal(pos))
def get_video_file_index(self, file_index): video_index = 0 for index in xrange(file_index): if is_video_file(self.current_download["files"][index]['name']): video_index += 1 return video_index