yt 0.9.6 → 0.9.7
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 +4 -4
- data/Gemfile.lock +1 -1
- data/HISTORY.md +1 -0
- data/README.md +1 -1
- data/Rakefile +1 -1
- data/lib/yt/models/content_detail.rb +25 -9
- data/lib/yt/version.rb +1 -1
- data/spec/models/content_detail_spec.rb +10 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fe0377f41d87e871a3db2e1380356bc53f788fa5
|
4
|
+
data.tar.gz: 8943b3e3187efbe011d4c73b56882daea6d1f94f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0825f5187597673a1467626df427092c874961c29b0c8f888dddc424d28a99afedaba755719a1f713e9694a9bb38762e9709d9fa6b4759af0fe83127e17af088
|
7
|
+
data.tar.gz: 6b0a8ab02e131601d729f6b3be3dc97464fe8c4c51f19cf7afac602fa33507b9fdd4ef45f72a2755fba4b27c220b605453969628803a6778d4e67a8d00016eba
|
data/Gemfile.lock
CHANGED
data/HISTORY.md
CHANGED
@@ -9,6 +9,7 @@ v0.9 - 2014/07/28
|
|
9
9
|
* Add actual_start_time, actual_end_time, scheduled_start_time, scheduled_end_time for live-streaming videos
|
10
10
|
* Add privacy_status, public_stats_viewable, publish_at to the options that Video#update accepts
|
11
11
|
* Allow angle brackets when editing title, description, tags and replace them with similar characters allowed by YouTube
|
12
|
+
* Correctly parse duration of videos longer than 24 hours
|
12
13
|
|
13
14
|
v0.8 - 2014/07/18
|
14
15
|
-----------------
|
data/README.md
CHANGED
@@ -41,7 +41,7 @@ To install on your system, run
|
|
41
41
|
|
42
42
|
To use inside a bundled Ruby project, add this line to the Gemfile:
|
43
43
|
|
44
|
-
gem 'yt', '~> 0.9.
|
44
|
+
gem 'yt', '~> 0.9.7'
|
45
45
|
|
46
46
|
Since the gem follows [Semantic Versioning](http://semver.org),
|
47
47
|
indicating the full version in your Gemfile (~> *major*.*minor*.*patch*)
|
data/Rakefile
CHANGED
@@ -17,7 +17,7 @@ require "rspec/core/version"
|
|
17
17
|
# API to work again.
|
18
18
|
desc "Run all examples except ones with access to Content Owner"
|
19
19
|
RSpec::Core::RakeTask.new(:spec) do |t|
|
20
|
-
t.rspec_opts = '--tag ~partner'
|
20
|
+
t.rspec_opts = '--tag ~partner --tag ~device_app'
|
21
21
|
end
|
22
22
|
|
23
23
|
task default: [:spec]
|
@@ -39,19 +39,35 @@ module Yt
|
|
39
39
|
|
40
40
|
private
|
41
41
|
|
42
|
-
#
|
43
|
-
#
|
44
|
-
#
|
45
|
-
#
|
46
|
-
#
|
47
|
-
#
|
48
|
-
#
|
42
|
+
# @return [Integer] the duration of the resource as reported by YouTube.
|
43
|
+
# @see https://developers.google.com/youtube/v3/docs/videos
|
44
|
+
#
|
45
|
+
# According to YouTube documentation, the value is an ISO 8601 duration
|
46
|
+
# in the format PT#M#S, in which the letters PT indicate that the value
|
47
|
+
# specifies a period of time, and the letters M and S refer to length in
|
48
|
+
# minutes and seconds, respectively. The # characters preceding the M and
|
49
|
+
# S letters are both integers that specify the number of minutes (or
|
50
|
+
# seconds) of the video. For example, a value of PT15M51S indicates that
|
51
|
+
# the video is 15 minutes and 51 seconds long.
|
52
|
+
#
|
53
|
+
# The ISO 8601 duration standard, though, is not +always+ respected by
|
54
|
+
# the results returned by YouTube API. For instance: video 2XwmldWC_Ls
|
55
|
+
# reports a duration of 'P1W2DT6H21M32S', which is to be interpreted as
|
56
|
+
# 1 week, 2 days, 6 hours, 21 minutes, 32 seconds. Mixing weeks with
|
57
|
+
# other time units is not strictly part of ISO 8601; in this context,
|
58
|
+
# weeks will be interpreted as "the duration of 7 days". Similarly, a
|
59
|
+
# day will be interpreted as "the duration of 24 hours".
|
60
|
+
# Video tPEE9ZwTmy0 reports a duration of 'PT2S'. Skipping time units
|
61
|
+
# such as minutes is not part of the standard either; in this context,
|
62
|
+
# it will be interpreted as "0 minutes and 2 seconds".
|
49
63
|
def to_seconds(iso8601_duration)
|
50
|
-
match = iso8601_duration.match %r{^
|
64
|
+
match = iso8601_duration.match %r{^P(?:|(?<weeks>\d*?)W)(?:|(?<days>\d*?)D)(?:|T(?:|(?<hours>\d*?)H)(?:|(?<min>\d*?)M)(?:|(?<sec>\d*?)S))$}
|
65
|
+
weeks = (match[:weeks] || '0').to_i
|
66
|
+
days = (match[:days] || '0').to_i
|
51
67
|
hours = (match[:hours] || '0').to_i
|
52
68
|
minutes = (match[:min] || '0').to_i
|
53
69
|
seconds = (match[:sec]).to_i
|
54
|
-
(hours * 60 + minutes) * 60 + seconds
|
70
|
+
(((((weeks * 7) + days) * 24 + hours) * 60) + minutes) * 60 + seconds
|
55
71
|
end
|
56
72
|
end
|
57
73
|
end
|
data/lib/yt/version.rb
CHANGED
@@ -5,6 +5,16 @@ describe Yt::ContentDetail do
|
|
5
5
|
subject(:content_detail) { Yt::ContentDetail.new data: data }
|
6
6
|
|
7
7
|
describe '#duration' do
|
8
|
+
context 'given a content_detail with duration in weeks, days, hours, minutes' do
|
9
|
+
let(:data) { {"duration"=>"P1W2DT6H21M32S"}}
|
10
|
+
it { expect(content_detail.duration).to eq 800492 }
|
11
|
+
end
|
12
|
+
|
13
|
+
context 'given a content_detail with duration in days' do
|
14
|
+
let(:data) { {"duration"=>"P1D"}}
|
15
|
+
it { expect(content_detail.duration).to eq 86400 }
|
16
|
+
end
|
17
|
+
|
8
18
|
context 'given a content_detail with duration in hours, minutes, seconds' do
|
9
19
|
let(:data) { {"duration"=>"PT1H18M52S"} }
|
10
20
|
it { expect(content_detail.duration).to eq 4732 }
|