Class: SaveTube
- Inherits:
-
Object
- Object
- SaveTube
- Defined in:
- lib/savetube_downloader.rb
Instance Attribute Summary collapse
-
#formats ⇒ Object
readonly
Returns the value of attribute formats.
-
#output ⇒ Object
readonly
Returns the value of attribute output.
-
#shortId ⇒ Object
readonly
Returns the value of attribute shortId.
-
#shortUrl ⇒ Object
readonly
Returns the value of attribute shortUrl.
Instance Method Summary collapse
-
#initialize(url = nil, formats = nil, path = nil) ⇒ SaveTube
constructor
A new instance of SaveTube.
- #Main ⇒ Object
- #save_tubes ⇒ Object
Constructor Details
#initialize(url = nil, formats = nil, path = nil) ⇒ SaveTube
Returns a new instance of SaveTube.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/savetube_downloader.rb', line 13 def initialize(url=nil, formats=nil, path=nil) @shortUrl = url @host = "https://ytshorts.savetube.me/" @api = "https://api.savetube.me" @headers = { "Host":"api.savetube.me", "User-Agent":"Mozilla/5.0 (Linux; Android 11; Infinix X6810 Build/RP1A.200720.011;) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/102.0.5005.78 Mobile Safari/537.36", "Accept": "*/*", "Origin": @host, "Referer": @host } @output = !path.nil? ? path : File.realpath(File.dirname(".")) + "/" # set default path where u running bin file @formats = !formats.nil? ? formats : 'video' @shortId = url.match(%r"shorts\/([\w]+)").to_s end |
Instance Attribute Details
#formats ⇒ Object (readonly)
Returns the value of attribute formats.
12 13 14 |
# File 'lib/savetube_downloader.rb', line 12 def formats @formats end |
#output ⇒ Object (readonly)
Returns the value of attribute output.
12 13 14 |
# File 'lib/savetube_downloader.rb', line 12 def output @output end |
#shortId ⇒ Object (readonly)
Returns the value of attribute shortId.
12 13 14 |
# File 'lib/savetube_downloader.rb', line 12 def shortId @shortId end |
#shortUrl ⇒ Object (readonly)
Returns the value of attribute shortUrl.
12 13 14 |
# File 'lib/savetube_downloader.rb', line 12 def shortUrl @shortUrl end |
Instance Method Details
#Main ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/savetube_downloader.rb', line 54 def Main puts "\n [savetube] downloading webpage: #{@shortId}" data = save_tubes if (!data.nil?) puts " [savetube] Title: #{data['title']}\n [savetube] List quality: " puts data["res"].each_with_index do | label, index | puts " (#{index+1}). #{label}" end puts quality = prompt(" [savetube] Set : ").to_i if (quality - 1) < data['res'].length res = data['res'][quality - 1].split('->')[0].strip filename = data['title'] + (@formats == 'audio' ? '.mp3' : '.mp4') puts " [savetube] downloading files: #{filename}" get_link = loadJson(getPage("#{@api}/download/#{@formats}/#{res}/#{data['key']}", headers=@headers).to_s) if (get_link['status'] and get_link['message'].to_i == 200) download_stream( get_link['data']['downloadUrl'], filename, @output ) puts " [savetube] file saved in: #{@output}#{filename}" else abort(data.to_s) end else abort(" [savetube-err] Must < #{data['res'].length}!!") end else abort(data.to_s) end end |
#save_tubes ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/savetube_downloader.rb', line 29 def save_tubes page = getPage("#{@api}/info", @headers, {'url': @shortUrl}) js = loadJson(page.to_s) if (js["status"] and js['message'].to_i == 200) if (["audio","video"].include?(@formats)) response = { "key" => js['data']['key'], "title" => js['data']['title'], "res" => js['data']["#{@formats}_formats"].map { | v | "%s -> %s" % [ v.has_key?("height") ? v['height'] : v['quality'], v['label'] ] } } response["res"] = (@formats == 'video' ? response['res'].slice(1...) : response['res']) return response else return nil end else abort(js.to_s) end end |