Skip to content

Commit

Permalink
javdb*.json path search order
Browse files Browse the repository at this point in the history
  • Loading branch information
lededev committed Sep 27, 2021
1 parent 07893de commit 75b7188
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
20 changes: 18 additions & 2 deletions ADC_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -590,10 +590,26 @@ def is_uncensored(number):
# 从网站登录后,通过浏览器插件(CookieBro或EdittThisCookie)或者直接在地址栏网站链接信息处都可以复制或者导出cookie内容,
# 并填写到以上json文件的相应字段中
def load_cookies(filename):
filename = os.path.basename(filename)
if not len(filename):
return None, None
path_search_order = [
f"./{filename}",
os.path.join(Path.home(), filename),
os.path.join(Path.home(), f".avdc/{filename}"),
os.path.join(Path.home(), f".local/share/avdc/{filename}")
]
cookies_filename = None
for p in path_search_order:
if os.path.exists(p):
cookies_filename = p
break
if not cookies_filename:
return None, None
try:
return json.load(open(filename))
return json.load(open(cookies_filename)), cookies_filename
except:
return None
return None, None

# 文件修改时间距此时的天数
def file_modification_days(filename) -> int:
Expand Down
6 changes: 3 additions & 3 deletions WebCrawler/javdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,10 @@ def main(number):
# 不加载过期的cookie,javdb登录界面显示为7天免登录,故假定cookie有效期为7天
cdays = file_modification_days(cookie_json)
if cdays < 7:
javdb_cookies = load_cookies(cookie_json)
javdb_cookies, cookies_filepath = load_cookies(cookie_json)
elif cdays != 9999:
print('[!]Cookies file ' + cookie_json + ' was updated ' + str(cdays) +
' days ago, it will not be used for HTTP requests.')
print(
f'[!]Cookies file {cookies_filepath} was updated {cdays} days ago, it will not be used for HTTP requests.')

try:
javdb_url = 'https://' + javdb_site + '.com/search?q=' + number + '&f=all'
Expand Down

0 comments on commit 75b7188

Please sign in to comment.