コード例 #1
0
ファイル: song_model_tests.py プロジェクト: spncrlkt/gillard
    def test_new_song_has_played_at(self):
        with gillard.app.app_context():
            song = Song()

            song = test_utils.save_and_refresh(
                gillard.db.session, song
            )

            # played_at starts empty
            assert song.played_at is None

            song.artist = 'fake_ass_bullshit'

            song = test_utils.save_and_refresh(
                gillard.db.session, song
            )

            # played_at doesn't update unless 'played' changes
            assert song.played_at is None

            song.played = True

            song = test_utils.save_and_refresh(
                gillard.db.session, song
            )

            # on update played field, played_at gets set to now-ish
            assert (datetime.datetime.now() - song.played_at).\
                total_seconds() < 2
コード例 #2
0
ファイル: scrape.py プロジェクト: nickhs/hypeliberator
    def _fetch_data(self, url):
        '''
        Actual fetching of song information from remote server
        pased on the url provided

        Returns True or False depending on whether the request/parsing
        succeeded
        '''

        resp = requests.get(url)

        if not resp.ok:
            print "Failed to get %s [%s]" % (resp.url, resp.status_code)
            return False

        try:
            data = resp.json()
        except ValueError as e:
            print e
            return False

        if not data:
            return False

        count = 0

        while count < 100:
            if str(count) not in data:
                break

            track = data[str(count)]
            song = self._check_id(track['mediaid'])

            if not song:
                song = Song(track['mediaid'])
                song.title = track['title']
                song.artist = track['artist']
                song.url = track['stream_url_raw']
                db.session.add(song)
            else:
                song.downloaded += 1
                song.url = track['stream_url_raw']
                db.session.add(song)

            db.session.commit()

            self.songs.append(song)
            count += 1

        return True
コード例 #3
0
ファイル: scrape.py プロジェクト: jeremydeanw/hypeliberator
    def _fetch_data(self, url):
        '''
        Actual fetching of song information from remote server
        pased on the url provided

        Returns True or False depending on whether the request/parsing
        succeeded
        '''

        resp = requests.get(url)

        if not resp.ok:
            print "Failed to get %s [%s]" % (resp.url, resp.status_code)
            return False

        try:
            data = resp.json()
        except ValueError as e:
            print e
            return False

        if not data:
            return False

        count = 0

        while count < 100:
            if str(count) not in data:
                break

            track = data[str(count)]
            song = self._check_id(track['mediaid'])

            if not song:
                song = Song(track['mediaid'])
                song.title = track['title']
                song.artist = track['artist']
                song.url = track['stream_url_raw']
                db.session.add(song)
            else:
                song.downloaded += 1
                song.url = track['stream_url_raw']
                db.session.add(song)

            db.session.commit()

            self.songs.append(song)
            count += 1

        return True
コード例 #4
0
    def test_new_song_has_updated_at(self):
        with gillard.app.app_context():
            song = Song()

            song = test_utils.save_and_refresh(gillard.db.session, song)

            # updated_at starts empty
            assert song.updated_at is None

            song.artist = 'fake_ass_bullshit'

            song = test_utils.save_and_refresh(gillard.db.session, song)

            # on update, updated_at gets set to now-ish
            assert (datetime.datetime.now() - song.updated_at).\
                total_seconds() < 2
コード例 #5
0
ファイル: scrape.py プロジェクト: lubibul/hypeliberator
    def _fetch_data(self, url):
        resp = requests.get(url)

        if not resp.ok:
            print "Failed to get %s [%s]" % (resp.url, resp.status_code)
            return False

        try:
            data = resp.json()
        except ValueError as e:
            print e
            return False

        if not data:
            return False

        count = 0

        while count < 100:
            if str(count) not in data:
                break

            track = data[str(count)]
            song = self._check_id(track['mediaid'])

            if not song:
                song = Song(track['mediaid'])
                song.title = track['title']
                song.artist = track['artist']
                song.url = track['stream_url_raw']
                db.session.add(song)
            else:
                song.downloaded += 1
                song.url = track['stream_url_raw']
                db.session.add(song)

            db.session.commit()

            self.songs.append(song)
            count += 1

        return True
コード例 #6
0
ファイル: song_model_tests.py プロジェクト: spncrlkt/gillard
    def test_new_song_has_updated_at(self):
        with gillard.app.app_context():
            song = Song()

            song = test_utils.save_and_refresh(
                gillard.db.session, song
            )

            # updated_at starts empty
            assert song.updated_at is None

            song.artist = 'fake_ass_bullshit'

            song = test_utils.save_and_refresh(
                gillard.db.session, song
            )

            # on update, updated_at gets set to now-ish
            assert (datetime.datetime.now() - song.updated_at).\
                total_seconds() < 2
コード例 #7
0
    def test_new_song_has_played_at(self):
        with gillard.app.app_context():
            song = Song()

            song = test_utils.save_and_refresh(gillard.db.session, song)

            # played_at starts empty
            assert song.played_at is None

            song.artist = 'fake_ass_bullshit'

            song = test_utils.save_and_refresh(gillard.db.session, song)

            # played_at doesn't update unless 'played' changes
            assert song.played_at is None

            song.played = True

            song = test_utils.save_and_refresh(gillard.db.session, song)

            # on update played field, played_at gets set to now-ish
            assert (datetime.datetime.now() - song.played_at).\
                total_seconds() < 2
コード例 #8
0
ファイル: db.py プロジェクト: OrnIngvar/guitarparty
def process_mp3_song(path):
    tag = eyeD3.Tag()
    tag.link(path)
    song = Song()
    # Check if song is already in DB
    s_id = None
    song_is_dupe = False
    song_exists = Song.select().where(path=path)
    for s in song_exists:
        s_id = s.id
        song_is_dupe = True

    if tag.getTitle() and tag.getArtist() and tag.getAlbum() and tag.getGenre() and not song_is_dupe:
        song.title = tag.getTitle()
        song.artist = tag.getArtist()
        song.album = tag.getAlbum()
        song.genre = tag.getGenre().getName()
        song.path = path
        song.save()
        return 'ok'
    elif tag.getTitle() and tag.getArtist() and tag.getAlbum() and not song_is_dupe:
        song.title = tag.getTitle()
        song.artist = tag.getArtist()
        song.album = tag.getAlbum()
        song.path = path
        song.save()
        return 'ok'
    elif tag.getTitle() and tag.getArtist() and not song_is_dupe:
        song.title = tag.getTitle()
        song.artist = tag.getArtist()
        song.path = path
        song.save()
        return 'ok'
    elif tag.getTitle() and not song_is_dupe:
        song.title = tag.getTitle()
        song.path = path
        song.save()
        return 'ok'
    elif tag.getArtist() and not song_is_dupe:
        song.artist = tag.getArtist()
        song.path = path
        song.save()
        return 'ok'
    elif tag.getAlbum() and not song_is_dupe:
        song.album = tag.getAlbum()
        song.path = path
        song.save()
        return 'ok'
    elif tag.getGenre() and not song_is_dupe:
        song.genre = tag.getGenre().getName()
        song.path = path
        song.save()
        return 'ok'
    # Song already exists in db so we only update the tags if by any chance the user updated them and uploaded again
    elif song_is_dupe:
        print 'song is duplicate'
        song.id = s_id
        if tag.getTitle():
            song.title = tag.getTitle()
        if tag.getArtist():
            song.artist = tag.getArtist()
        if tag.getAlbum():
            song.album = tag.getAlbum()
        if tag.getGenre():
            song.genre = tag.getGenre().getName()
        song.save()
        return 'ok'


    elif path:
        song.path = path
        song.save()
        return 'no tags'