64 lines
1.9 KiB
Python
64 lines
1.9 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
|
|
import argparse
|
|
from p115 import P115Client, P115FileSystem
|
|
import time
|
|
import traceback
|
|
import os
|
|
import re
|
|
|
|
count=0
|
|
|
|
def walk_dir(fs,f,replaceroot):
|
|
dirlist=list()
|
|
file_list = fs.listdir_attr()
|
|
filetype_re=re.compile(r'\.(png|jpg|jpeg|bmp|gif|doc|nfo|flac|mp3|wma|ape|cue|wav|dst|dff|dts|ac3|eac3|txt)$')
|
|
for file_obj in file_list:
|
|
if not file_obj.is_directory:
|
|
path = file_obj.path
|
|
if filetype_re.search(path) != None or "BDMV" in path:
|
|
continue
|
|
paths = path.split("/")
|
|
if replaceroot!="":
|
|
if len(paths)>=3:
|
|
path=os.path.join("/",replaceroot,*paths[2:])
|
|
|
|
print(path+"\t"+str(file_obj.size))
|
|
f.write(path+"\t"+str(file_obj.size)+"\n")
|
|
f.flush()
|
|
else:
|
|
dirlist.append(file_obj.path)
|
|
for dirItem in dirlist:
|
|
fs.chdir(dirItem)
|
|
# global count
|
|
# count=count+1
|
|
# if count%4==0:
|
|
# time.sleep(1)
|
|
walk_dir(fs,f,replaceroot)
|
|
return
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser(description='快速遍历115分享目录')
|
|
parser.add_argument('--cookie', type=str, required=True, help='115Cookie')
|
|
parser.add_argument('--url', type=str, required=True, help='115ShareUrl')
|
|
parser.add_argument('--output', type=str, required=True, help='outputfile')
|
|
parser.add_argument('--replaceroot', type=str, default="", required=False, help='替换根目录名称')
|
|
args = parser.parse_args()
|
|
cookie=args.cookie
|
|
shareUrl=args.url
|
|
client=P115Client(cookie)
|
|
|
|
if not shareUrl.startswith("http"):
|
|
shareUrl = "https://115.com/s/" + shareUrl
|
|
|
|
print("cookie:"+args.cookie+", shareurl:"+shareUrl)
|
|
fs = client.get_share_fs(shareUrl)
|
|
|
|
count=0
|
|
f=open(args.output, mode="a", encoding="utf-8")
|
|
walk_dir(fs,f,args.replaceroot)
|
|
|
|
if __name__ == '__main__':
|
|
main()
|