rubytube 0.2.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +7 -0
- data/lib/rubytube/cipher.rb +2 -1
- data/lib/rubytube/stream.rb +8 -0
- data/lib/rubytube/stream_query.rb +25 -6
- data/lib/rubytube/version.rb +1 -1
- data/lib/rubytube.rb +1 -0
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 81f3bc458444b3f15a63612fa193c5fbeb0fba3f2ca73a8b3936453fcf269d58
|
4
|
+
data.tar.gz: ba175f34390fd95271cacc283bec75370b543b1a0edebad81e67a4188ca94790
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9652bd73252dee11c51d1fd322813660c447e1e9c0b6a863be9e4f277309927ff8eb4d2910a991c055c8b11db833986129e5c74988653a4b50441f2e546a5804
|
7
|
+
data.tar.gz: 49593099d2603a922a9db02f8147e3b69d1674af663174e4d8bb6f8e7839b7b388036072f402d053699b2aee43b5b0bb6dd1789f248f10905f5aa30615b4f1f1
|
data/README.md
CHANGED
@@ -16,4 +16,11 @@ video = RubyTube.new('https://www.youtube.com/watch?v=dQw4w9WgXcQ')
|
|
16
16
|
|
17
17
|
# Download video
|
18
18
|
video.streams.first.download
|
19
|
+
|
20
|
+
# Filtering streams
|
21
|
+
video.streams
|
22
|
+
.filter(progressive: true, file_extension: 'mp4')
|
23
|
+
.order(resolution: :desc)
|
24
|
+
.first
|
25
|
+
.download
|
19
26
|
```
|
data/lib/rubytube/cipher.rb
CHANGED
@@ -351,7 +351,8 @@ module RubyTube
|
|
351
351
|
plan_regex = Regexp.new(transform_start)
|
352
352
|
match = raw_code.match(plan_regex)
|
353
353
|
|
354
|
-
transform_plan_raw = Parser.find_object_from_startpoint(raw_code, match.end(0) - 1)
|
354
|
+
# transform_plan_raw = Parser.find_object_from_startpoint(raw_code, match.end(0) - 1)
|
355
|
+
transform_plan_raw = js
|
355
356
|
step_regex = %r"c\[(\d+)\]\(c\[(\d+)\](,c(\[(\d+)\]))?\)"
|
356
357
|
matches = transform_plan_raw.scan(step_regex)
|
357
358
|
transform_steps = []
|
data/lib/rubytube/stream.rb
CHANGED
@@ -7,24 +7,22 @@ module RubyTube
|
|
7
7
|
@streams = fmt_streams
|
8
8
|
end
|
9
9
|
|
10
|
-
def filter(file_extension: nil, only_audio: false, only_video: false, resolution: nil)
|
10
|
+
def filter(file_extension: nil, only_audio: false, only_video: false, resolution: nil, progressive: false, adaptive: false)
|
11
11
|
filters = []
|
12
12
|
|
13
13
|
filters << ->(stream) { stream.subtype == file_extension } if file_extension
|
14
14
|
filters << ->(stream) { stream.is_audio? } if only_audio
|
15
15
|
filters << ->(stream) { stream.is_video? } if only_video
|
16
16
|
filters << ->(stream) { stream.resolution == resolution } if resolution
|
17
|
+
filters << ->(stream) { stream.is_progressive? } if progressive
|
18
|
+
filters << ->(stream) { stream.is_adaptive? } if adaptive
|
17
19
|
|
18
20
|
r = streams
|
19
21
|
filters.each do |f|
|
20
22
|
r = r.select(&f)
|
21
23
|
end
|
22
24
|
|
23
|
-
r
|
24
|
-
end
|
25
|
-
|
26
|
-
def first
|
27
|
-
streams.first
|
25
|
+
StreamQuery.new(r)
|
28
26
|
end
|
29
27
|
|
30
28
|
def get_by_itag(itag)
|
@@ -34,5 +32,26 @@ module RubyTube
|
|
34
32
|
def get_by_resolution(resolution)
|
35
33
|
streams.find { |s| s.resolution == resolution }
|
36
34
|
end
|
35
|
+
|
36
|
+
def order(arg)
|
37
|
+
case arg
|
38
|
+
when Symbol
|
39
|
+
field = arg
|
40
|
+
dir = :asc
|
41
|
+
when Hash
|
42
|
+
field = arg.keys.first
|
43
|
+
dir = arg[field] == :desc ? :desc : :asc
|
44
|
+
end
|
45
|
+
|
46
|
+
allowed_fields = [:file_size, :itag, :resolution]
|
47
|
+
raise InvalidArgumentError unless allowed_fields.include? field
|
48
|
+
|
49
|
+
r = streams
|
50
|
+
r.sort! {|a, b| a.send(field).to_i <=> b.send(field).to_i }
|
51
|
+
|
52
|
+
r.reverse! if dir == :desc
|
53
|
+
|
54
|
+
StreamQuery.new(r)
|
55
|
+
end
|
37
56
|
end
|
38
57
|
end
|
data/lib/rubytube/version.rb
CHANGED
data/lib/rubytube.rb
CHANGED
@@ -23,6 +23,7 @@ module RubyTube
|
|
23
23
|
class ExtractError < StandardError; end
|
24
24
|
class MaxRetriesExceeded < StandardError; end
|
25
25
|
class VideoUnavailable < StandardError; end
|
26
|
+
class InvalidArgumentError < ArgumentError; end
|
26
27
|
|
27
28
|
class RegexMatchError < StandardError
|
28
29
|
def initialize(caller, pattern)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubytube
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- nightswinger
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-09-
|
11
|
+
date: 2023-09-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -38,7 +38,7 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
-
description:
|
41
|
+
description:
|
42
42
|
email:
|
43
43
|
- stardustkids83@gmail.com
|
44
44
|
executables: []
|
@@ -92,5 +92,6 @@ requirements: []
|
|
92
92
|
rubygems_version: 3.4.10
|
93
93
|
signing_key:
|
94
94
|
specification_version: 4
|
95
|
-
summary:
|
95
|
+
summary: RubyTube is a Ruby adaptation of pytube, enabling simplified downloading
|
96
|
+
and streaming of YouTube videos in a Ruby-friendly manner.
|
96
97
|
test_files: []
|