summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorOmar Roth <omarroth@protonmail.com>2020-03-30 14:27:07 -0500
committerOmar Roth <omarroth@protonmail.com>2020-03-30 14:27:07 -0500
commitc97cdf551ecd4fb5d467bf260f7b97e05a6d62f8 (patch)
tree60b4d4a2754d8cd8e2666f8adfb72bc6afd83289 /src
parent80fc60b5e2d0d2c421b7993495398272c751ec3b (diff)
downloadinvidious-c97cdf551ecd4fb5d467bf260f7b97e05a6d62f8.tar.gz
invidious-c97cdf551ecd4fb5d467bf260f7b97e05a6d62f8.tar.bz2
invidious-c97cdf551ecd4fb5d467bf260f7b97e05a6d62f8.zip
Refactor extract_plid
Diffstat (limited to 'src')
-rw-r--r--src/invidious/trending.cr34
1 files changed, 7 insertions, 27 deletions
diff --git a/src/invidious/trending.cr b/src/invidious/trending.cr
index 3a9c6935..017c42f5 100644
--- a/src/invidious/trending.cr
+++ b/src/invidious/trending.cr
@@ -39,33 +39,13 @@ def fetch_trending(trending_type, region, locale)
end
def extract_plid(url)
- wrapper = HTTP::Params.parse(URI.parse(url).query.not_nil!)["bp"]
-
- wrapper = URI.decode_www_form(wrapper)
- wrapper = Base64.decode(wrapper)
-
- # 0xe2 0x02 0x2e
- wrapper += 3
-
- # 0x0a
- wrapper += 1
-
- # Looks like "/m/[a-z0-9]{5}", not sure what it does here
-
- item_size = wrapper[0]
- wrapper += 1
- item = wrapper[0, item_size]
- wrapper += item.size
-
- # 0x12
- wrapper += 1
-
- plid_size = wrapper[0]
- wrapper += 1
- plid = wrapper[0, plid_size]
- wrapper += plid.size
-
- plid = String.new(plid)
+ plid = URI.parse(url)
+ .try { |i| HTTP::Params.parse(i.query.not_nil!)["bp"] }
+ .try { |i| URI.decode_www_form(i) }
+ .try { |i| Base64.decode(i) }
+ .try { |i| IO::Memory.new(i) }
+ .try { |i| Protodec::Any.parse(i) }
+ .try { |i| i["44:0:embedded"]["2:1:string"].as_s }
return plid
end