Пример #1
0
    def register(cls, batch=100):
        """Crawls concerts with no tracks in batches of 100 and
        populate their tracks in your db. Crawling tracks can take a
        long time (a few days) especially on low-performance
        machines. You may wish to run `Track.register()` in multiple
        python instances to crawl tracks concurrently. It is naively
        architected to avoid duplicates.

        usage:
        >>> from api.music import Track
        >>> Track.register()
        """
        while True:
            try:
                offset = randint(0, int(Concert.query.count() / batch))
                concerts = Concert.trackless_concerts(
                    limit=batch, offset=offset
                    )
                if not concerts:
                    break
                for concert in concerts:
                    print("%s CONCERT: %s" % ("*" * 10, concert.tag))
                    concert.register_tracks()
                    # remove concert if it still has no tracks after
                    # attempting to crawl.  (likely book / some other
                    # media accidentally include)
                    if not concert.tracks:
                        print("Removing %s" % concert.tag)
                        concert.remove()
            except (ObjectDeletedError, InvalidRequestError):
                db.remove()
Пример #2
0
    def register_songs(self):
        """Discovers and creates db entries for the Songs of this
        Album through the musixmatch api.

        usage:
        >>> from api.music import Artist
        >>> a = Artist.get(tag="ExplosionsintheSky")
        >>> a.albums[0].register_songs()
        """
        songs = Musix.album_songs(self.musixmatch)
        for song in songs:
            print(song)
            try:
                s = Song.get(musixmatch=str(song['track_id']))
            except core.GrooveboxException:
                s = Song(musixmatch=str(song['track_id']),
                         name=song['track_name'],
                         artist_id=self.artist_id)
                s.create()
            s.albums.append(self)

            try:
                s.save()
            except Exception:
                db.remove()
Пример #3
0
 def inner(*args, **kwargs):
     try:
         try:
             res = f(*args, **kwargs)
             if isinstance(res, wrappers.Response):
                 return res
             response = Response(json.dumps(res, cls=DatetimeEncoder))
         except Exception as e:
             top = traceback.extract_stack()[-1]
             r = {
                 "message":
                 str(e),
                 "error":
                 ', '.join([
                     type(e).__name__,
                     os.path.basename(top[0]),
                     str(top[1])
                 ])
             }
             response = Response(json.dumps(r))
         response.headers.add('Content-Type', 'application/json')
         response.headers['Access-Control-Allow-Credentials'] = 'true'
         return response
     finally:
         db.rollback()
         db.remove()
Пример #4
0
 def inner(*args, **kwargs):
     try:
         return jsonify(f(*args, **kwargs))
     except Exception as e:
         return jsonify({"error": str(e)})
     finally:
         db.rollback()
         db.remove()
Пример #5
0
 def inner(*args, **kwargs):
     try:
         return jsonify(f(*args, **kwargs))
     except Exception as e:
         return jsonify({"error": str(e)})
     finally:
         db.rollback()
         db.remove()
Пример #6
0
 def inner(*args, **kwargs):
     try:
         try:
             res = f(*args, **kwargs)
             if isinstance(res, wrappers.Response):
                 return res
             response = Response(json.dumps(res, cls=DatetimeEncoder))
         except Exception as e:
             top = traceback.extract_stack()[-1]
             r = {"message": str(e)}
             if DEBUG:
                 r['error'] = ', '.join([type(e).__name__,
                                         os.path.basename(top[0]),
                                         str(top[1])
                                         ])
             response = Response(json.dumps(r))
         response.headers.add('Content-Type', 'application/json')
         response.headers['Access-Control-Allow-Credentials'] = 'true'
         return response
     finally:
         db.rollback()
         db.remove()
Пример #7
0
def shutdown_session(exception=None):
    # Removes db session at the end of each request
    db.remove()