summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2015-12-20 12:44:58 +0100
committertv <tv@krebsco.de>2015-12-20 12:44:58 +0100
commite1fe3c7c3ef7efcc82c537a647cfab6e65d532fb (patch)
treea65fb34dee06f7305770c5b08b4d6d36cbe3cef0
initial commit
-rwxr-xr-xsoundcloud82
1 files changed, 82 insertions, 0 deletions
diff --git a/soundcloud b/soundcloud
new file mode 100755
index 0000000..9e827cc
--- /dev/null
+++ b/soundcloud
@@ -0,0 +1,82 @@
+#! /bin/sh
+
+# Url Page -> Eff Play
+play_stream() {
+ echo "play: $1"
+ mpv "$(get_streams "$1" | head -1)"
+ play_stream "$(next_stream "$1")"
+}
+
+# Url Page -> Url Page
+next_stream() {
+ get_related "$1" | head -1
+}
+
+# Url Page -> Streams
+get_streams() {(
+ streams_url=$(streams_url "$(get "$1")")
+ get "$streams_url" | jq -r 'to_entries[] | "\(.key) \(.value)"' | grep -v ^preview | awk '{print$2}'
+)}
+
+# Url Page -> [Url Page]
+get_related() {(
+ page_url=$1
+ track_path=${page_url#https://soundcloud.com}
+ related_url=$1/recommended
+ related=$(get "$related_url")
+ echo "$related" | sed -n 's/<a itemprop="url" href="\([^"]*\)">/\ntrack_path \1\n/gp' \
+ | awk \
+ -v track_path="$track_path" \
+ '
+ ($1 == "track_path" && $2 != track_path) {print"https://soundcloud.com"$2}
+ '
+
+)}
+
+# Page -> Url Streams
+streams_url() {(
+ page=$1
+ app_url=$(app_url "$page")
+ app=$(get "$app_url")
+ public_api_host=$(public_api_host "$app")
+ stream_id=$(stream_id "$page")
+ client_id=$(client_id "$app")
+ streams_path=$(paths "$app" | sed -n "/streams$/{s/:id/$stream_id/p;T;q}")
+ app_version=$(app_version "$page")
+ streams_url="$public_api_host$streams_path?client_id=$client_id&app_version=$app_version"
+ echo "$streams_url"
+)}
+
+get() {
+ curl -fsS "$1"
+}
+
+# Page -> Url App
+app_url() {
+ echo "$1" | sed -n 's|.*"\(https:[^"]*/app-[^"]*\.js\)".*|\1|p'
+}
+
+# Page -> StreamId
+stream_id() {
+ echo "$1" | sed -n 's|.*"soundcloud://sounds:\([0-9]\+\)".*|\1|p;T;q'
+}
+
+# App -> ClientId
+client_id() {
+ echo "$1" | sed -n 's|.*\<client_id:"\([^"]\+\)".*|\1|p;T;q'
+}
+
+# Page -> AppVersion
+app_version() {
+ echo "$1" | sed -n 's|.*__sc_version\s*=\s*"\([^"]*\)".*|\1|p;T;q'
+}
+
+# App -> [PathPattern]
+paths() {
+ echo "$1" | sed -n 's|\<path:"[^"]*"|\n&\n|gp' | sed -n 's/^path:"\([^"]*\)"$/\1/p'
+}
+
+# App -> Url
+public_api_host() {
+ echo "$1" | sed -n 's|.*\<public_api_host:\s*"\([^"]*\)".*|\1|p;T;q'
+}