Last active
November 5, 2025 13:28
-
-
Save ykla/91e27db14e68ba60903e97fe1c437246 to your computer and use it in GitHub Desktop.
刮削参考
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env zsh | |
| zmodload zsh/mathfunc | |
| typeset -r target_dir="/home/dl/media/pian/电影" | |
| typeset -r target_tvdir="/home/dl/media/pian/剧集" | |
| typeset -r tmdb_token="eyJhb" | |
| typeset -r authheader="Authorization: Bearer $tmdb_token" | |
| # 查找缺少top.md的子目录basename | |
| typeset -a missing_dirs missing_tvdirs | |
| for dir in $target_dir/*(/N); do | |
| [[ -f $dir/top.md ]] || missing_dirs+=(${dir:t}) | |
| done | |
| for dir in $target_tvdir/*(/N); do | |
| [[ -f $dir/top.md ]] || missing_tvdirs+=(${dir:t}) | |
| done | |
| # 输出结果 | |
| print_missing(){ | |
| local type=$1 array=(${(P)@[2]}) | |
| if (( $#array ));then | |
| print -l "${type} - 缺少 top.md 文件:" $array | |
| else | |
| print "${type}:都包含 top.md 文件" | |
| fi | |
| } | |
| #print_missing "电影" missing_dirs | |
| #print_missing "剧集" missing_tvdirs | |
| # 用dnschecker查找dns,防dns污染 | |
| upd=$(( rand48() * 1000 +rand48() * 1000 )) | |
| dnschecker_csrf_token=$( curl -s "https://dnschecker.org/ajax_files/gen_csrf.php?upd=$upd" -H "Referer: https://dnschecker.org/" |jq -r '.csrf') | |
| ips=$(curl -s --url "https://dnschecker.org/ajax_files/api/1/A/api.themoviedb.org?dns_key=ip&dns_value=4&cd_flag=1" -H "csrftoken: $dnschecker_csrf_token" -H "Referer: https://dnschecker.org/" | jq -r '.result.ips') | |
| dnsip="api.themoviedb.org:443:${ips%%<br*},${ips##*>}" | |
| function searchmovie { | |
| input_string="$1" | |
| name=${input_string%.*} | |
| year=${input_string##*.} | |
| echo -n "search $name:" | |
| [[ $input_string == $name ]] && year="" | |
| querystr=$(echo -n "$name" | xxd -plain | tr -d '\n' | sed -E 's/(..)/%\1/g') | |
| requrl='https://api.themoviedb.org/3/search/movie?language=zh-CN&query='"$querystr" | |
| if [[ -n "$year" ]];then | |
| requrl="$requrl""&year=$year" | |
| fi | |
| r="" | |
| r=$(curl -s --request GET --url "$requrl" -H "$authheader" -H "Accept: application/json" --resolve "$dnsip") | |
| rcount=$(echo $r| jq -r ' .total_results') | |
| if (( $rcount > 0 ));then | |
| echo "get $name" | |
| id=$(echo $r|jq '.results[0].id') | |
| detail_url='https://api.themoviedb.org/3/movie/'$id'?language=zh-CN' | |
| detail=$(curl -s --request GET --url "$detail_url" -H "$authheader" -H "Accept: application/json" --resolve "$dnsip") | |
| staff_url="https://api.themoviedb.org/3/movie/"$id"/credits?language=zh-CN" | |
| staff=$(curl -s --request GET --url "$staff_url" -H "$authheader" -H "Accept: application/json" --resolve "$dnsip") | |
| echo $detail| jq -r '"\n\n"+"# "+(.title)+"\n\n"+"原名: "+ .original_title+"\n\n"+"语言: "+([.spoken_languages[].name]|join(","))+"\n\n"+"发行日期: "+.release_date+"\n\n"+"类型: "+([.genres[].name]|join(","))+"\n\n"' > $target_dir/$input_string/top.md | |
| echo "导演: " >> $target_dir/$input_string/top.md | |
| echo $staff| jq -r '[[.crew[]|select(.known_for_department=="Directing")][].name]|unique|join(",")'>> $target_dir/$input_string/top.md | |
| echo "\n\n编剧: " >> $target_dir/$input_string/top.md | |
| echo $staff| jq -r '[[.crew[]|select(.known_for_department=="Writing")][].name]|join(",")'>> $target_dir/$input_string/top.md | |
| echo "\n\n演员: " >> $target_dir/$input_string/top.md | |
| echo $staff| jq -r '[[.cast[]|select(.known_for_department=="Acting")|select(.character|contains("uncredited")|not)][]|.name]|join(",")'>> $target_dir/$input_string/top.md | |
| echo $detail |jq -r '"\n\n简介: "+.overview' >> $target_dir/$input_string/top.md | |
| else | |
| echo "get nothing!" | |
| fi | |
| } | |
| function searchtv { | |
| input_string="$1" | |
| name=${input_string%.*} | |
| season=${input_string##*.} | |
| echo -n "search $name:" | |
| [[ $input_string == $name ]] && season="" | |
| [[ $season =~ '^s(0*)([0-9]+)$' ]] && season=${match[2]} && season=${season##0} | |
| querystr=$(echo -n "$name" | xxd -plain | tr -d '\n' | sed -E 's/(..)/%\1/g') | |
| requrl="https://api.themoviedb.org/3/search/tv?include_adult=false&language=zh-CN&page=1&query="$querystr | |
| r="" | |
| r=$(curl -s --request GET --url "$requrl" -H "$authheader" -H "Accept: application/json" --resolve "$dnsip") | |
| rcount=$(echo -E "$r"| jq ' .total_results') | |
| if (( $rcount > 0 ));then | |
| echo "get $name" | |
| id=$(echo -E $r|jq '.results[0].id') | |
| detail_url='https://api.themoviedb.org/3/tv/'$id'?language=zh-CN' | |
| detail=$(curl -s --request GET --url "$detail_url" -H "$authheader" -H "Accept: application/json" --resolve "$dnsip") | |
| echo -E "$detail"|jq -r '.seasons|length' | |
| echo -E "$detail"|jq -r '"\n\n"+"# "+.name+"\n\n"+"简介: "+.overview' > $target_tvdir/$input_string/top.md | |
| else | |
| echo "get nothing!" | |
| fi | |
| } | |
| for v in $missing_dirs;do | |
| searchmovie "$v" | |
| done | |
| for v in $missing_tvdirs;do | |
| searchtv "$v" | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment