video-dl 1.0.0 → 1.1.0

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/bin/video-dl +116 -16
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: aa500ccd48ac4dd53b0f533d9152a2568bea2ea7
4
- data.tar.gz: acebbe336a0b629330a88c3dc9da4c6db8f8672a
3
+ metadata.gz: f5689a2a59b76619ccb4bea029c53f7aec696acd
4
+ data.tar.gz: 5de666c235a1f91203e4b29aeea253796bf16032
5
5
  SHA512:
6
- metadata.gz: 408e28e321bcdb2d6ea7532b2e2e9fe2ed82c072722444e7657e73e6b38738433b061247e2df640af6b3b8c109ef00a11b2107641c652c735b418cac7401b4c2
7
- data.tar.gz: ee75592ed19318366d46dbfacb93ade891344640fe0d2a34203773edfe9a02e3f91d4e5500e4375818d242cc97ad3ef12ae24da556992d4a3f8ba47bb48f105b
6
+ metadata.gz: 319e22fba01fd4dd11cdd71745790a19517be7af2f4e859f91c76c22ae8778b32c00010582d5824df29bdb166240a27b95ec55df4f8d5cf8f1eb14b6e8a80d9b
7
+ data.tar.gz: 9a938fcdc5783d5be6a01d6855ba155404e6b27f3d13dd0ea1496367473539462e6de0901a962d08b57406b6bc1524cbd67d6d700f3b2983bc22c031ccc385ee
@@ -3,9 +3,9 @@
3
3
  require 'rubygems'
4
4
  require "bundler/setup"
5
5
  require 'commander/import'
6
- require 'json'
7
6
  require 'open-uri'
8
7
  require 'nokogiri'
8
+ require 'uri'
9
9
 
10
10
  program :name, "video-dl"
11
11
  program :version, '1.0.0'
@@ -14,16 +14,34 @@ program :description, 'Download video easily'
14
14
  default_command :download
15
15
 
16
16
  command :download do |c|
17
- c.syntax = 'video-dl download http://some.url'
18
- c.description = 'Download a video'
19
- c.option '--bar STRING', String, 'Option bar with a string'
20
- c.action do |args, options|
21
- options.default :bar => 'BAR'
22
- # puts "Args: #{args}"
23
- # puts "Option Bar: #{options.bar}"
24
- url = args[0]
25
- download_video(url)
26
- end
17
+ c.syntax = 'video-dl download http://some.url'
18
+ c.description = 'Download a video'
19
+ c.option '--bar STRING', String, 'Option bar with a string'
20
+ c.action do |args, options|
21
+ options.default :bar => 'BAR'
22
+ # puts "Args: #{args}"
23
+ # puts "Option Bar: #{options.bar}"
24
+ url = args[0]
25
+ download_video(url)
26
+ end
27
+ end
28
+
29
+ command :episodes do |c|
30
+ c.syntax = 'video-dl episodes http://some.url'
31
+ c.description = 'Download all the episodes of a drama'
32
+ c.action do |args, options|
33
+ url = args[0]
34
+ download_all_episodes(url)
35
+ end
36
+ end
37
+
38
+ command :html do |c|
39
+ c.syntax = 'video-dl html http://some.url'
40
+ c.description = 'Display the html of the url'
41
+ c.action do |args, options|
42
+ url = args[0]
43
+ display_html(url)
44
+ end
27
45
  end
28
46
 
29
47
 
@@ -33,25 +51,107 @@ end
33
51
  # Video Download
34
52
  ########################################################################################
35
53
 
54
+ def display_html(url)
55
+ doc = Nokogiri::HTML(open(url))
56
+ puts doc
57
+ end
58
+
36
59
  def download_video(url)
37
- puts "Downloading #{url}"
60
+ puts "Downloading from #{url}"
38
61
 
62
+ # Read the url HTML
39
63
  doc = Nokogiri::HTML(open(url))
40
64
  # puts doc
41
65
 
66
+ # Find the video title
42
67
  title = doc.css("h1[class='title']")[0].content
43
68
  puts "Title: #{title}"
44
69
 
70
+ # doc.css("source[type='video/mp4']").each { |source|
71
+ # puts "Source: #{source['src']}"
72
+ # }
73
+
74
+ sources = doc.css("source[type='video/mp4']")
75
+ videoUrl = findHighestRes(sources)
76
+ if videoUrl != nil
77
+ download(title, videoUrl)
78
+ return
79
+ end
80
+
81
+ # Otherwise, video is in an iframe
45
82
  iframeSrc = doc.css('div#servermobile > iframe')[0]['src']
46
- # puts iframeSrc
83
+ puts "iframe src: #{iframeSrc}"
47
84
 
85
+ # Read the iframe HTML
48
86
  doc = Nokogiri::HTML(open(iframeSrc))
49
87
  # puts doc
50
88
 
51
- videoUrl = doc.css("video#my-video > source[label='720']")[0]['src']
52
- puts "Video is at #{videoUrl} \n\n"
89
+ # Finally we have the video url
90
+ sources = doc.css("source[type='video/mp4']")
91
+ videoUrl = findHighestRes(sources)
92
+ if videoUrl != nil
93
+ download(title, videoUrl)
94
+ return
95
+ else
96
+ puts "Failed to find video url"
97
+ end
98
+ end
99
+
53
100
 
101
+ # Run youtube-dl shell command
102
+ def download(title, videoUrl)
103
+ puts "Video is at #{videoUrl}\n\n"
54
104
  cmd = "youtube-dl -o #{Shellwords.escape(title)}.mp4 #{Shellwords.escape(videoUrl)}"
55
105
  puts "Running #{cmd}"
56
- puts system(cmd)
106
+ system(cmd)
107
+ end
108
+
109
+
110
+ # Find the highest resolution source from an array of sources like this:
111
+ # <source src="http://3.bp.blogspot.com/xyz" type="video/mp4" label="720"></source>
112
+ # Return the video url
113
+ def findHighestRes(sources)
114
+ if sources.length > 0
115
+ highestResSource = nil
116
+ sources.each { |source|
117
+ if highestResSource == nil
118
+ highestResSource = source
119
+ else
120
+ if source['label'].to_i > highestResSource['label'].to_i
121
+ highestResSource = source
122
+ end
123
+ end
124
+ }
125
+ # puts "Highest Res Source: #{highestResSource}"
126
+ videoUrl = highestResSource['src']
127
+ return videoUrl
128
+ end
129
+ return nil
130
+ end
131
+
132
+
133
+ def download_all_episodes(url)
134
+ puts "Downloading all episodes from #{url}"
135
+
136
+ uri = URI.parse(url)
137
+ domain = "#{uri.scheme}://#{uri.host}"
138
+ # puts "Domain: #{domain}"
139
+
140
+ # Read the url HTML
141
+ doc = Nokogiri::HTML(open(url))
142
+
143
+ # Find the episode list
144
+ episodes = doc.css("select[class='gotolistepisode'] > option")
145
+ episodeUrls = []
146
+ puts "Episodes:"
147
+ episodes.reverse.each { |episode|
148
+ episodeUrl = "#{domain}#{episode['value']}"
149
+ puts "\tEpisode URL: #{episodeUrl}"
150
+ episodeUrls.push(episodeUrl)
151
+ }
152
+
153
+ # Download each
154
+ episodeUrls.each { |episodeUrl|
155
+ download_video(episodeUrl)
156
+ }
57
157
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: video-dl
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Junda