randomyoutube 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,10 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2012 Daniel P. Clark & 6ft Dan(TM)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
10
+
data/README ADDED
@@ -0,0 +1,18 @@
1
+ RandomYouTube
2
+ by Daniel P. Clark
3
+
4
+ Require's linux with the 'shuf' executable in path and your words dictionary at /usr/share/dict/words
5
+
6
+ gem install randomyoutube --no-rdoc --no-ri
7
+
8
+ Description
9
+ * Grab 3 words randomly from the system dictionary and pull a youtube video link with those words.
10
+
11
+ require 'randomyoutube'
12
+
13
+ RandomYouTube::human # One search. Human readable output on success, or failure.
14
+ RandomYouTube::human_must # Search until success, human readable output.
15
+ RandomYouTube::pretty # One search. Array on success, nil on failure.
16
+ RandomYouTube::pretty_must # Search until success, returns array.
17
+ RandomYouTube::raw # One search. Array on success, nil on failure.
18
+ RandomYouTube::raw_must # Search until success, returns array.
data/bin/randomyoutube ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/ruby
2
+ require 'rubygems'
3
+ require 'randomyoutube'
4
+ RandomYouTube::human_must
@@ -0,0 +1,68 @@
1
+ # RandomYouTube
2
+ # Authored by: Daniel P. Clark
3
+ # Date: 11-24-2012
4
+ # Requires Linux
5
+ require 'rubygems'
6
+ require 'nokogiri'
7
+ require 'open-uri'
8
+ require 'mightystring'
9
+ require 'randomyoutube/version'
10
+
11
+ module RandomYouTube
12
+ ACC_CHARS = (('a'..'z').to_a + ('A'..'Z').to_a + ('0'..'9').to_a + ["\n"]).flatten.join
13
+ REQUESTOR = "https://gdata.youtube.com/feeds/api/videos?q="
14
+ THREE_WORDS = "shuf -n 3 /usr/share/dict/words"
15
+
16
+ attr :mywords
17
+
18
+ def self.local_exec
19
+ @mywords = `#{THREE_WORDS}`
20
+ @mywords = @mywords.strip_byac(ACC_CHARS).split("\n")
21
+ urlsearch = REQUESTOR + @mywords.join('+')
22
+ Nokogiri::XML(open(urlsearch))
23
+ end
24
+
25
+ def self.human
26
+ page = local_exec
27
+ puts "Your search results for: #{@mywords.join(', ')}"
28
+ if page.at('openSearch|totalResults').text.to_i > 0
29
+ puts "Title: #{page.css('entry title').first.text}"
30
+ puts "Link: #{page.css('entry link').first['href']}"
31
+ else
32
+ puts "There are no results for your search."
33
+ end
34
+ end
35
+
36
+ def self.pretty
37
+ page = local_exec
38
+ if page.at('openSearch|totalResults').text.to_i > 0
39
+ return ["Your search results for: #{@mywords.join(', ')}", "Title: #{page.css('entry title').first.text}", "Link: #{page.css('entry link').first['href']}"]
40
+ else
41
+ return nil
42
+ end
43
+ end
44
+
45
+ def self.raw
46
+ page = local_exec
47
+ if page.at('openSearch|totalResults').text.to_i > 0
48
+ return [@mywords.join(', '), page.css('entry title').first.text, page.css('entry link').first['href']]
49
+ else
50
+ return nil
51
+ end
52
+ end
53
+
54
+ def self.human_must
55
+ output = pretty while output == nil
56
+ puts output
57
+ end
58
+
59
+ def self.pretty_must
60
+ output = pretty while output == nil
61
+ return output
62
+ end
63
+
64
+ def self.raw_must
65
+ output = raw while output == nil
66
+ return output
67
+ end
68
+ end # module RandomYouTube
@@ -0,0 +1,3 @@
1
+ module RandomYouTube
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: randomyoutube
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Daniel P. Clark / 6ftDan(TM)
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-11-25 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: mightystring
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 0
31
+ version: "0"
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: nokogiri
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ hash: 3
43
+ segments:
44
+ - 0
45
+ version: "0"
46
+ type: :runtime
47
+ version_requirements: *id002
48
+ description: Grab a random youtube video link from any linux box. Parsable and human readable.
49
+ email: webmaster@6ftdan.com
50
+ executables:
51
+ - randomyoutube
52
+ extensions: []
53
+
54
+ extra_rdoc_files:
55
+ - README
56
+ files:
57
+ - bin/randomyoutube
58
+ - lib/randomyoutube/version.rb
59
+ - lib/randomyoutube.rb
60
+ - README
61
+ - LICENSE
62
+ homepage: http://www.github.com/danielpclark/RandomYouTube
63
+ licenses:
64
+ - The MIT License (MIT)
65
+ post_install_message: Enjoy RandomYouTube!
66
+ rdoc_options:
67
+ - --main
68
+ - README
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ hash: 3
77
+ segments:
78
+ - 0
79
+ version: "0"
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ hash: 3
86
+ segments:
87
+ - 0
88
+ version: "0"
89
+ requirements: []
90
+
91
+ rubyforge_project:
92
+ rubygems_version: 1.8.24
93
+ signing_key:
94
+ specification_version: 3
95
+ summary: Grab a random youtube video link from any linux box.
96
+ test_files: []
97
+