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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f2401a0d9b81d6da08424943a09b392870081fc6
4
- data.tar.gz: b1fd60bb4f1426f34182730f73bdf4641e6025d0
3
+ metadata.gz: fe0377f41d87e871a3db2e1380356bc53f788fa5
4
+ data.tar.gz: 8943b3e3187efbe011d4c73b56882daea6d1f94f
5
5
  SHA512:
6
- metadata.gz: 74acf5be09a43cdbb3f7da60d275c57b5db7fb9336c4f236c0db48257b0120ebb95619a4e5a5ae8eb77a5b6450c600d0cbed14bb015a43e1d2b474c813020caf
7
- data.tar.gz: 7daada1a1bc24ddd581cacbb6f2171a5947f9c387b608222dae391b664bb944d1c22a8e6d6cbcfd7df3531ae90622e200eae61eaebfbe8bf00c8e333c0475523
6
+ metadata.gz: 0825f5187597673a1467626df427092c874961c29b0c8f888dddc424d28a99afedaba755719a1f713e9694a9bb38762e9709d9fa6b4759af0fe83127e17af088
7
+ data.tar.gz: 6b0a8ab02e131601d729f6b3be3dc97464fe8c4c51f19cf7afac602fa33507b9fdd4ef45f72a2755fba4b27c220b605453969628803a6778d4e67a8d00016eba
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- yt (0.9.6)
4
+ yt (0.9.7)
5
5
  activesupport
6
6
 
7
7
  GEM
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.6'
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
- # The duration of the resource as reported by YouTube. The value is an
43
- # ISO 8601 duration in the format PT#M#S, in which the letters PT
44
- # indicate that the value specifies a period of time, and the letters M
45
- # and S refer to length in minutes and seconds, respectively. The #
46
- # characters preceding the M and S letters are both integers that specify
47
- # the number of minutes (or seconds) of the video. For example, a value
48
- # of PT15M51S indicates that the video is 15 minutes and 51 seconds long.
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{^PT(?:|(?<hours>\d*?)H)(?:|(?<min>\d*?)M)(?:|(?<sec>\d*?)S)$}
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
@@ -1,3 +1,3 @@
1
1
  module Yt
2
- VERSION = '0.9.6'
2
+ VERSION = '0.9.7'
3
3
  end
@@ -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 }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.6
4
+ version: 0.9.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Claudio Baccigalupo