playlist 0.2.0 → 1.0.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.
- checksums.yaml +4 -4
- data/lib/playlist.rb +2 -1
- data/lib/playlist/format/cue.rb +21 -20
- data/lib/playlist/format/m3u.rb +6 -5
- data/lib/playlist/format/simple_text.rb +7 -4
- data/lib/playlist/format/xspf.rb +2 -2
- data/lib/playlist/track.rb +12 -12
- data/lib/playlist/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bc3a6497a40653031438f4692659e4f1136e2a29
|
4
|
+
data.tar.gz: 88e19ff093d5b1eba7569f011f02e2707751daae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7d7baa63b8aed79765ffac6280baa708eb65b5afccc30b40590b7f6383d91bddd1a5d0a9d80c57916c9f05ffc856d5203557cce99953b525e65a025ed2df6593
|
7
|
+
data.tar.gz: 09dfeed3a840b1c3aa8a1e8fb98dd85a3ec1a6175755f18c6dc3e4c2a9a29dcbc1e39d0bdcf58593b3e85d9f8f295dd44e16852b1c15f81632e5ff818ebb6e00
|
data/lib/playlist.rb
CHANGED
@@ -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
|
data/lib/playlist/format/cue.rb
CHANGED
@@ -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
|
14
|
+
elsif (matches = line.match(/^\s*TRACK (\d+) AUDIO/))
|
15
15
|
track = Playlist::Track.new(
|
16
|
-
:track_number =>
|
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
|
48
|
-
track.title =
|
49
|
-
elsif
|
50
|
-
track.performer =
|
51
|
-
elsif
|
52
|
-
track.isrc =
|
53
|
-
elsif
|
54
|
-
track.start_time = parse_time(
|
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
|
62
|
-
playlist.title =
|
63
|
-
elsif
|
64
|
-
playlist.media_location =
|
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
|
94
|
-
if
|
95
|
-
mins =
|
96
|
-
secs =
|
97
|
-
frames =
|
98
|
-
(mins *
|
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
|
data/lib/playlist/format/m3u.rb
CHANGED
@@ -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
|
13
|
-
track.duration =
|
14
|
-
track.creator =
|
15
|
-
track.title =
|
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
|
-
|
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
|
-
|
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 =>
|
26
|
-
:creator =>
|
27
|
-
:title =>
|
28
|
+
:start_time => matches[1],
|
29
|
+
:creator => matches[3].strip,
|
30
|
+
:title => matches[4].strip
|
28
31
|
)
|
29
32
|
end
|
30
33
|
end
|
data/lib/playlist/format/xspf.rb
CHANGED
@@ -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.
|
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(
|
56
|
+
xml.duration(track.duration) unless track.duration.nil?
|
57
57
|
end
|
58
58
|
end
|
59
59
|
end
|
data/lib/playlist/track.rb
CHANGED
@@ -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
|
36
|
-
# May be a Float to include fractions of a
|
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
|
41
|
-
# May be a Float to include fractions of a
|
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
|
136
|
-
def duration=(
|
137
|
-
if
|
138
|
-
@duration =
|
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
|
-
|
141
|
-
@duration = if
|
142
|
-
|
140
|
+
milliseconds = milliseconds.to_s
|
141
|
+
@duration = if milliseconds =~ /\./
|
142
|
+
milliseconds.to_f
|
143
143
|
else
|
144
|
-
|
144
|
+
milliseconds.to_i
|
145
145
|
end
|
146
146
|
end
|
147
147
|
@duration = nil if [0, -1].include?(@duration)
|
data/lib/playlist/version.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2018-08-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|