2025-05-11 09:58:11 +08:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
import argparse
|
|
|
|
from p115 import P115Client, P115FileSystem
|
|
|
|
import time
|
|
|
|
import traceback
|
2025-05-14 07:05:24 +08:00
|
|
|
import os
|
2025-05-16 18:26:37 +08:00
|
|
|
import re
|
2025-05-17 13:33:47 +08:00
|
|
|
import sys
|
|
|
|
import traceback
|
2025-05-11 09:58:11 +08:00
|
|
|
|
|
|
|
count=0
|
2025-05-17 13:33:47 +08:00
|
|
|
failcount=0
|
|
|
|
|
|
|
|
fullscan=True
|
2025-05-11 09:58:11 +08:00
|
|
|
|
2025-05-14 07:05:24 +08:00
|
|
|
def walk_dir(fs,f,replaceroot):
|
2025-05-11 09:58:11 +08:00
|
|
|
dirlist=list()
|
2025-05-17 13:33:47 +08:00
|
|
|
try:
|
2025-05-23 22:36:10 +08:00
|
|
|
#print("try listdir")
|
2025-05-17 13:33:47 +08:00
|
|
|
file_list = fs.listdir_attr()
|
|
|
|
except KeyboardInterrupt:
|
|
|
|
print("get ctrl+c, exit")
|
|
|
|
sys.exit(1)
|
|
|
|
except:
|
|
|
|
traceback.print_exc()
|
|
|
|
time.sleep(1)
|
|
|
|
return
|
2025-05-23 22:36:10 +08:00
|
|
|
#filetype_re=re.compile(r'\.(png|jpg|jpeg|bmp|gif|doc|nfo|flac|mp3|wma|ape|cue|wav|dst|dff|dts|ac3|eac3|txt|db|pdf)$')
|
|
|
|
filetype_re=re.compile(r'\.(png|jpg|jpeg|bmp|gif|doc|nfo|txt|db|pdf)$')
|
2025-05-11 09:58:11 +08:00
|
|
|
for file_obj in file_list:
|
|
|
|
if not file_obj.is_directory:
|
2025-05-14 07:05:24 +08:00
|
|
|
path = file_obj.path
|
2025-05-16 18:26:37 +08:00
|
|
|
if filetype_re.search(path) != None or "BDMV" in path:
|
|
|
|
continue
|
2025-05-23 22:36:10 +08:00
|
|
|
size=int(file_obj.size)
|
|
|
|
if size>0 and size<4096:
|
|
|
|
continue
|
2025-05-14 07:05:24 +08:00
|
|
|
paths = path.split("/")
|
|
|
|
if replaceroot!="":
|
|
|
|
if len(paths)>=3:
|
|
|
|
path=os.path.join("/",replaceroot,*paths[2:])
|
2025-05-26 20:51:33 +08:00
|
|
|
path=path.replace("\\/","|")
|
2025-05-14 07:05:24 +08:00
|
|
|
|
2025-05-23 22:36:10 +08:00
|
|
|
print(f"{path}\t{file_obj.size}")
|
|
|
|
f.write(f"{path}\t{file_obj.size}\n")
|
2025-05-11 09:58:11 +08:00
|
|
|
f.flush()
|
|
|
|
else:
|
|
|
|
dirlist.append(file_obj.path)
|
|
|
|
for dirItem in dirlist:
|
|
|
|
fs.chdir(dirItem)
|
2025-05-17 13:33:47 +08:00
|
|
|
global count
|
|
|
|
count=count+1
|
|
|
|
if count%3==0:
|
|
|
|
time.sleep(1)
|
|
|
|
try:
|
|
|
|
walk_dir(fs,f,replaceroot)
|
|
|
|
except KeyboardInterrupt:
|
|
|
|
print("get ctrl+c, exit")
|
|
|
|
sys.exit(1)
|
|
|
|
except:
|
|
|
|
traceback.print_exc()
|
|
|
|
time.sleep(1)
|
2025-05-11 09:58:11 +08:00
|
|
|
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')
|
2025-05-14 07:05:24 +08:00
|
|
|
parser.add_argument('--replaceroot', type=str, default="", required=False, help='替换根目录名称')
|
2025-05-11 09:58:11 +08:00
|
|
|
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)
|
2025-05-17 13:33:47 +08:00
|
|
|
cidre = re.compile(r'cid=([0-9]+)')
|
|
|
|
matches = cidre.findall(shareUrl)
|
|
|
|
cid = None
|
|
|
|
if len(matches)>0:
|
|
|
|
cid=int(matches[0])
|
|
|
|
shareUrl = cidre.sub("", shareUrl).replace("?&","?").replace("&&","&")
|
|
|
|
|
2025-05-11 09:58:11 +08:00
|
|
|
fs = client.get_share_fs(shareUrl)
|
|
|
|
|
2025-05-17 13:33:47 +08:00
|
|
|
#if cid != None:
|
|
|
|
# fs.chdir(cid)
|
|
|
|
|
|
|
|
|
2025-05-11 09:58:11 +08:00
|
|
|
count=0
|
|
|
|
f=open(args.output, mode="a", encoding="utf-8")
|
2025-05-14 07:05:24 +08:00
|
|
|
walk_dir(fs,f,args.replaceroot)
|
2025-05-11 09:58:11 +08:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|