get_freaky 0.3.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cd9a568627ed1bfc123b1379ef94ac04b27f35c4
4
- data.tar.gz: 126773bf0a32042076d10ebc7994ae5e710fcd32
3
+ metadata.gz: 879240e6e90154c17f2dde2fd7a202e11669fb21
4
+ data.tar.gz: 58e08b94cb3a887cf007df433aa115da36eb7fb3
5
5
  SHA512:
6
- metadata.gz: fd8f6dad18d40da39937eab8b8dbfb8198afe4997e3498ec4763ee1a1e78777a71da77e874e1f3f57452f996fce60138d3b36fe8d8e657e8612976a80fc5e3f8
7
- data.tar.gz: b4aa75f699b37ddc9209aa867377a19c58401c64750190ae3b2e64626b13673b722c8a6f401d48ba50e115e85ff142591a5b95ed52eeb77a8bed0b2c820c1e99
6
+ metadata.gz: 3b57896d5b65dea702dd816c3be14858bc8ff0f083857d4a5fd596cbd83fb4dcdcb43ac4506e5396ef1869e0b5044a1e803e9e91e102bfb1308bae179de98499
7
+ data.tar.gz: 1f06ee9aa36eaa2178636732086644b99f4a17721f56b02c677e4640cd1e7b1a5f8e92c9a4d81c6c5b54d06cdb0d3515c56f6d2f377403e67c3d0f242467ff38
data/bin/get_freaky CHANGED
@@ -54,11 +54,17 @@ command :event do |c|
54
54
  c.summary = 'Shows the videos available from confreaks for an event (an instance of a conference in a particular year)'
55
55
  c.description = c.summary
56
56
  c.example 'Display information about the railsberry2013', 'get_freaky event railsberry2013'
57
+ c.example 'Download all the videos from railsberry2013', 'get_freaky event railsberry2013 --all'
57
58
  c.action do |args, options|
59
+
58
60
  unless args[0]
59
61
  puts `get_freaky conf --help`
60
62
  else
61
63
  event = Event.find(args[0])
64
+ if options.include "all"
65
+ event.download_all_videos!
66
+ break
67
+ end
62
68
  videos = event.video_list
63
69
  video_title = choose("Choose a talk to see more information about it:\n\n", *videos)
64
70
  video = Video.find(event.name, video_title)
@@ -68,6 +74,18 @@ command :event do |c|
68
74
  end
69
75
  end
70
76
 
77
+ command :download_event do |c|
78
+ c.syntax = 'get_freaky download_event EVENT_NAME [options]'
79
+ c.summary = 'Downloads all the confreaks videos for a particular event'
80
+ c.description = c.summary
81
+ c.example 'Download all the videos from RubyConf 2015', 'get_freaky download_event rubyconf2015'
82
+ c.action do |args, options|
83
+ event = Event.find(args[0])
84
+ event.download_all_videos!
85
+ end
86
+ end
87
+
88
+
71
89
  command :download do |c|
72
90
  c.syntax = 'get_freaky download VIDEO_NAME EVENT_NAME [options]'
73
91
  c.summary = 'Downloads a confreaks video locally using the viddl-rb library. Note that the "event name" given needs to be formatted in the same way as the listing show by the "event" command. Be sure to put quotes around video titles of multiple words and escape special exclamation points'
data/lib/get_freaky.rb CHANGED
@@ -3,8 +3,10 @@ require 'slugify'
3
3
  require 'viddl-rb'
4
4
 
5
5
  require_relative 'get_freaky/conference'
6
+ require_relative 'get_freaky/error_object'
6
7
  require_relative 'get_freaky/event'
8
+ require_relative 'get_freaky/info'
9
+ require_relative 'get_freaky/null_conference'
10
+ require_relative 'get_freaky/null_event'
11
+ require_relative 'get_freaky/version'
7
12
  require_relative 'get_freaky/video'
8
- require_relative "get_freaky/version"
9
- require_relative "get_freaky/info"
10
-
@@ -13,11 +13,7 @@ class Conference
13
13
  response = get("/conferences/#{name}.json")
14
14
  # TODO: I need to figure out a better way of dealing with 404 errors
15
15
  if response["status"] == 404
16
- self.new(
17
- "Not Found",
18
- "Not Found",
19
- "Not Found"
20
- )
16
+ NullConference.new("No conference was found with that name")
21
17
  elsif response.success?
22
18
  self.new(
23
19
  response["name"],
@@ -36,10 +32,14 @@ class Conference
36
32
  end
37
33
 
38
34
  def event_list
39
- if events == "Not Found"
40
- "There was no conference found by that name."
41
- else
35
+ if valid?
42
36
  events.map { |event| event["short_code"] }
37
+ else
38
+ "There was no conference found by that name."
43
39
  end
44
40
  end
41
+
42
+ def valid?
43
+ true
44
+ end
45
45
  end
@@ -0,0 +1,13 @@
1
+ class ErrorObject
2
+ def initialize(message)
3
+ @message = message
4
+ end
5
+
6
+ def valid?
7
+ false
8
+ end
9
+
10
+ def to_s
11
+ "Error: #{@message}"
12
+ end
13
+ end
@@ -5,12 +5,12 @@ class Event
5
5
  attr_accessor :short_code, :conference_name, :conference_id, :video_count, :date
6
6
 
7
7
  # TODO: I'm pretty sure that at this number of arguments it should just take a hash
8
- def initialize(short_code, conference_name, conference_id, video_count, date)
9
- self.short_code = short_code
10
- self.conference_name = conference_name
11
- self.conference_id = conference_id
12
- self.video_count = video_count
13
- self.date = date
8
+ def initialize(params = {})
9
+ self.short_code = params[:short_code]
10
+ self.conference_name = params[:conference_name]
11
+ self.conference_id = params[:conference_id]
12
+ self.video_count = params[:video_count]
13
+ self.date = params[:date]
14
14
  end
15
15
 
16
16
  # Alias short_code as name; "short_code" is consistent with the api, but "name" is easier to remember
@@ -25,23 +25,16 @@ class Event
25
25
  def self.find(short_code)
26
26
  response = get("/events/#{short_code}.json")
27
27
  if response["status"] == 404
28
- # TODO: The below is totally embarrassing...need to figure out a better way to handle this (though it's still better than nil)
29
- # Look into using NULL Objects?
30
- # Better exceptions?
31
- self.new(
32
- "Not Found",
33
- "Not Found",
34
- "Not Found",
35
- "Not Found",
36
- "Not Found"
37
- )
28
+ NullEvent.new("No event was found with that name")
38
29
  elsif response.success?
39
30
  self.new(
40
- response["short_code"],
41
- response["conference"]["name"],
42
- response["conference"]["id"],
43
- response["video_count"],
44
- fix_date(response["start_at"])
31
+ {
32
+ :short_code => response["short_code"],
33
+ :conference_name => response["conference"]["name"],
34
+ :conference_id => response["conference"]["id"],
35
+ :video_count => response["video_count"],
36
+ :date => fix_date(response["start_at"])
37
+ }
45
38
  )
46
39
  else
47
40
  # This raises the net/http response that was raised
@@ -55,8 +48,12 @@ class Event
55
48
 
56
49
  def videos
57
50
  response = HTTParty.get("#{BASE_URI}/events/#{short_code}/videos.json")
51
+ videos = []
58
52
  if response.success?
59
- return response
53
+ response.each do |video|
54
+ videos << Video.find(short_code, video["title"])
55
+ end
56
+ return videos
60
57
  else
61
58
  # This raises the net/http response that was raised
62
59
  raise response.response
@@ -65,22 +62,25 @@ class Event
65
62
 
66
63
  # TODO: This implementation isn't really ideal. By calling the videos method you're hitting the api again.
67
64
  # Ideally you want to just hit the api once and store that information away since you know that hitting the API takes more resources (and time frankly) then just storing the names in memory which is all you really care about until you need to actually get the information for that particular video
68
- #
69
65
  # Probably should do something like store the list of video names as strings as soon as you create the object and then keep that array for future use
70
66
  # This seems slightly better but I'm still not sure it's ideal
71
67
  def video_list
72
- if self.videos == "Not Found"
73
- "There was no conference found by that name."
74
- else
75
- videos.map { |video| video["title"] }
76
- end
68
+ videos.map { |video| video.title }
69
+ end
70
+
71
+ def download_all_videos!
72
+ videos.each { |video| video.download }
77
73
  end
78
74
 
75
+ def valid?
76
+ true
77
+ end
78
+
79
+ private
80
+
79
81
  def self.fix_date(date)
80
82
  year, month, day = date[0..3].to_i, date[5..6].to_i, date[8..9].to_i
81
83
  Date.new(year, month, day)
82
84
  end
83
85
 
84
- private
85
-
86
86
  end
@@ -0,0 +1,5 @@
1
+ class NullConference < ErrorObject
2
+ def name
3
+ to_s
4
+ end
5
+ end
@@ -0,0 +1,20 @@
1
+ class NullEvent < ErrorObject
2
+ def short_code; nil ; end
3
+ def conference_name; nil; end
4
+ def conference_id; nil; end
5
+ def video_count; nil; end
6
+ def date; nil; end
7
+ # Could use Avdi Grimm's Naught gem to simplify the above
8
+
9
+ def video_list
10
+ to_s
11
+ end
12
+
13
+ def name
14
+ to_s
15
+ end
16
+
17
+ def valid?
18
+ false
19
+ end
20
+ end
@@ -1,4 +1,4 @@
1
1
  module GetFreaky
2
- VERSION = "0.3.0"
3
- DATE = %q{2015-05-14}
2
+ VERSION = "0.3.1"
3
+ DATE = %q{2015-11-14}
4
4
  end
@@ -1,4 +1,5 @@
1
1
  require 'paint'
2
+ require 'youtube-dl.rb'
2
3
 
3
4
  class Video
4
5
  include HTTParty
@@ -36,7 +37,8 @@ class Video
36
37
  end
37
38
 
38
39
  def download
39
- cmd = %x[ viddl-rb #{url} ]
40
+ puts "downloading #{title}"
41
+ YoutubeDL.download url, { output: "#{title}.mp4" }
40
42
  end
41
43
 
42
44
  def event
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: get_freaky
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stephen Mariano Cabrera
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-14 00:00:00.000000000 Z
11
+ date: 2015-11-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: commander
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - '='
81
81
  - !ruby/object:Gem::Version
82
82
  version: 1.0.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: youtube-dl.rb
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: fabricas
85
99
  requirement: !ruby/object:Gem::Requirement
@@ -164,8 +178,11 @@ files:
164
178
  - bin/setup
165
179
  - lib/get_freaky.rb
166
180
  - lib/get_freaky/conference.rb
181
+ - lib/get_freaky/error_object.rb
167
182
  - lib/get_freaky/event.rb
168
183
  - lib/get_freaky/info.rb
184
+ - lib/get_freaky/null_conference.rb
185
+ - lib/get_freaky/null_event.rb
169
186
  - lib/get_freaky/version.rb
170
187
  - lib/get_freaky/video.rb
171
188
  homepage: https://github.com/smcabrera/get_freaky
@@ -189,7 +206,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
189
206
  version: '0'
190
207
  requirements: []
191
208
  rubyforge_project:
192
- rubygems_version: 2.4.7
209
+ rubygems_version: 2.4.5.1
193
210
  signing_key:
194
211
  specification_version: 4
195
212
  summary: Get Freaky!