|
1 | 1 | #!/usr/bin/env sh |
2 | 2 |
|
3 | | -LOBSTER_VERSION="4.5.7" |
| 3 | +LOBSTER_VERSION="4.5.8" |
4 | 4 |
|
5 | 5 | ### General Variables ### |
6 | 6 | config_file="$HOME/.config/lobster/lobster_config.sh" |
|
18 | 18 | # These are not arbitrary, but determined by rofi kb-custom-1 and kb-custom-2 exit codes |
19 | 19 | BACK_CODE=10 |
20 | 20 | FORWARD_CODE=11 |
| 21 | +API_URL="https://dec.eatmynerds.live" |
21 | 22 |
|
22 | 23 | ### Notifications ### |
23 | 24 | command -v notify-send >/dev/null 2>&1 && notify="true" || notify="false" # check if notify-send is installed |
|
329 | 330 | rc="$BACK_CODE" |
330 | 331 | choice=${choice#*"$nl"} |
331 | 332 | ;; |
332 | | - "$nl"*) choice=${choice#"$nl"} ;; |
| 333 | + "$nl"*) choice=${choice#*"$nl"} ;; |
333 | 334 | *) exit 1 ;; |
334 | 335 | esac |
335 | 336 | fi |
|
493 | 494 | rc="$BACK_CODE" |
494 | 495 | choice=${choice#*"$nl"} |
495 | 496 | ;; |
496 | | - "$nl"*) choice=${choice#"$nl"} ;; |
| 497 | + "$nl"*) choice=${choice#*"$nl"} ;; |
497 | 498 | *) exit 1 ;; |
498 | 499 | esac |
499 | 500 | ueberzugpp cmd -s "$LOBSTER_UEBERZUG_SOCKET" -a exit |
|
514 | 515 | rc="$BACK_CODE" |
515 | 516 | choice=${choice#*"$nl"} |
516 | 517 | ;; |
517 | | - "$nl"*) choice=${choice#"$nl"} ;; |
| 518 | + "$nl"*) choice=${choice#*"$nl"} ;; |
518 | 519 | *) exit 1 ;; |
519 | 520 | esac |
520 | 521 | fi |
@@ -563,23 +564,79 @@ EOF |
563 | 564 | } |
564 | 565 |
|
565 | 566 | extract_from_embed() { |
566 | | - json_data=$(curl -s "https://dec.eatmynerds.live/?url=${embed_link}") |
| 567 | + challenge_response=$(curl -s "${API_URL}/challenge") |
| 568 | + |
| 569 | + if [ -z "$challenge_response" ]; then |
| 570 | + send_notification "ERROR: Failed to get a response from the API server." |
| 571 | + return 1 |
| 572 | + fi |
| 573 | + |
| 574 | + payload=$(printf "%s" "${challenge_response}" | sed -n 's/.*"payload":"\([^"]*\)".*/\1/p') |
| 575 | + signature=$(printf "%s" "${challenge_response}" | sed -n 's/.*"signature":"\([^"]*\)".*/\1/p') |
| 576 | + difficulty=$(printf "%s" "${challenge_response}" | sed -n 's/.*"difficulty":\([0-9]*\).*/\1/p') |
| 577 | + challenge=$(printf "%s" "${payload}" | cut -d'.' -f1) |
| 578 | + |
| 579 | + if [ -z "$payload" ] || [ -z "$signature" ] || [ -z "$difficulty" ]; then |
| 580 | + send_notification "FATAL: Could not parse the API challenge response." |
| 581 | + return 1 |
| 582 | + fi |
| 583 | + |
| 584 | + prefix="" |
| 585 | + i=0 |
| 586 | + while [ "$i" -lt "$difficulty" ]; do |
| 587 | + prefix="${prefix}0" |
| 588 | + i=$((i + 1)) |
| 589 | + done |
| 590 | + |
| 591 | + nonce=0 |
| 592 | + while true; do |
| 593 | + text_to_hash="${challenge}${nonce}" |
| 594 | + hash_val=$(printf "%s" "${text_to_hash}" | sha256sum | awk '{print $1}') |
| 595 | + |
| 596 | + case "$hash_val" in |
| 597 | + "${prefix}"*) |
| 598 | + break |
| 599 | + ;; |
| 600 | + *) ;; |
| 601 | + esac |
| 602 | + |
| 603 | + nonce=$((nonce + 1)) |
| 604 | + done |
| 605 | + |
| 606 | + final_url="${API_URL}/?url=${embed_link}&payload=${payload}&signature=${signature}&nonce=${nonce}" |
| 607 | + json_data=$(curl -s "${final_url}") |
| 608 | + |
| 609 | + case "$json_data" in |
| 610 | + *"error"*) |
| 611 | + api_error_msg=$(printf "%s" "$json_data" | $sed -n 's/.*"error":"\([^"]*\)".*/\1/p') |
| 612 | + send_notification "API Error: $api_error_msg" |
| 613 | + return 1 |
| 614 | + ;; |
| 615 | + *) ;; |
| 616 | + esac |
| 617 | + |
567 | 618 | video_link=$(printf "%s" "$json_data" | $sed -nE "s_.*\"file\":\"([^\"]*\.m3u8)\".*_\1_p" | head -1) |
568 | 619 |
|
569 | | - [ -n "$quality" ] && video_link=$(printf "%s" "$video_link" | $sed -e "s|/playlist.m3u8|/$quality/index.m3u8|") |
| 620 | + [ -n "$quality" ] && video_link=$(printf "%s" "$video_link" | sed -e "s|/playlist.m3u8|/$quality/index.m3u8|") |
570 | 621 |
|
571 | 622 | [ "$json_output" = "true" ] && printf "%s\n" "$json_data" && exit 0 |
| 623 | + |
572 | 624 | if [ "$no_subs" = "true" ]; then |
573 | 625 | send_notification "Continuing without subtitles" |
574 | 626 | else |
575 | | - subs_links=$(printf "%s" "$json_data" | tr "{}" "\n" | $sed -nE "s@.*\"file\":\"([^\"]*)\",\"label\":\"(.$subs_language)[,\"\ ].*@\1@p") |
576 | | - subs_arg="--sub-file" |
577 | | - num_subs=$(printf "%s" "$subs_links" | wc -l) |
578 | | - if [ "$num_subs" -gt 0 ]; then |
579 | | - subs_links=$(printf "%s" "$subs_links" | $sed -e "s/:/\\$path_thing:/g" -e "H;1h;\$!d;x;y/\n/$separator/" -e "s/$separator\$//") |
580 | | - subs_arg="--sub-files" |
| 627 | + subs_links=$(printf "%s" "$json_data" | tr '{' '\n' | $sed -n "s/.*\"file\":\"\([^\"]*\)\".*\"label\":\"[^\"]*${subs_language}[^\"]*\".*/\1/Ip") |
| 628 | + |
| 629 | + if [ -z "$subs_links" ]; then |
| 630 | + send_notification "No subtitles found for language '$subs_language'" |
| 631 | + subs_arg="" |
| 632 | + else |
| 633 | + subs_arg="--sub-file" |
| 634 | + num_subs=$(printf "%s" "$subs_links" | wc -l) |
| 635 | + if [ "$num_subs" -gt 0 ]; then |
| 636 | + subs_links=$(printf "%s" "$subs_links" | sed -e "s/:/\\$path_thing:/g" -e "H;1h;\$!d;x;y/\n/$separator/" -e "s/$separator\$//") |
| 637 | + subs_arg="--sub-files" |
| 638 | + fi |
581 | 639 | fi |
582 | | - [ -z "$subs_links" ] && send_notification "No subtitles found" |
583 | 640 | fi |
584 | 641 | } |
585 | 642 |
|
|
921 | 978 | fi |
922 | 979 | else |
923 | 980 | if [ "$image_preview" = "true" ]; then |
924 | | - download_video "$video_link" "$title - $season_title - $episode_title" "$download_dir" "$json_data" "$images_cache_dir/ $title ($media_type) $media_id.jpg" & |
| 981 | + download_video "$video_link" "$title - $season_title - $episode_title" "$download_dir" "$json_data" "$images_cache_dir/ $title - $season_title - $episode_title ($media_type) $media_id.jpg" & |
925 | 982 | send_notification "Finished downloading" "5000" "$images_cache_dir/ $title - $season_title - $episode_title ($media_type) $media_id.jpg" "$title - $season_title - $episode_title" |
926 | 983 | else |
927 | 984 | download_video "$video_link" "$title - $season_title - $episode_title" "$download_dir" "$json_data" & |
|
0 commit comments