Skip to content
Snippets Groups Projects
Commit b0412b48 authored by Per Cederqvist's avatar Per Cederqvist
Browse files

Sort recordings on receive time.

Properly store when a recording was received.  Sort the recordings on
that column.

Fix the _list.rhtml template so that it is more nice.  Add ID3 tags to
the MP3 files.
parent 277431a5
No related branches found
No related tags found
No related merge requests found
...@@ -26,7 +26,7 @@ class RecordingsController < ApplicationController ...@@ -26,7 +26,7 @@ class RecordingsController < ApplicationController
@recording_pages, @recordings = paginate :recordings, @recording_pages, @recordings = paginate :recordings,
:per_page => 10, :per_page => 10,
:conditions => [ "(user_id = ? OR user_id IS NULL)", user_id], :conditions => [ "(user_id = ? OR user_id IS NULL)", user_id],
:order => "updated_on" :order => "`when` desc"
end end
def show def show
...@@ -87,13 +87,20 @@ class RecordingsController < ApplicationController ...@@ -87,13 +87,20 @@ class RecordingsController < ApplicationController
timestamp = $2 timestamp = $2
cid = $3 cid = $3
mp3file = dir + "/mp3/v-" + pid + "-" + timestamp + "-" + cid + ".mp3" mp3file = dir + "/mp3/v-" + pid + "-" + timestamp + "-" + cid + ".mp3"
record_time = Time.at(timestamp.to_i)
id3title = "Nr " + cid + record_time.strftime(" at %Y-%m-%d %H:%M:%S.")
id3artist = cid
id3album = record_time.strftime("Answering machine %Y-%m-%d")
system("rmdtopvf " + dir + "/incoming/" + system("rmdtopvf " + dir + "/incoming/" +
filename + "| pvftowav " + filename + "| pvftowav " +
"| lame -h - " + mp3file) "| lame -h --add-id3v2" +
record_time = Time.at(timestamp.to_i) " --tt '" + id3title + "'" +
" --ta '" + id3artist + "'" +
" --tl '" + id3album + "'" +
" - " + mp3file)
mp3info = Mp3Info.new(mp3file) mp3info = Mp3Info.new(mp3file)
recording = Recording.new(:cid => cid, recording = Recording.new(:cid => cid,
:when => timestamp, :when => record_time,
:file => mp3file, :file => mp3file,
:length => mp3info.length, :length => mp3info.length,
:seen => 0, :seen => 0,
...@@ -104,5 +111,6 @@ class RecordingsController < ApplicationController ...@@ -104,5 +111,6 @@ class RecordingsController < ApplicationController
# dir + "/archived/" + filename) # dir + "/archived/" + filename)
end end
end end
@recordings.sort!
end end
end end
class Recording < ActiveRecord::Base class Recording < ActiveRecord::Base
belongs_to :user belongs_to :user
def <=>(other)
# Reverse the order, to get the newest entry first.
other["when"] <=> self["when"]
end
end end
<table> <% special_columns = ["when", "length"] %>
<% ignored_columns = ["file", "created_on", "updated_on"] %>
<% first_columns = ["when", "cid", "from", "length", "user_id", "comment"] %>
<table border="1">
<tr> <tr>
<th>&nbsp;</th> <th>&nbsp;</th>
<% for column_name in first_columns %>
<th><%= Recording.columns_hash[column_name].human_name %></th>
<%end%>
<% for column in Recording.content_columns %> <% for column in Recording.content_columns %>
<% if not (ignored_columns + first_columns).include?(column.name) %>
<th><%= column.human_name %></th> <th><%= column.human_name %></th>
<% end %> <% end %>
<% end %>
</tr> </tr>
<% for recording in @recordings %> <% for recording in @recordings %>
<tr> <tr>
<td><%= link_to 'Play', :action => 'play', :id => recording %></td> <td><%= link_to 'Play', :action => 'play', :id => recording %></td>
<% for column_name in first_columns %>
<td>
<% if special_columns.include?(column_name) %>
<% if column_name == "when" %>
<%= recording["when"].strftime("%Y-%m-%d&nbsp;%H:%M:%S") %>
<% elsif column_name == "length" %>
<%= (10*recording["length"].to_f).round / 10.0 %>
<% end %>
<% else %>
<%=h recording.send(column_name) %>
<%end%>
</td>
<%end%>
<% for column in Recording.content_columns %> <% for column in Recording.content_columns %>
<% if not (ignored_columns + first_columns).include?(column.name) %>
<td><%=h recording.send(column.name) %></td> <td><%=h recording.send(column.name) %></td>
<% end %> <% end %>
<% end %>
<td><%= link_to 'Show', :action => 'show', :id => recording %></td> <td><%= link_to 'Show', :action => 'show', :id => recording %></td>
<td><%= link_to 'Edit', :action => 'edit', :id => recording %></td> <td><%= link_to 'Edit', :action => 'edit', :id => recording %></td>
<td><%= link_to 'Destroy', { :action => 'destroy', :id => recording }, :confirm => 'Are you sure?', :post => true %></td> <td><%= link_to 'Destroy', { :action => 'destroy', :id => recording }, :confirm => 'Are you sure?', :post => true %></td>
......
...@@ -12,6 +12,7 @@ class Initial < ActiveRecord::Migration ...@@ -12,6 +12,7 @@ class Initial < ActiveRecord::Migration
:options => 'ENGINE=InnoDB DEFAULT CHARSET=utf8') do |t| :options => 'ENGINE=InnoDB DEFAULT CHARSET=utf8') do |t|
t.column :cid, :string t.column :cid, :string
t.column :from, :string t.column :from, :string
t.column :comment, :string
t.column :when, :datetime t.column :when, :datetime
t.column :user_id, :integer t.column :user_id, :integer
t.column :file, :string t.column :file, :string
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment