1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
| #!/bin/bash liverc=""$HOME"/.liverc" url='https://api.live.bilibili.com/room/v1/Room/get_status_info_by_uids' greeting='GET DA⭐ZE' bye='Enjoy Yourself!!' sorry='DAMEDAYO!' tip='Press Enter To Exit...' append_tip='Using Options:'
while IFS=' ' read name ID; do table+=(["$ID"]="$name") done < "$liverc"
printf "\e[35m%s\e[0m\n" "Requesting..." respond=$(curl -s4 \ 'https://api.live.bilibili.com/room/v1/Room/get_status_info_by_uids' \ -H 'Content-Type: application/json' \ -d '{"uids": ['$(IFS=,; echo "${!table[*]}")']}') IDs=($(echo $respond | jq '.["data"]| 'keys'' | sed -e 's/"//g' -e 's/,/ /g' -e 's/\[//g' -e 's/\]//g')) printf "\e[35m%s\e[0m\n" "$greeting"
count=1 for ID in ${IDs[@]} ; do result=$(echo $respond | jq '.["data"] | .["'${ID}'"] | [.live_status, .title, .live_time, .room_id, .short_id]') title=$(echo $result | sed -e 's/.*"\(.*\)".*/\1/' -e 's/"//g' -e 's/"//g' -e 's/【/「/g' -e 's/】/」/g') result=$(echo $result | sed -e 's/".*", //g' -e 's/, / /g' -e "s/\[//g" -e 's/\]//g') IFS=' ' read live_status live_time room_id short_id<<< $result if [[ ${live_status} == 1 || $1 == '-p' ]]; then if [[ ${short_id} != 0 ]]; then room_id=${short_id}; fi live_time=$(date -d @$live_time +"%H:%M:%S") buffer+='printf "%d\t%s\t\e[90m%s\e[0m\t\e[32m%s\e[0m\t%s\n" "'$count'" "'${table["${ID}"]}'" "'${title}'" "'${live_time}'" "'${room_id}'";' room_ids+=($room_id) count=$((${count}+1)) fi done
if [[ $buffer != '' ]] then buffer='printf "\e[34mNO\tNickname\tTitle\tStart\tRoom_ID\n\e[0m";'$buffer eval "$buffer" | column -t -s $'\t' if [[ $1 != '' ]]; then if [[ $1 == '-p' ]]; then printf "\e[35m%s\e[0m\n" "$bye" exit 0 elif [[ $1 == '-a' ]]; then my_opt="-a"" ""${*:2}" printf "\e[34m%s%s\e[0m\n" "$append_tip" "${*:2}" fi fi if [[ ${#room_ids[@]} != 0 ]]; then let total=${#room_ids[@]} printf "\e[35m%s\e[0m\n" "choose..." read -a choices if [[ $(echo $choices | grep -E 'a|A') != '' ]]; then choices="$(seq -s ' ' 0 $(($total - 1)))" fi for choice in ${choices[@]}; do if [[ $choice =~ ^[0-9]+$ ]] && [[ $choice -le ${#room_ids[@]} ]]; then run="${room_ids[$(($choice - 1))]}"" ""${my_opt}" printf "\e[35mbili-live %s\e[0m\n" "$run" exec bili-live ${run} & fi done printf "\e[35m%s\e[0m\n" "$bye" fi else printf "\e[35m%s\e[0m\n" "$sorry" printf "\e[35m%s\e[0m\n" "$tip" fi read
|