aa-vimeo-downloader 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/aa-vimeo-downloader.rb +143 -0
  3. metadata +46 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 75821119489d609b76eff872a527cd7165dd08a3
4
+ data.tar.gz: 661f4d7bc14b4414e3ec7ca79d44bc64d900544d
5
+ SHA512:
6
+ metadata.gz: 489d3b75a65c7b85f4cd18e549290c37e207fdbdbe1e7f7a53da0c5f776e061189c44f9155e082ba783b11f9476ccf6fd62746ba2ebd2fb417c10af9d2aa5841
7
+ data.tar.gz: 2806f5b4ee08eb00ff8f1462364d212a40cf41a1a935983f31865f7b754d64771d342fb337df0ce4083e1d71d21109fd61538c594d25a4bb25bb41989665fb0f
@@ -0,0 +1,143 @@
1
+ require 'open-uri'
2
+ require 'io/console'
3
+ require 'pty'
4
+ # No installation! Wew!
5
+ require 'youtube-dl'
6
+
7
+ class GitRaw
8
+ attr_reader :body
9
+ def initialize(url)
10
+ @body = open(url).map(&:chomp)
11
+ end
12
+ end
13
+
14
+ class LinkParser
15
+ attr_reader :links
16
+
17
+ def initialize(raw, creds)
18
+ unparsed_links = narrow_to_week_section(raw.body.dup, creds.day)
19
+ to_hash(unparsed_links)
20
+ end
21
+
22
+ private
23
+
24
+ def narrow_to_week_section(body, target)
25
+ links = []
26
+
27
+ unless target =~ /all/i
28
+ body.shift until body.first =~ Regexp.new("[^\\[#]#{target}", 'i')
29
+ links << body.shift until body.first =~ /homeworks|additional resources|projects/i
30
+ end
31
+
32
+ body = links.select! { |l| l =~ /vimeo/ }
33
+ end
34
+
35
+ def to_hash(unparsed_links)
36
+ @links = Hash.new do |h, k|
37
+ k =~ /(\[.*\]).*(http.*)/
38
+ h["#{h.count + 1}: #{$1}"] = $2
39
+ end
40
+
41
+ unparsed_links.each { |unparsed| @links[unparsed] }
42
+ end
43
+ end
44
+
45
+ # should be able to remove this once binding works correctly
46
+ def has_youtube_dl?
47
+ if `which youtube-dl` =~ /^$/
48
+ print <<~HEREDOC
49
+ The dependency 'youtube_dl' is not installed.
50
+ To install this program, see
51
+ https://rg3.github.io/youtube-dl/download.html
52
+
53
+ Are you using OSX or Linux and would like to
54
+ install youtube_dl automatically?
55
+ HEREDOC
56
+
57
+ print "[Y/N]: "
58
+
59
+ if STDIN.gets =~ /y/i
60
+ raise "Install failed; please install manually" unless install_youtube_dl
61
+ return true
62
+ else
63
+ abort('Install youtube_dl to use this program')
64
+ end
65
+ end
66
+ end
67
+
68
+ def install_youtube_dl
69
+ `sudo curl -L https://yt-dl.org/downloads/latest/youtube-dl -o /usr/local/bin/youtube-dl`
70
+ `sudo chmod a+rx /usr/local/bin/youtube-dl`
71
+ `which youtube-dl` =~ /^$/
72
+ end
73
+
74
+ class Credentials
75
+ attr_reader :day, :url, :vimeo_password
76
+ def initialize
77
+ @day = ARGV.find { |a| a =~ /w\d+d\d+|all/i }
78
+ @url = ARGV.find { |a| a =~ /raw.githubusercontent/ }
79
+
80
+ abort("Must provide a URL to a README.md RAW") unless @url
81
+ abort("Must provide a day like 'w4d1' OR '--all'") unless @day
82
+
83
+ @day = @day.upcase
84
+ @vimeo_password = get_vimeo_password
85
+ p ''
86
+ end
87
+
88
+ private
89
+
90
+ def get_vimeo_password
91
+ print "Please enter the password to access these Vimeo videos:\n> "
92
+ STDIN.noecho(&:gets).chomp
93
+ end
94
+ end
95
+
96
+ def make_video_dir(creds, links)
97
+ vdirname = "#{creds.day}_videos"
98
+ Dir.mkdir vdirname unless Dir.exists?(vdirname)
99
+ Dir.chdir vdirname
100
+ p "Created the directory #{vdirname}"
101
+
102
+ links.each do |name, link|
103
+ if Dir.entries('.').find { |e| e.index name }
104
+ puts "#{name} already exists; continuing to next video"
105
+ else
106
+ get_video(name, link, creds.vimeo_password)
107
+ end
108
+ end
109
+
110
+ p "#{vdirname} successfully created with #{Dir.entries('.').reject { |e| e =~ /^\./ }.count} videos"
111
+
112
+ print `ls -1`
113
+ end
114
+
115
+ # Replace this with ruby binding
116
+ def get_video(name, link, pass)
117
+ title = "#{name}.%(ext)s"
118
+ command = %{youtube-dl --video-password "#{pass}" -o "#{title}" #{link}}
119
+
120
+ YoutubeDL.download link, {
121
+ "video-password": pass,
122
+ "o": title
123
+ }
124
+
125
+ # begin
126
+ # PTY.spawn(command) do |stdout, _stdin, _pid|
127
+ # begin
128
+ # stdout.each { |line| print line }
129
+ # rescue Errno::EIO
130
+ # end
131
+ # end
132
+ # rescue PTY::ChildExited
133
+ # puts "The child process exited!"
134
+ # end
135
+ end
136
+
137
+ if $PROGRAM_NAME == __FILE__
138
+ #has_youtube_dl? # This will go since ruby binding should work
139
+ creds = Credentials.new
140
+ raw = GitRaw.new creds.url
141
+ links = LinkParser.new(raw, creds)
142
+ make_video_dir(creds, links.links)
143
+ end
metadata ADDED
@@ -0,0 +1,46 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: aa-vimeo-downloader
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Joseph Burger
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-12-07 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A script that wraps around youtube-dl to download private App Academy
14
+ videos
15
+ email: candyapplecorn@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/aa-vimeo-downloader.rb
21
+ homepage: https://github.com/candyapplecorn/aa-vimeo-downloader
22
+ licenses:
23
+ - MIT
24
+ metadata: {}
25
+ post_install_message:
26
+ rdoc_options: []
27
+ require_paths:
28
+ - lib
29
+ required_ruby_version: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ required_rubygems_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ requirements: []
40
+ rubyforge_project:
41
+ rubygems_version: 2.6.11
42
+ signing_key:
43
+ specification_version: 4
44
+ summary: Download the day's videos for offline use
45
+ test_files: []
46
+ has_rdoc: