1
0
Fork 0

Import script works fine

This commit is contained in:
magnolia-fan 2011-06-14 22:06:46 +04:00
parent 908f18c7de
commit cb42a55f9d
12 changed files with 118 additions and 13 deletions

View File

@ -7,6 +7,7 @@ gem 'rails', '3.0.8'
gem 'sqlite3'
gem 'pg'
gem 'awesome_print', :require => 'ap'
# Use unicorn as the web server
# gem 'unicorn'

View File

@ -29,6 +29,7 @@ GEM
activesupport (= 3.0.8)
activesupport (3.0.8)
arel (2.0.10)
awesome_print (0.4.0)
builder (2.1.2)
erubis (2.6.6)
abstract (>= 1.0.0)
@ -70,6 +71,7 @@ PLATFORMS
ruby
DEPENDENCIES
awesome_print
pg
rails (= 3.0.8)
sqlite3

View File

@ -0,0 +1,2 @@
class ArtistController < ApplicationController
end

View File

@ -0,0 +1,2 @@
module ArtistHelper
end

Binary file not shown.

View File

@ -0,0 +1,9 @@
class AddPicUrlToArtist < ActiveRecord::Migration
def self.up
add_column :artists, :pic_url, :string
end
def self.down
remove_column :artists, :pic_url
end
end

View File

@ -0,0 +1,9 @@
class AddLengthToTrack < ActiveRecord::Migration
def self.up
add_column :tracks, :length, :integer
end
def self.down
remove_column :tracks, :length
end
end

View File

@ -10,7 +10,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20110613135648) do
ActiveRecord::Schema.define(:version => 20110614175827) do
create_table "albums", :force => true do |t|
t.string "name"
@ -27,6 +27,7 @@ ActiveRecord::Schema.define(:version => 20110613135648) do
t.text "desc"
t.datetime "created_at"
t.datetime "updated_at"
t.string "pic_url"
end
create_table "tracks", :force => true do |t|
@ -38,6 +39,7 @@ ActiveRecord::Schema.define(:version => 20110613135648) do
t.integer "acoustic"
t.datetime "created_at"
t.datetime "updated_at"
t.integer "length"
end
end

View File

@ -1,6 +1,72 @@
namespace :db do
desc 'Imports data from MusicBrainz database'
task :import => :environment do
ati = ['Kasabian']
ati.each do |name|
# Get artist from MB
mb_artist = MusicBrainzArtist.getByName(name)
# Save artist
artist = Artist.new
artist.name = mb_artist.name
artist.desc = 'test import desc'
artist.pic_url = '/images/dummy.png'
artist.save
# Get albums from MB
mb_albums = MusicBrainzAlbum.where('artist_id = ? AND release_type = 1', mb_artist.id).order('year ASC, id ASC')
mb_albums.each do |mb_album|
# Saving album
album = Album.new
album.name = mb_album.name
album.artist_id = artist.id
album.status = 1
album.pic_url = '/images/dummy.png'
album.save
# Get album releases from MB
mb_releases = MusicBrainzRelease.where('album_id = ? AND release_type = 1', mb_album.id).order('date ASC, id ASC')
# Get tracks from the first release and then exclude release
mb_main_tracks = MusicBrainzTrack.where('release_id IN (?)', mb_releases.shift.id).order('position ASC')
# Creating hashed array for matching
mb_main_tracks_hashed = []
mb_main_tracks.each do |mb_track|
mb_main_tracks_hashed << mb_track.name.downcase.scan(/[a-z0-9]*/).join
end
# Getting other releases ids
release_ids = []
mb_releases.each do |mb_release|
release_ids << mb_release.id
end
# Searching for tracks in other releases
mb_other_tracks = MusicBrainzTrack.where('release_id IN (?)', release_ids).order('position ASC')
mb_bonus_tracks = []
mb_other_tracks.each do |mb_track|
unless mb_main_tracks_hashed.include? mb_track.name.downcase.scan(/[a-z0-9]*/).join
mb_bonus_tracks << mb_track
end
end
# Saving tracks
mb_main_tracks.each do |mb_track|
track = Track.new
track.name = mb_track.name
track.album_id = album.id
track.position = mb_track.position
track.length = mb_track.length
track.bonus = 0
track.live = mb_track.name.downcase.include? 'live'
track.acoustic = mb_track.name.downcase.include? 'acoustic'
track.save
end
mb_bonus_tracks.each do |mb_track|
track = Track.new
track.name = mb_track.name
track.album_id = album.id
track.position = mb_track.position
track.length = mb_track.length
track.bonus = 1
track.live = mb_track.name.downcase.include? 'live'
track.acoustic = mb_track.name.downcase.include? 'acoustic'
track.save
end
end
end
end
end

View File

@ -3,18 +3,18 @@
<head>
<title>BetaHaven</title>
<meta charset="utf-8"/>
<link rel="stylesheet" type="text/css" media="screen" href="css/layout.css" />
<link rel="stylesheet" type="text/css" media="screen" href="css/misc.css" />
<link rel="stylesheet" type="text/css" media="screen" href="css/player.css" />
<link rel="stylesheet" type="text/css" media="screen" href="css/albums.css" />
<script type="text/javascript" charset="utf-8" src="js/jquery.min.js"></script>
<script type="text/javascript" charset="utf-8" src="js/layout.js"></script>
<script type="text/javascript" charset="utf-8" src="js/ajax.js"></script>
<script type="text/javascript" charset="utf-8" src="js/pages.js"></script>
<script type="text/javascript" charset="utf-8" src="js/audio.js"></script>
<script type="text/javascript" charset="utf-8" src="js/player.js"></script>
<link rel="stylesheet" type="text/css" media="screen" href="stylesheets/layout.css" />
<link rel="stylesheet" type="text/css" media="screen" href="stylesheets/misc.css" />
<link rel="stylesheet" type="text/css" media="screen" href="stylesheets/player.css" />
<link rel="stylesheet" type="text/css" media="screen" href="stylesheets/albums.css" />
<script type="text/javascript" charset="utf-8" src="javascripts/jquery.min.js"></script>
<script type="text/javascript" charset="utf-8" src="javascripts/layout.js"></script>
<script type="text/javascript" charset="utf-8" src="javascripts/ajax.js"></script>
<script type="text/javascript" charset="utf-8" src="javascripts/pages.js"></script>
<script type="text/javascript" charset="utf-8" src="javascripts/audio.js"></script>
<script type="text/javascript" charset="utf-8" src="javascripts/player.js"></script>
<script type="text/javascript" charset="windows-1251" src="http://vkontakte.ru/js/api/openapi.js"></script>
<script type="text/javascript" charset="utf-8" src="js/vkontakte.js"></script>
<script type="text/javascript" charset="utf-8" src="javascripts/vkontakte.js"></script>
</head>
<body>

View File

@ -0,0 +1,8 @@
require 'test_helper'
class ArtistControllerTest < ActionController::TestCase
# Replace this with your real tests.
test "the truth" do
assert true
end
end

View File

@ -0,0 +1,4 @@
require 'test_helper'
class ArtistHelperTest < ActionView::TestCase
end