Пример #1
0
def update_artists(artist_ids):

    for artist in artist_ids:
    	payload = {'api_key': ECHONEST, 'id': 'songkick:artist:'+str(artist)+'',
        'format': 'json', 'bucket': ['genre', 'id:spotify-WW', 'familiarity',
        'discovery', 'hotttnesss', 'artist_location', 'years_active']}
    	url = 'http://developer.echonest.com/api/v4/artist/profile?'

    	r = requests.get(url, params=payload)
    	data = r.json()
        # retrieve the artist record from the db
        artist = Artist.get(artist_id=artist)

        try:
            results = data['response']['artist']
        except KeyError, error:
            print '%s: No data for artist %s %s' % (error, artist.name, artist.artist_id)
            continue

        try:
            echonest_response = results
            genres = results['genres']
            spotify_id = results['foreign_ids'][0]['foreign_id']
            familiarity = results['familiarity']
            hotttnesss = results['hotttnesss']
            years_active = results['years_active']
            location = results['artist_location']
            discovery = results['discovery']

        except KeyError, error:
            print 'An error has occured %s' % error
            pass
Пример #2
0
 def rawPost(self, ballotID, voteID):
     vote = self.getVote(ballotID, voteID)
     id = self.request.get('release.id', default_value=None)
     mbid = self.request.get('release.mbid', default_value=None)
     if id:
         vote.release = db.Key.from_path(Release.kind(), int(id))
     elif mbid:
         vote.release = Release.get(mbid)
     else:
         id = self.request.get('artist.id', default_value=None)
         mbid = self.request.get('artist.mbid', default_value=None)
         if id:
             artist = db.Key.from_path(Artist.kind(), int(id))
         elif mbid:
             artist = Artist.get(mbid)
         else:
             artist = Artist(name=self.request.get('artist'),
                             sortname=self.request.get('sortname'))
             artisturl = self.request.get('artisturl', default_value=None)
             if artisturl:
                 artist.url = artisturl
             artist.put()
         release = Release(artist=artist, title=self.request.get('title'))
         releaseurl = self.request.get('releaseurl', default_value=None)
         if releaseurl:
             release.url = releaseurl
         release.put()
         vote.release = release
     vote.put()
     next = Vote.gql('WHERE release = :1 ORDER BY artist', None).get()
     if next:
         key = next.key()
         self.redirect('../%d/%d' % (key.parent().id(), key.id()))
     else:
         self.redirect('../..')
def addReleases(artist_id, update_artist = True):
  artist_record = Artist.get(id=artist_id)
  musicbrainz_artist = musicbrainz.getBestArtistMatch(artist_record.name)
  release_ids = []

  for release in musicbrainz_artist.getReleases():
    release_ids.append(utils.extractUuid(release.id))

  # These release results do not contain all the information, we must re-query for that info...
  for rid in release_ids:
    release = musicbrainz.getRelease(rid)

    if not release: continue

    release_group_id = utils.extractUuid(release.getReleaseGroup().id)

    try:
      release_group_tracked = Album.get(release_group_id=release_group_id)
    except peewee.DoesNotExist:
      release_group_tracked = None

    if release_group_tracked: continue

    release_record = Album.create(
        musicbrainz_id = rid,
        asin = release.getAsin(),
        release_group_id = release_group_id,
        artist_id = artist_id,
        name = release.getTitle(),
        type = release.getType(),
        released_on = release.getEarliestReleaseDate(),
        state = 'wanted')

    track_number = 1

    for track in release.getTracks():
      Track.create(
          album_id = release_record.id,
          number = track_number,
          title = track.getTitle(),
          length = track.getDuration(),
          state = 'wanted')

      track_number += 1

  # Rescan the Music Library after adding new releases to see if the user has 
  # them or not. Will not run if explicitly told not to by the caller.
  if(update_artist): ThreadPool.put(updateArtist, {'artist_id': artist_id})
def updateArtist(artist_id):
  try:
    artist = Artist.get(id=artist_id)
  except peewee.DoesNotExist:
    artist = None

  if artist:
    for dirpath, dirnames, filenames in os.walk(artist.location):
      logger.debug(u'Now scanning the directory "%s"' % dirpath)

      # Scan all of the files in this directory:
      for filename in filenames:
        # Only scan music files...
        if any(filename.lower().endswith('.' + x.lower()) for x in config.music.formats.split(',')):
          full_path = os.path.join(dirpath, filename)

          # Try to read the tags from the file, move on if we can't.
          try:
            media_file = MediaFile(full_path)

            # connection.action("UPDATE tracks SET track_location=?, track_status=? WHERE album_id IN \
            #     (SELECT album_id FROM albums WHERE album_name LIKE ? AND artist_id IN \
            #     (SELECT artist_id FROM artists WHERE artist_id=?)) AND track_number=?",
            #     (full_path, 'have', media_file.album, artist_id, media_file.track))
          except Exception, e:
            logger.debug(u'Cannot read tags of file "%s" because of the exception "%s"' % (filename, str(e)))
            continue


    for album in artist.albums():
      album_complete = True # Assuming it is complete is easier...

      for track in album.tracks():
        if track.location == None:
          track.state = 'wanted'
          track.save()
          album_complete = False

      # If we have all of the tracks for this album, set the state of the 
      # album to 'have', otherwise we will set them to 'wanted'.
      # 
      # There could be a bug here that if we set the album state to 'wanted'
      # the corresponding, missing tracks might not be set to 'wanted' as well.
      # 
      # Investigate this later...
      album.state = 'have' if album_complete else 'wanted'
      album.save()
def addArtist(id3_artist_name, path):
  musicbrainz_artist = musicbrainz.getBestArtistMatch(id3_artist_name)

  if musicbrainz_artist is None:
    unique_name = id3_artist_name
    artist_mb_id = None
  else:
    unique_name = musicbrainz_artist.getUniqueName()
    artist_mb_id = utils.extractUuid(musicbrainz_artist.id)

  try:
    artist = Artist.get(peewee.Q(musicbrainz_id=artist_mb_id) | peewee.Q(unique_name=unique_name))
  except peewee.DoesNotExist:
    artist = Artist.create(
        name = id3_artist_name,
        unique_name = unique_name,
        location = path,
        state = 'wanted',
        musicbrainz_id = artist_mb_id)

  return artist
Пример #6
0
    def artist(self, id):
        artist = Artist.get(id=id)

        return self.serve_template("artist.html", title=artist.name, artist=artist)
Пример #7
0
import peewee

from models import Album, Artist

band = Artist.select().where(Artist.name == "Kutless").get()
print band.name

# shortcut method
band = Artist.get(Artist.name == "Kutless")
print band.name

# change band name
band.name = "Beach Boys"
band.save()

album = Album.select().join(Artist).where((Album.title == "Thrive")
                                          & (Artist.name == "Newsboys")).get()
album.title = "Step Up to the Microphone"
album.save()

query = Album.select().join(Artist)
qry_filter = ((Album.title == "Step Up to the Microphone") &
              (Artist.name == "Newsboys"))
album = query.where(qry_filter).get()
print album
Пример #8
0
# del_data.py

from models import Artist

band = Artist.get(Artist.name == "MXPX")
band.delete_instance()
Пример #9
0
# edit_data.py
 
import peewee
 
from models import Album, Artist
 
band = Artist.select().where(Artist.name=="Kutless").get()
print (band.name)
 
# shortcut method
band = Artist.get(Artist.name=="Kutless")
print (band.name)
 
# change band name
band.name = "Beach Boys"
band.save()
 
album = Album.select().join(Artist).where(
    (Album.title=="Thrive") & (Artist.name == "Newsboys")
    ).get()
album.title = "Step Up to the Microphone"
album.save()
Пример #10
0
def get_by_id():
    id = ui.get_positive_integer("Enter artist id: ")
    artist = Artist.get(Artist.id == id)
    ui.display(format_artist(artist))
    return artist
Пример #11
0
def scan():
  logger.info(u"Now scanning the music library located at %s." % config.music.directory)

  artists_being_added = []

  for dirpath, dirnames, filenames in os.walk(config.music.directory):
    logger.debug(u'Now scanning the directory "%s"' % unicode(dirpath, errors="ignore"))

    # Scan all of the files in this directory:
    for filename in filenames:
      # Only scan music files...
      if any(filename.lower().endswith('.' + x.lower()) for x in config.music.formats.split(',')):
        logger.debug(u'Now scanning the file "%s"' % unicode(filename, errors="ignore"))

        full_path = os.path.join(dirpath, filename)

        # Try to read the tags from the file, move on if we can't.
        try:
          media_file = MediaFile(full_path)
        except Exception, e:
          logger.debug(u'Cannot read tags of file "%s" because of the exception "%s"' % (unicode(filename, errors="ignore"), str(e)))
          break

        # If we did read the tags, but the artist can't be found, move on to the next file...
        if media_file.albumartist:
          id3_artist = media_file.albumartist
        elif media_file.artist:
          id3_artist = media_file.artist
        else:
          break

        logger.debug(u'Found the artist name "%s" in the ID3 tag of "%s" file.' % (id3_artist, unicode(full_path, errors="ignore")))

        artist_path_parts = []

        for part in dirpath.split('/'):
          artist_path_parts.append(part)

          if id3_artist.lower() in part.lower(): break

        if artist_path_parts:
          artist_path = os.sep.join(artist_path_parts)
        else:
          artist_path = config.music.directory

        # If we already have this artist in the DB only add their releases,
        # we do not need to re-add them to the Music Library.
        try:
          tracked_artist = Artist.get(name=id3_artist)
        except peewee.DoesNotExist:
          tracked_artist = None

        if tracked_artist and tracked_artist.id not in artists_being_added:
          logger.debug(u'Artist name "%s" is already tracked by Headphones, moving on but adding releases...' % id3_artist)

          ThreadPool.put(addReleases, {'artist_id': tracked_artist.id})
          artists_being_added.append(tracked_artist.id)

          break
        else:
          artist_record = addArtist(id3_artist, artist_path)

          if artist_record is not None:
            if artist_record.id not in artists_being_added:
              logger.debug('We have a new artist! Adding them now: artist_id %s' % artist_record.id)

              ThreadPool.put(addReleases, {'artist_id': artist_record.id})
              artists_being_added.append(artist_record.id)

          break