<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>app/views/track/lfm_list.html.erb</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -146,4 +146,11 @@ class TrackController &lt; ApplicationController
 
     render :layout =&gt; false
   end
+  
+  def lfm_list
+    @title = &quot;Your recent favourite tracks&quot;
+    if logged_in?
+      @tracks = Lastfming.get_recent_top_tracks(current_user)
+    end
+  end
 end
\ No newline at end of file</diff>
      <filename>app/controllers/track_controller.rb</filename>
    </modified>
    <modified>
      <diff>@@ -54,6 +54,7 @@ ActionController::Routing::Routes.draw do |map|
   map.connect 'track/latest', :controller =&gt; 'track', :action =&gt; 'latest'
   map.connect 'track/latest.xml', :controller =&gt; 'track', :action =&gt; 'latest', :format =&gt; 'xml'
   map.connect 'track/list_xml', :controller =&gt; 'track', :action =&gt; 'list_xml', :format =&gt; 'xml'
+  map.connect 'track/lfm_list', :controller =&gt; 'track', :action =&gt; 'lfm_list'
   map.connect 'track/:permalink', :controller =&gt; 'track', :action =&gt; 'show', :format =&gt; 'html'
   
   map.signup '/claim', :controller =&gt; 'users', :action =&gt; 'claim' </diff>
      <filename>config/routes.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,6 +1,6 @@
 module Lastfming
   
-  #WEEKLY_TRACK_CHART_BASE_URL = &quot;http://ws.audioscrobbler.com/2.0/?method=user.getweeklytrackchart&amp;api_key=#{API_KEY}&amp;user=&quot;
+  WEEKLY_TRACK_CHART_BASE_URL = &quot;http://ws.audioscrobbler.com/2.0/?method=user.getweeklytrackchart&amp;api_key=#{Configuring.get(&quot;last_fm_api_key&quot;)}&quot;
   
   # def self.try_to_add_track(audiography)
   #   added_track = nil
@@ -18,23 +18,50 @@ module Lastfming
   #   track_data[:playcount].to_i &gt; 0 &amp;&amp; !audiography.contains_track?(nil, track_data[:title], track_data[:artist])
   # end
   
-  # def self.get_recent_top_tracks(user)
-  #   tracks = []
-  #   if user.last_fm_username
-  #     xml = APIUtil.response_to_xml(get_weekly_track_chart(user.last_fm_username))
-  #     xml.elements.each(&quot;lfm/weeklytrackchart/track&quot;) do |data|
-  #       track = {}
-  #       track[:artist] = data.elements[&quot;artist&quot;].text if data.elements[&quot;artist&quot;]
-  #       track[:title] = data.elements[&quot;name&quot;].text if data.elements[&quot;name&quot;]
-  #       track[:playcount] = data.elements[&quot;playcount&quot;].text if data.elements[&quot;playcount&quot;]
-  #       tracks &lt;&lt; track
-  #     end
-  #   end
-  #   
-  #   return tracks
-  # end
+  def self.get_recent_top_tracks(user)
+    recent_top_tracks = {}
+    if user &amp;&amp; user.last_fm_username
+      all_month_tracks = []
+      all_month_tracks += get_weekly_tracks(user.last_fm_username, 1.week.ago.tv_sec, Time.new.tv_sec)
+      all_month_tracks += get_weekly_tracks(user.last_fm_username, 2.weeks.ago.tv_sec, 1.week.ago.tv_sec)
+      all_month_tracks += get_weekly_tracks(user.last_fm_username, 3.weeks.ago.tv_sec, 2.weeks.ago.tv_sec)
+      all_month_tracks += get_weekly_tracks(user.last_fm_username, 4.weeks.ago.tv_sec, 3.weeks.ago.tv_sec)
+      
+      for all_month_track in all_month_tracks
+        identifier = all_month_track[:artist] + all_month_track[:title]
+        if recent_top_tracks.has_key?(identifier)
+          if Util.ne(all_month_track[:playcount])
+            recent_top_tracks[identifier][:playcount] = recent_top_tracks[identifier][:playcount].to_i + all_month_track[:playcount].to_i 
+          end
+        else
+          recent_top_tracks[identifier] = all_month_track
+        end
+      end
+    end
+    
+    return recent_top_tracks
+  end
   
-  # def self.get_weekly_track_chart(username)
-  #   Util.ne(username) ? APIUtil.get_request(WEEKLY_TRACK_CHART_BASE_URL + username) : nil
-  # end
+  def self.get_weekly_tracks(username, from, to)
+    tracks = []
+    xml = APIUtil.response_to_xml(get_weekly_track_chart(username, from, to))
+    xml.elements.each(&quot;lfm/weeklytrackchart/track&quot;) do |data|
+      track = {}
+      artist = data.elements[&quot;artist&quot;].text if data.elements[&quot;artist&quot;] &amp;&amp; Util.ne(data.elements[&quot;artist&quot;].text)
+      title = data.elements[&quot;name&quot;].text if data.elements[&quot;name&quot;] &amp;&amp; Util.ne(data.elements[&quot;name&quot;].text)
+      playcount = data.elements[&quot;playcount&quot;].text.to_i if data.elements[&quot;playcount&quot;] &amp;&amp; Util.ne(data.elements[&quot;playcount&quot;].text)
+      if artist &amp;&amp; title &amp;&amp; playcount
+        track[:artist] = artist
+        track[:title] = title
+        track[:playcount] = playcount
+        tracks &lt;&lt; track
+      end
+    end
+    
+    return tracks
+  end
+  
+  def self.get_weekly_track_chart(username, from, to)
+    APIUtil.get_request(WEEKLY_TRACK_CHART_BASE_URL + &quot;&amp;user=#{username}&amp;from=#{from}&amp;to=#{to}&quot;)
+  end
 end
\ No newline at end of file</diff>
      <filename>lib/lastfming.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>f7010b346c31b3d3e6eb5394f2072b5ee0248d3e</id>
    </parent>
  </parents>
  <author>
    <name>Mary Cook</name>
    <email>maryrosecook@maryrosecookhom.home</email>
  </author>
  <url>http://github.com/maryrosecook/playmary/commit/0343e57cf0d85631c0a6ce92633ca7965aac6025</url>
  <id>0343e57cf0d85631c0a6ce92633ca7965aac6025</id>
  <committed-date>2009-10-10T16:46:55-07:00</committed-date>
  <authored-date>2009-10-10T16:46:55-07:00</authored-date>
  <message>shows user their favourite tracks from the last month according to last.fm (if they have set a last.fm username which is impossible via the web interface)</message>
  <tree>4bff17c33d964960894c476bead3383f5a2b9502</tree>
  <committer>
    <name>Mary Cook</name>
    <email>maryrosecook@maryrosecookhom.home</email>
  </committer>
</commit>
