def recursive_scan(father): """To add recursively every file to the tree from the root of the scan""" # for performance reasons, we will scan files with mediainfo only if they have a videofile extension ext_video = ['.divx','.avi','.mp4','.mkv','.wmv','.flv','.mov','.mpg','.mpeg','.rmvb','.m4v','.ts','.vlc'] curdir = os.path.join(father.path, father.name) # print "recursive-scan: i visited " + curdir for file in os.listdir(curdir): # for every file new_node = node(curdir, file, father) file_name, file_extension = os.path.splitext(file) # TODO: we get filesize (in bytes) # we could also get creation date or last modification date # in order to deal with case matching, we convert extension to lowercase, and then we compare if file_extension.lower() in ext_video and model.recordVideoMetadatas == True: # we use MediaInfo to get video informations if it's a video file mediainfo(new_node) else: new_node.isVid = False father.children.append(new_node) if os.path.isdir(os.path.join(curdir, file)): # if the file is a directory new_node.isDir = True recursive_scan(new_node) else: # if the file is not a directory new_node.isDir = False
def run(self): if self.dirToScan == "": print "User canceled" return else: print "Choosen dir: " + self.dirToScan # we scan the directory # root = node(os.path.basename(str(dir)), None) # BUG: relative path root = node(os.path.dirname(self.dirToScan),os.path.basename(self.dirToScan), None) root.isDir = True recursive_scan(root) model.root_node_list.append(root) # we convert the tree of nodes to a tree of items to display it root_item = convertBinaryTreeToDisplayDirOnly(root) model.model_dir.appendRow(root_item) model.root_item_list.append(root_item) # we emit a signal to say that this task is done self.emit(QtCore.SIGNAL('thread_scan_finished')) return