-
-
Save KrzaQ/41b47508d64f89d2d7f8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'httpclient' | |
require 'tk' | |
require 'json' | |
def getDataOverHttp(link) | |
http = HTTPClient.new(:agent_name => 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20100101 Firefox/25.0') | |
r = http.get(link) | |
raise r.status.to_s if r.status != 200 | |
return r.body | |
end | |
def dumpHash(h) | |
h.keys.each { |k| | |
puts "#{k} -> #{h[k]}" | |
} | |
end | |
def extract(v) | |
m = v.to_s.match /(\d+)/ | |
raise 'No number found in the string' unless m | |
ret = getDataOverHttp "http://www.tvp.pl/shared/cdn/tokenizer_v2.php?object_id=#{m[1].to_i}&sdt_version=1" | |
parsed = JSON.parse ret | |
parsed['formats'].to_a.each do |o| | |
m = o['url'].to_s.match /m3u8$/ | |
return o['url'].to_s if m | |
end | |
return 'Failed to find m3u8 link' | |
end | |
if __FILE__ == $0 | |
begin | |
root = TkRoot.new { | |
title "tvp stream link extractor" | |
width 400 | |
} | |
entry = TkEntry.new(root){ width 100 } | |
var = TkVariable.new("") | |
entry.textvariable(var){ | |
width "100%" | |
} | |
button = TkButton.new(root){ | |
text "magic" | |
command proc { | |
begin | |
result = extract var.value | |
var.value = result | |
rescue Exception => e | |
var.value = e.message | |
end | |
} | |
} | |
entry.pack() | |
button.pack() | |
Tk.mainloop() | |
rescue Exception => e | |
puts "Exception: #{e.message}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment