snackpack 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
data/bin/snackpack ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'snackpack'
4
+
5
+ unless FileTest.exists?('snackpack.yml')
6
+ puts "Missing snackpack.yml"
7
+ exit
8
+ end
9
+
10
+ if ARGV.count >= 2
11
+ Snackpack.new.enter_avdis_kitchen
12
+ else
13
+ puts "usage: snackpack username password"
14
+ end
@@ -0,0 +1,26 @@
1
+ class Condiments
2
+ def initialize(snack_store, condiment)
3
+ @snack = snack_store
4
+ @condiment = <<-EOF
5
+ <center>
6
+ <video width="960" height="540" controls="controls">
7
+ <source src="#{condiment}" type="video/mp4">
8
+ Your browser does not support el video tag.
9
+ </video>
10
+ </center>
11
+ EOF
12
+ end
13
+
14
+ def add
15
+ super_snack = Tempfile.new('super_snack')
16
+ File.open(@snack) do |f|
17
+ while line = f.gets
18
+ super_snack.puts line
19
+ if line.match(/<h1 class/)
20
+ super_snack.puts @condiment
21
+ end
22
+ end
23
+ end
24
+ FileUtils.mv(super_snack.path, @snack)
25
+ end
26
+ end
@@ -0,0 +1,39 @@
1
+ class Gobble
2
+
3
+ def initialize(snack_pack, snacker, stomach)
4
+ @snack_pack = snack_pack
5
+ @snacker = snacker
6
+ @stomach = stomach
7
+ end
8
+
9
+ def eat
10
+ choice_snacks = pick_choice_snacks
11
+ consume_snacks(choice_snacks)
12
+ end
13
+
14
+ private
15
+ def pick_choice_snacks
16
+ @snack_pack.links_with(:href => /download/)
17
+ end
18
+
19
+ def consume_snacks(snacks)
20
+ title = @snack_pack.search('h2').inner_text.downcase.gsub(/ /, '-')
21
+ id = @snack_pack.uri.to_s.match(/\d+/).to_s
22
+ tupaware = title + '-' + id + '/'
23
+
24
+ condiment = snacks.select { |s| s.text.match(/mp4/) }
25
+
26
+ snacks.each do |snack|
27
+ snack_store = @stomach + tupaware + snack.text
28
+
29
+ # dont download file twice
30
+ unless FileTest.exists?(snack_store)
31
+ snack.click.save(snack_store)
32
+ if snack.text.match(/html/)
33
+ Condiments.new(snack_store, condiment.first.text).add
34
+ end
35
+ end
36
+ end
37
+ end
38
+
39
+ end
data/lib/snackpack.rb ADDED
@@ -0,0 +1,47 @@
1
+ require 'mechanize'
2
+ require 'yaml'
3
+ require 'tempfile'
4
+ require 'fileutils'
5
+
6
+ require_relative 'snackpack/gobble.rb'
7
+ require_relative 'snackpack/condiments.rb'
8
+
9
+ class Snackpack
10
+
11
+ def initialize
12
+ @config = YAML.load_file('snackpack.yml')
13
+ @email = ARGV[0]
14
+ @password = ARGV[1]
15
+ @snacker = Mechanize.new
16
+ @snacker.pluggable_parser.default = Mechanize::Download
17
+ @kitchen = @snacker.get('https://rubytapas.dpdcart.com/subscriber/content')
18
+ end
19
+
20
+ def enter_avdis_kitchen
21
+ open_fridge
22
+ unwrap_snacks(get_snackpacks)
23
+ #TODO build_the_menu (build index linking to all episodes)
24
+ end
25
+
26
+ private
27
+ def open_fridge
28
+ fridge = @kitchen.forms[0]
29
+ fridge.username = @email
30
+ fridge.password = @password
31
+ @kitchen = fridge.submit fridge.buttons.first
32
+ end
33
+
34
+ def get_snackpacks
35
+ # TODO check expiration date
36
+ # have we already eaten these?
37
+ @kitchen.links_with(:text => /Attachments/)
38
+ end
39
+
40
+ def unwrap_snacks(snackpacks)
41
+ snackpacks.each do |pack|
42
+ @snack_pack = pack.click
43
+ Gobble.new(@snack_pack, @snacker, @config[:stomach]).eat
44
+ end
45
+ end
46
+
47
+ end
metadata ADDED
@@ -0,0 +1,50 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: snackpack
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.4
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Cory Schmitt
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-11-14 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: ! " Snackpack logs into your RubyTapas subscription and downloads\n
15
+ \ all the available episodes with their supporting files onto your local\n computer.\n"
16
+ email: cory@schmitty.me
17
+ executables:
18
+ - snackpack
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - lib/snackpack/gobble.rb
23
+ - lib/snackpack/condiments.rb
24
+ - lib/snackpack.rb
25
+ - bin/snackpack
26
+ homepage: https://github.com/cas27/snackpack
27
+ licenses: []
28
+ post_install_message:
29
+ rdoc_options: []
30
+ require_paths:
31
+ - lib
32
+ required_ruby_version: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ required_rubygems_version: !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ requirements: []
45
+ rubyforge_project:
46
+ rubygems_version: 1.8.10
47
+ signing_key:
48
+ specification_version: 3
49
+ summary: Downloads and packages RubyTapas locally
50
+ test_files: []