Skip to content

Commit

Permalink
glob only valid mp3recs, create show upfront to handle multiple broad…
Browse files Browse the repository at this point in the history
…casts of new show in one batch
  • Loading branch information
codez committed Apr 8, 2017
1 parent 5ca6b65 commit 6655128
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 19 deletions.
4 changes: 2 additions & 2 deletions app/services/import/broadcast_mapping.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ def overlaps?(recording)
end

def fetch_show(attrs = {})
Show.where(name: attrs.fetch(:name)).first_or_initialize.tap do |show|
show.details ||= attrs[:details]
Show.where(name: attrs.fetch(:name)).first_or_create.tap do |show|
show.details = attrs[:details] if attrs[:details].present?
end
end

Expand Down
2 changes: 2 additions & 0 deletions app/services/import/recording/file/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ module File
# time and duration).
class Base

DIGIT_GLOB = '[0-9]'.freeze

include Loggable

class_attribute :pending_glob, :imported_glob, :lossy
Expand Down
2 changes: 1 addition & 1 deletion app/services/import/recording/file/iso8601.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Iso8601 < Base
IMPORTED_SUFFIX = '_imported'.freeze
DATE_GLOB = '[12][019][0-9][0-9]-[0-1][0-9]-[0-3][0-9]'.freeze # yyyy-mm-dd
TIME_GLOB = '[0-2][0-9][0-5][0-9][0-5][0-9]{+,-}[0-2][0-9][0-5]0'.freeze # HHMMSS+ZZZZ
DURATION_GLOB = '[0-9][0-9][0-9]'.freeze # ddd, minutes
DURATION_GLOB = DIGIT_GLOB * 3 # ddd, minutes
FILENAME_GLOB = "#{DATE_GLOB}T#{TIME_GLOB}_#{DURATION_GLOB}".freeze

self.pending_glob = FILENAME_GLOB + '.*'
Expand Down
2 changes: 1 addition & 1 deletion app/services/import/recording/file/mp3_rec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ module File
# mp3rec-05-5-20170203-090000-3600-sec-der_morgen.wav.mp3
class Mp3Rec < SelfContained

self.extension = 'mp3'
self.lossy = true
self.pending_glob = "*#{DIGIT_GLOB * 8}-#{DIGIT_GLOB * 6}-#{DIGIT_GLOB * 4}-sec-*.mp3"

def started_at
@started_at ||= Time.zone.parse(filename_parts[1].tr('-', ' '))
Expand Down
10 changes: 0 additions & 10 deletions app/services/import/recording/file/self_contained.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,8 @@ module Recording
module File
class SelfContained < Base

class_attribute :extension

attr_reader :show_name

class << self

def pending_glob
"*.#{extension}"
end

end

def sequel?(other)
other &&
show_name == other.show_name &&
Expand Down
2 changes: 1 addition & 1 deletion test/integration/import_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class ImportTest < ActiveSupport::TestCase
.expects(:notify_exception)
.with(Import::Recording::TooShortError.new(Import::Recording::File.new(@f5)), instance_of(Hash))

assert_difference('Show.count', 1) do
assert_difference('Show.count', 2) do
assert_difference('Broadcast.count', 2) do
assert_difference('AudioFile.count', 6) do
Import.run
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class Import::BroadcastMapping::Builder::AirtimeDbTest < ActiveSupport::TestCase
morgen_map = mappings.first
assert_equal morgen.name, morgen_map.show.name
assert_equal morgen.description, morgen_map.show.details
assert morgen_map.show.new_record?
assert morgen_map.show.persisted?
assert_equal morgen.name, morgen_map.broadcast.label
assert_equal morgen.description, morgen_map.broadcast.details
assert_equal Time.zone.local(2016, 1, 1, 8), morgen_map.broadcast.started_at
Expand Down
6 changes: 3 additions & 3 deletions test/services/import/broadcast_mapping_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Import::BroadcastMappingTest < ActiveSupport::TestCase
assert_equal 'Morgen', show.name
assert_equal 'La mañana', show.details
assert_equal profiles(:default), show.profile
assert show.new_record?
assert show.persisted?
end

test '#assign_show_attrs uses an existing show' do
Expand All @@ -22,12 +22,12 @@ class Import::BroadcastMappingTest < ActiveSupport::TestCase
assert_equal shows(:info), show
end

test '#assign_show_attrs uses an existing show and keeps details' do
test '#assign_show_attrs uses an existing show and updates details' do
shows(:info).update!(details: 'RaBe Info')
mapping.assign_show(name: 'Info', details: 'Info')

assert_equal 'Info', show.name
assert_equal 'RaBe Info', show.details
assert_equal 'Info', show.details
assert_equal profiles(:important), show.profile
assert_equal shows(:info), show
end
Expand Down

0 comments on commit 6655128

Please sign in to comment.