summaryrefslogtreecommitdiff
path: root/.local
diff options
context:
space:
mode:
authorxyz <gky44px1999@gmail.com>2021-09-04 01:36:24 -0700
committerxyz <gky44px1999@gmail.com>2021-09-04 01:36:24 -0700
commit85c585e2fa982140eacde2ffe5a8b4f8798d60eb (patch)
treec7b3551aba294b7234bb7868aa341fe6897ee14e /.local
parentc3d8471dc1301a67814f64baf8b520c5d6fea5e3 (diff)
refactor
Diffstat (limited to '.local')
-rwxr-xr-x.local/bin/curlkg16
-rwxr-xr-x.local/bin/curlncm18
2 files changed, 10 insertions, 24 deletions
diff --git a/.local/bin/curlkg b/.local/bin/curlkg
index 2b6f4f91..dfd7d077 100755
--- a/.local/bin/curlkg
+++ b/.local/bin/curlkg
@@ -6,7 +6,6 @@
homepage_url='https://node.kg.qq.com/cgi/fcgi-bin/kg_ugc_get_homepage'
music_url='https://node.kg.qq.com/cgi/fcgi-bin/fcg_get_play_url'
-#tab_space=$(printf '\t')
# num seems only 8 and 15 works
num=15
tmp_json_file='/tmp/curlkg.json'
@@ -41,19 +40,4 @@ done
# how to show less aria2c stdout?
jq -r '.data.ugclist[]|"'"$music_url"'?shareid=\(.shareid)\n out=\(.title)_\(.time).m4a"' "$tmp_json_file" | aria2c -d "$download_dir" --auto-file-renaming=false -i-
-
-## ytfzf way with curl only
-#data="$(jq -r '.data.ugclist[]|[.shareid,.time,.title]|@tsv' "$tmp_json_file")"
-#while IFS=$tab_space read -r shareid time title; do
-# filename="$download_dir/${title}_$time.m4a"
-# if ! [ -e "$filename" ]; then
-# # may need parallel download and control pid for curl to be faster
-# curl -L -G --data-urlencode shareid="$shareid" "$music_url" > "$filename"
-# else
-# echo "$filename exist"
-# fi
-#done <<- EOF
-#$data
-#EOF
-
rm "$tmp_json_file"
diff --git a/.local/bin/curlncm b/.local/bin/curlncm
index 3e7bc70e..c240f6e2 100755
--- a/.local/bin/curlncm
+++ b/.local/bin/curlncm
@@ -13,6 +13,7 @@
# trial and error to get dj_max, don't know why, maybe because it is 2^31 and it is the size limit of whatever type of the variable
dj_max=2147483647
dl_urls_tmp='/tmp/curlncm_dl_urls'
+# printf 'e82ckenh8dichen8' | hexdump -ve '/1 "%02x"'
key='653832636b656e683864696368656e38'
url='/api/song/enhance/player/url'
request_id=$(date +'%s%3N')_$(seq -w 1 1000 | shuf -n1)
@@ -35,7 +36,7 @@ while getopts a:i:r: opt; do
aid="$OPTARG"
flag=1;;
i) [ "$flag" -eq 1 ] && die "options a,i,r are mutually exclusive"
- id="$OPTARG"
+ ids="$OPTARG"
flag=1;;
r) [ "$flag" -eq 1 ] && die "options a,i,r are mutually exclusive"
rid="$OPTARG"
@@ -49,9 +50,9 @@ shift $((OPTIND-1))
download_dir="${1:-"$PWD"}"
[ -d "$download_dir" ] || mkdir -p "$download_dir"
-if [ -n "$id" ]; then
+if [ -n "$ids" ]; then
# temporary solution, can improve by auto curl names
- data="$(printf '%s\t%s' "$id" 'songname')"
+ data="$(echo "$ids" | tr ',' '\n' | awk '{printf("%s\t%s\n",$0,"songname")}')"
else
# need to consider second page of djradio
if [ -n "$rid" ]; then
@@ -59,18 +60,19 @@ else
elif [ -n "$aid" ]; then
data="$(curl -s -G --data-urlencode id="$aid" 'https://music.163.com/artist' | grep -E '\[\{.*\}\]' | sed -e 's/.*>\[{/\[{/' -e 's/}\]<.*/}\]/' | jq -r '.[]|[.id,.name]|@tsv' | sort | tr '/' '_')"
fi
+ # with only awk, has a ',' at the end, need to remove that, not sure how to do that in awk, not sure if it's faster?
+ #ids="$(echo "$data" | awk -F'\t' '{printf "%s,", $1}')"
+ ids="$(echo "$data" | awk -F'\t' '{print $1}' | paste -sd ',')"
fi
-# with only awk, has a ',' at the end, need to remove that, not sure how to do that in awk, not sure if it's faster?
-#ids="$(echo "$data" | awk -F'\t' '{printf "%s,", $1}')"
-ids="$(echo "$data" | awk -F'\t' '{print $1}' | paste -sd ',')"
+echo "$data"
# I don't fully understand following several lines of code
# I rewrite TianyiShi2001's python script, he rewrites NeteaseCloudMusicApi
text="$(printf '{"ids":"[%s]","br":999000,"header":{%s}}' "$ids" "$cookie")"
message="nobody${url}use${text}md5forencrypt"
-digest="$(printf '%s' "$message" | openssl dgst -md5 -hex | awk '{print $2}')"
+digest="$(printf "$message" | openssl dgst -md5 -hex | awk '{print $2}')"
params="$(printf '%s-36cd479b6b5-%s-36cd479b6b5-%s' "$url" "$text" "$digest")"
-encrypted_params="$(printf '%s' "$params" | openssl enc -aes-128-ecb -K "$key" | hexdump -ve '/1 "%02X"')"
+encrypted_params="$(printf "$params" | openssl enc -aes-128-ecb -K "$key" | hexdump -ve '/1 "%02X"')"
# curl default user agent header seems not working
curl -s -A "$user_agent" -d params="$encrypted_params" 'https://interface3.music.163.com/eapi/song/enhance/player/url' | jq -r '.data|sort_by(.id)|.[].url' > "$dl_urls_tmp"
[ "$(echo "$data" | wc -l)" -ne "$(wc -l < "$dl_urls_tmp")" ] && die "number of download uls doesn't match request"