How to download video via viddl-rb? [closed] - ruby

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I want to download video files from youtube.com, according links from my database.
I found gem viddl-rb, but I see only console way to download in documentation - viddl-rb youtube.com/watch/myvideoid
How to download video, using require viddl-rb in console?

Please be warned that it may be against Youtube's ToS to download videos from Youtube; but anyways, following code might help you do it:
require 'open-uri'
require 'viddl-rb'
YouTubeLinks = %w[
https://www.youtube.com/watch?v=Z8wLQ3NCBgg
https://www.youtube.com/watch?v=QH2-TGUlwu4
]
youtube_hashes = YouTubeLinks.map do |link|
ViddlRb.get_urls_names(link).first
end
youtube_hashes.each do |yt|
puts "Downloading: #{yt[:name]}"
File.open(yt[:name], 'wb') do |video_file|
open(yt[:url]) { |video| video_file.write video.read }
end
end

Related

Plis I wish indications a site to train automated software testing [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 months ago.
Improve this question
describe 'Visit script' do
it 'visitar a pagina' do
puts "visitando a pagina"
visit "https://www.google.com/"
expect(page.title).to eql "Google"
end
Don't use the standard RSpec matchers with Capybara objects - the standard matchers don't have waiting/retrying behavior. Instead use the Capybara provided matchers
it 'visitar a pagina' do
puts "visitando a pagina"
visit "https://www.google.com/"
expect(page).to have_title("Google")
end

how to expand system path using ruby? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I'm trying to require modules in my app without using require ./module or require_relative.
I know that in python you can do:
import sys
sys.path.append("whatever")
Then, you can import every module in the "whatever" path.
I guess it is possible to do it in ruby as well, but couldn't figure out a better way than:
ENV["PATH"] += ':whatever'
What about
$LOAD_PATH.unshift('whatever')
$LOAD_PATH.append('whatever')
https://thoughtbot.com/blog/following-the-path

how to capture text from a web page with ruby [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I am running an automated test script written in Ruby in which I get a result page, I would like to capture some of the text on the page and print them in a file. Can anyone assist with this effort?
Like the comments say, use Nokogiri.
Install it with gem install nokogiri.
To print the first top-level heading from example.com:
require 'nokogiri'
require 'open-uri'
doc = Nokogiri::HTML(open("http://www.example.com/"))
puts doc.css("h1").first
For more information on finding the text you want, try this guide

Time difference compare to presence like Twitter in Ruby [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
Is there a gem or another easy way to get time difference compare to present time like Twitter?
Of course I can write it myself, but I don't want to reinvent the wheel.
If you are using rails, you could do
distance_of_time_in_words_to_now #user.created_at
#=> "15 days"
or
time_ago_in_words #post.created_at
#=> "about 13 hours"

Should I use File.write? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 5 years ago.
Improve this question
I recently run into problems converting a ruby script to .EXE because I had a File.write statement in it. The documentation doesn't mention the write method but when I do a
pp File.methods
it is there. So should I use File.write? In a normal Ruby script the following works
File.write("test.txt", "test")
But is it good practice and why doesn't the documentation mention it?
File.write is in fact IO.write (File is a child of IO) which can be verified by monkey-patching:
class IO
def IO.write
puts "IO's class method write was called."
end
end
File.write # outputs "IO's class method write was called."
It is very well in the documentation.
Thus, I see no reason not to use it.

Resources