playlist 0.2.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e0abdf1a10cd890a9d446a6617ed5bf12856dba0
4
- data.tar.gz: 0719e57569fed6a8798e58db21eb50dd6c7dfc34
3
+ metadata.gz: bc3a6497a40653031438f4692659e4f1136e2a29
4
+ data.tar.gz: 88e19ff093d5b1eba7569f011f02e2707751daae
5
5
  SHA512:
6
- metadata.gz: 44aa5aff176b61c1ad739765882e4c7a7dde57f828a9f4eee95bf19112362d8bcb4b55fe24145e0b435e48f56746ff6bba83086bf810862ffe584f253821cbdc
7
- data.tar.gz: e71116d7a8906db2cea15f117a4de683945e47b7fb285a36c8043635491c94979653be85adb0b90e4fd947d7fe6626baf4823fd128e32a58414a22ee78836c6b
6
+ metadata.gz: 7d7baa63b8aed79765ffac6280baa708eb65b5afccc30b40590b7f6383d91bddd1a5d0a9d80c57916c9f05ffc856d5203557cce99953b525e65a025ed2df6593
7
+ data.tar.gz: 09dfeed3a840b1c3aa8a1e8fb98dd85a3ec1a6175755f18c6dc3e4c2a9a29dcbc1e39d0bdcf58593b3e85d9f8f295dd44e16852b1c15f81632e5ff818ebb6e00
@@ -40,6 +40,7 @@ class Playlist
40
40
  # @param attr [Hash] a hash of attibute values to set
41
41
  def initialize(attr = {})
42
42
  @tracks = []
43
+ @identifiers = {}
43
44
  attr.each_pair do |key, value|
44
45
  send("#{key}=", value)
45
46
  end
@@ -54,7 +55,7 @@ class Playlist
54
55
  @tracks << (args.is_a?(Track) ? args : Track.new(args))
55
56
  end
56
57
 
57
- # Get the total duration of this playlist
58
+ # Get the total duration of this playlist in milliseconds
58
59
  # If any tracks on the playlist don't have a duation, then they are ignored
59
60
  # @return [Integer, Float]
60
61
  def duration
@@ -11,9 +11,9 @@ module Playlist::Format::Cue
11
11
  input.each_line do |line|
12
12
  if line =~ /^\s*REM\s/
13
13
  next
14
- elsif line =~ /^\s*TRACK (\d+) AUDIO/
14
+ elsif (matches = line.match(/^\s*TRACK (\d+) AUDIO/))
15
15
  track = Playlist::Track.new(
16
- :track_number => Regexp.last_match(1).to_i
16
+ :track_number => matches[1].to_i
17
17
  )
18
18
  playlist.add_track(track)
19
19
  elsif !track.nil?
@@ -44,24 +44,24 @@ module Playlist::Format::Cue
44
44
  protected
45
45
 
46
46
  def parse_track_line(track, line)
47
- if line =~ /^\s*TITLE \"?(.+?)\"?$/
48
- track.title = Regexp.last_match(1)
49
- elsif line =~ /^\s*PERFORMER \"?(.+?)\"?$/
50
- track.performer = Regexp.last_match(1)
51
- elsif line =~ /^\s*ISRC \"?(\w+?)\"?$/
52
- track.isrc = Regexp.last_match(1)
53
- elsif line =~ /^\s*INDEX /
54
- track.start_time = parse_time(line)
47
+ if (matches = line.match(/^\s*TITLE \"?(.+?)\"?$/))
48
+ track.title = matches[1]
49
+ elsif (matches = line.match(/^\s*PERFORMER \"?(.+?)\"?$/))
50
+ track.performer = matches[1]
51
+ elsif (matches = line.match(/^\s*ISRC \"?(\w+?)\"?$/))
52
+ track.isrc = matches[1]
53
+ elsif (matches = line.match(/^\s*INDEX (.+)$/))
54
+ track.start_time = parse_time(matches[1])
55
55
  else
56
56
  warn "Unknown command: #{line}"
57
57
  end
58
58
  end
59
59
 
60
60
  def parse_playlist_line(playlist, line)
61
- if line =~ /^\s*TITLE \"?(.+?)\"?$/
62
- playlist.title = Regexp.last_match(1)
63
- elsif line =~ /^\s*FILE \"?(.+?)\" (\w+)?$/
64
- playlist.media_location = Regexp.last_match(1)
61
+ if (matches = line.match(/^\s*TITLE \"?(.+?)\"?$/))
62
+ playlist.title = matches[1]
63
+ elsif (matches = line.match(/^\s*FILE \"?(.+?)\" (\w+)?$/))
64
+ playlist.media_location = matches[1]
65
65
  end
66
66
  end
67
67
 
@@ -90,18 +90,19 @@ module Playlist::Format::Cue
90
90
  end
91
91
 
92
92
  def parse_time(timestamp)
93
- if timestamp =~ /INDEX (\d+) (\d+):(\d+):(\d+)/
94
- if Regexp.last_match(1).to_i == 1
95
- mins = Regexp.last_match(2).to_f
96
- secs = Regexp.last_match(3).to_f
97
- frames = Regexp.last_match(4).to_f
98
- (mins * 60) + secs + (frames / 75)
93
+ if (matches = timestamp.match(/(\d+) (\d+):(\d+):(\d+)/))
94
+ if matches[1].to_i == 1
95
+ mins = matches[2].to_i
96
+ secs = matches[3].to_i
97
+ frames = matches[4].to_i
98
+ (mins * 60_000) + (secs * 1000) + (frames * (75 / 1000))
99
99
  end
100
100
  end
101
101
  end
102
102
 
103
103
  def format_time(duration)
104
104
  duration = 0 if duration.nil?
105
+ duration = duration.to_f / 1000
105
106
  mins = (duration / 60).floor
106
107
  secs = (duration % 60).floor
107
108
  frames = ((duration - duration.floor) * 75).round
@@ -9,10 +9,10 @@ module Playlist::Format::M3U
9
9
  Playlist.new do |playlist|
10
10
  track = Playlist::Track.new
11
11
  input.each_line do |line|
12
- if line =~ /^#EXTINF:(-?\d+),\s*(.+?)\s*-\s*(.+?)\s*$/
13
- track.duration = Regexp.last_match(1)
14
- track.creator = Regexp.last_match(2)
15
- track.title = Regexp.last_match(3)
12
+ if (matches = line.match(/^#EXTINF:(-?\d+),\s*(.+?)\s*-\s*(.+?)\s*$/))
13
+ track.duration = matches[1].to_i * 1000
14
+ track.creator = matches[2]
15
+ track.title = matches[3]
16
16
  else
17
17
  if line =~ /^[^#]\S+.+\s*$/
18
18
  track.location = line.strip
@@ -30,7 +30,8 @@ module Playlist::Format::M3U
30
30
  def generate(playlist)
31
31
  text = "#EXTM3U\n"
32
32
  playlist.tracks.each do |t|
33
- text += "#EXTINF:#{t.duration.to_i},#{t.artist} - #{t.title}\n"
33
+ duration = (t.duration / 1000).round
34
+ text += "#EXTINF:#{duration},#{t.artist} - #{t.title}\n"
34
35
  text += "#{t.location}\n"
35
36
  end
36
37
  text
@@ -20,11 +20,14 @@ module Playlist::Format::SimpleText
20
20
  # @param line [String] any object that responds to #each_line
21
21
  # @return [Track] a new Track object
22
22
  def parse_line(line)
23
- if line =~ /^(\d{1,2}[:.]\d{1,2}([:.]\d{1,2})?)?\s*(.+?) - (.+?)$/
23
+ matches = line.match(
24
+ /^(\d{1,2}[:.]\d{1,2}([:.]\d{1,2})?)?\s*(.+?) - (.+?)$/
25
+ )
26
+ unless matches.nil?
24
27
  Playlist::Track.new(
25
- :start_time => Regexp.last_match(1),
26
- :creator => Regexp.last_match(3).strip,
27
- :title => Regexp.last_match(4).strip
28
+ :start_time => matches[1],
29
+ :creator => matches[3].strip,
30
+ :title => matches[4].strip
28
31
  )
29
32
  end
30
33
  end
@@ -43,7 +43,7 @@ module Playlist::Format::XSPF
43
43
  track.title = doc.content_at('./xmlns:title')
44
44
  track.location = doc.content_at('./xmlns:location')
45
45
  if (duration = doc.content_at('./xmlns:duration'))
46
- track.duration = duration.to_f / 1000
46
+ track.duration = duration.to_i
47
47
  end
48
48
  end
49
49
  end
@@ -53,7 +53,7 @@ module Playlist::Format::XSPF
53
53
  xml.location(track.location) unless track.location.nil?
54
54
  xml.title(track.title) unless track.title.nil?
55
55
  xml.creator(track.creator) unless track.creator.nil?
56
- xml.duration((track.duration * 1000).to_i) unless track.duration.nil?
56
+ xml.duration(track.duration) unless track.duration.nil?
57
57
  end
58
58
  end
59
59
  end
@@ -32,13 +32,13 @@ class Playlist::Track
32
32
  # @return [String]
33
33
  attr_accessor :publisher
34
34
 
35
- # The time a track starts playing at, in seconds.
36
- # May be a Float to include fractions of a second.
35
+ # The time a track starts playing at, in milliseconds
36
+ # May be a Float to include fractions of a millisecond.
37
37
  # @return [Integer, Float]
38
38
  attr_accessor :start_time
39
39
 
40
- # The duration of the track in seconds.
41
- # May be a Float to include fractions of a second.
40
+ # The duration of the track in milliseconds
41
+ # May be a Float to include fractions of a millisecond.
42
42
  # @return [Integer, Float]
43
43
  attr_reader :duration
44
44
 
@@ -132,16 +132,16 @@ class Playlist::Track
132
132
 
133
133
  # Set the duration of the track
134
134
  # If the duration is 0 or -1, then the duration is set to nil
135
- # @param seconds [Numeric] the duration of the track in seconds
136
- def duration=(seconds)
137
- if seconds.is_a?(Numeric)
138
- @duration = seconds
135
+ # @param milliseconds [Numeric] the duration of the track in seconds
136
+ def duration=(milliseconds)
137
+ if milliseconds.is_a?(Numeric)
138
+ @duration = milliseconds
139
139
  else
140
- seconds = seconds.to_s
141
- @duration = if seconds =~ /\./
142
- seconds.to_f
140
+ milliseconds = milliseconds.to_s
141
+ @duration = if milliseconds =~ /\./
142
+ milliseconds.to_f
143
143
  else
144
- seconds.to_i
144
+ milliseconds.to_i
145
145
  end
146
146
  end
147
147
  @duration = nil if [0, -1].include?(@duration)
@@ -1,4 +1,4 @@
1
1
  class Playlist
2
2
  # The version number of the Playlist Ruby gem
3
- VERSION = '0.2.0'
3
+ VERSION = '1.0.0'
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: playlist
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nicholas Humfrey
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-07-23 00:00:00.000000000 Z
11
+ date: 2018-08-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri