Refactor extract_plid

This commit is contained in:
Omar Roth 2020-03-30 14:27:07 -05:00
parent 80fc60b5e2
commit c97cdf551e
No known key found for this signature in database
GPG key ID: B8254FB7EC3D37F2

View file

@ -39,33 +39,13 @@ def fetch_trending(trending_type, region, locale)
end end
def extract_plid(url) def extract_plid(url)
wrapper = HTTP::Params.parse(URI.parse(url).query.not_nil!)["bp"] plid = URI.parse(url)
.try { |i| HTTP::Params.parse(i.query.not_nil!)["bp"] }
wrapper = URI.decode_www_form(wrapper) .try { |i| URI.decode_www_form(i) }
wrapper = Base64.decode(wrapper) .try { |i| Base64.decode(i) }
.try { |i| IO::Memory.new(i) }
# 0xe2 0x02 0x2e .try { |i| Protodec::Any.parse(i) }
wrapper += 3 .try { |i| i["44:0:embedded"]["2:1:string"].as_s }
# 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)
return plid return plid
end end