コード例 #1
0
 def setUp(self):
     for model in (
             PlaylistTrack, Playlist, User,
             Album, Artist, Track ):
         for obj in model.all():
             obj.delete()
             
     # some data to work with:
     self.stevie = Artist.create(name="Stevie Wonder")
     self.stevie.put()
     self.talking_book = Album(
         album_id=1, # faux
         artist=self.stevie, 
         title="Talking Book",
         import_timestamp=datetime.datetime.now(),
         num_tracks=10)
     self.talking_book.put()
     self.tracks = {}
     for idx, title in enumerate([
             'You Are The Sunshine Of My Life',
             'Maybe Your Baby',
             'You And I (We Can Conquer The World)'
             # ...etc...
             ]):
         track = Track(
                     album=self.talking_book,
                     title=title,
                     sampling_rate_hz=44000,
                     bit_rate_kbps=256,
                     channels='stereo',
                     duration_ms=60*60*3, # faux
                     track_num=idx+1)
         self.tracks[title] = track
         track.put()
コード例 #2
0
    def setUp(self):
        for model in (PlaylistTrack, Playlist, User, Album, Artist, Track):
            for obj in model.all():
                obj.delete()

        # some data to work with:
        self.stevie = Artist.create(name="Stevie Wonder")
        self.stevie.put()
        self.talking_book = Album(
            album_id=1,  # faux
            artist=self.stevie,
            title="Talking Book",
            import_timestamp=datetime.datetime.now(),
            num_tracks=10)
        self.talking_book.put()
        self.tracks = {}
        for idx, title in enumerate([
                'You Are The Sunshine Of My Life', 'Maybe Your Baby',
                'You And I (We Can Conquer The World)'
                # ...etc...
        ]):
            track = Track(
                album=self.talking_book,
                title=title,
                sampling_rate_hz=44000,
                bit_rate_kbps=256,
                channels='stereo',
                duration_ms=60 * 60 * 3,  # faux
                track_num=idx + 1)
            self.tracks[title] = track
            track.put()
コード例 #3
0
ファイル: test_views.py プロジェクト: kumar303/chirpradio
def create_stevie_wonder_album_data():
    stevie = Artist.create(name="Stevie Wonder")
    stevie.put()
    talking_book = Album(
        album_id=1,  # faux
        artist=stevie,
        title="Talking Book",
        import_timestamp=datetime.datetime.now(),
        num_tracks=10)
    talking_book.put()
    tracks = {}
    for idx, title in enumerate([
            'You Are The Sunshine Of My Life', 'Maybe Your Baby',
            'You And I (We Can Conquer The World)', 'Tuesday Heartbreak',
            "You've Got It Bad Girl", 'Superstition', 'Big Brother',
            'Blame It On The Sun', "Lookin' For Another Pure Love",
            'I Believe (When I Fall In Love It Will Be Forever)'
    ]):
        track = Track(
            album=talking_book,
            title=title,
            sampling_rate_hz=44000,
            bit_rate_kbps=256,
            channels='stereo',
            duration_ms=60 * 60 * 3,  # faux
            track_num=idx + 1)
        tracks[title] = track
        track.put()

    return stevie, talking_book, tracks
コード例 #4
0
ファイル: test_views.py プロジェクト: kumar303/chirpradio
def create_stevie_wonder_album_data():
    stevie = Artist.create(name="Stevie Wonder")
    stevie.put()
    talking_book = Album(
        album_id=1, # faux
        artist=stevie,
        title="Talking Book",
        import_timestamp=datetime.datetime.now(),
        num_tracks=10)
    talking_book.put()
    tracks = {}
    for idx, title in enumerate([
            'You Are The Sunshine Of My Life',
            'Maybe Your Baby',
            'You And I (We Can Conquer The World)',
            'Tuesday Heartbreak',
            "You've Got It Bad Girl",
            'Superstition',
            'Big Brother',
            'Blame It On The Sun',
            "Lookin' For Another Pure Love",
            'I Believe (When I Fall In Love It Will Be Forever)'
            ]):
        track = Track(
                    album=talking_book,
                    title=title,
                    sampling_rate_hz=44000,
                    bit_rate_kbps=256,
                    channels='stereo',
                    duration_ms=60*60*3, # faux
                    track_num=idx+1)
        tracks[title] = track
        track.put()

    return stevie, talking_book, tracks
コード例 #5
0
ファイル: views.py プロジェクト: kumar303/chirpradio
def bootstrap(request):
    # Don't create dummy playlist tracks if playlist tracks already exist!
    pl_tracks = PlaylistTrack.all().fetch(1)
    if len(pl_tracks) > 0:
        return HttpResponse(status=404)

    playlist = ChirpBroadcast()

    minutes = 0
    tracks = Track.all().fetch(100)
    for track in tracks:
        pl_track = PlaylistTrack(
            playlist=playlist,
            selector=request.user,
            established=datetime.now() - timedelta(minutes=minutes),
            artist=track.album.album_artist,
            album=track.album,
            track=track,
        )
        pl_track.put()
        if minutes > 0 and minutes % 25 == 0:
            pl_break = PlaylistBreak(playlist=playlist, established=datetime.now() - timedelta(minutes=minutes - 1))
            pl_break.put()
        minutes += 5

    return HttpResponseRedirect("/playlists/")
コード例 #6
0
    def test_add_track_linked_to_library(self, fake_tq):
        fake_tq.is_a_stub()
        stevie = Artist.all().filter("name =", "Stevie Wonder")[0]
        talking_book = Album.all().filter("title =", "Talking Book")[0]
        sunshine = Track.all().filter("title =", "You Are The Sunshine Of My Life")[0]

        resp = self.client.post(reverse('playlists_add_event'), {
            'artist_key': stevie.key(),
            'artist': stevie.name,
            'song': "You Are The Sunshine Of My Life",
            'song_key': sunshine.key(),
            'album_key': talking_book.key(),
            'album': talking_book.title,
            'label': "Tamla",
            'label_key': 'Blah'
        })

        self.assertNoFormErrors(resp)
        self.assertRedirects(resp, reverse('playlists_landing_page'))
        # simulate the redirect:
        resp = self.client.get(reverse('playlists_landing_page'))
        context = resp.context[0]
        tracks = [t for t in context['playlist_events']]
        self.assertEquals(tracks[0].artist_name, "Stevie Wonder")
        self.assertEquals(tracks[0].artist.key(), stevie.key())
        self.assertEquals(tracks[0].album_title, "Talking Book")
        self.assertEquals(tracks[0].album.key(), talking_book.key())
        self.assertEquals(tracks[0].track_title, "You Are The Sunshine Of My Life")
        self.assertEquals(tracks[0].track.key(), sunshine.key())
コード例 #7
0
ファイル: test_views.py プロジェクト: CDMirel/chirpradio
    def test_add_track_linked_to_library(self, fake_tq):
        fake_tq.is_a_stub()
        stevie = Artist.all().filter("name =", "Stevie Wonder")[0]
        talking_book = Album.all().filter("title =", "Talking Book")[0]
        sunshine = Track.all().filter("title =", "You Are The Sunshine Of My Life")[0]

        resp = self.client.post(reverse('playlists_add_event'), {
            'artist_key': stevie.key(),
            'artist': stevie.name,
            'song': "You Are The Sunshine Of My Life",
            'song_key': sunshine.key(),
            'album_key': talking_book.key(),
            'album': talking_book.title,
            'label': "Tamla",
            'label_key': 'Blah'
        })

        self.assertNoFormErrors(resp)
        self.assertRedirects(resp, reverse('playlists_landing_page'))
        # simulate the redirect:
        resp = self.client.get(reverse('playlists_landing_page'))
        context = resp.context[0]
        tracks = [t for t in context['playlist_events']]
        self.assertEquals(tracks[0].artist_name, "Stevie Wonder")
        self.assertEquals(tracks[0].artist.key(), stevie.key())
        self.assertEquals(tracks[0].album_title, "Talking Book")
        self.assertEquals(tracks[0].album.key(), talking_book.key())
        self.assertEquals(tracks[0].track_title, "You Are The Sunshine Of My Life")
        self.assertEquals(tracks[0].track.key(), sunshine.key())
コード例 #8
0
ファイル: views.py プロジェクト: kumar303/chirpradio
def bootstrap(request):
    # Don't create dummy playlist tracks if playlist tracks already exist!
    pl_tracks = PlaylistTrack.all().fetch(1)
    if len(pl_tracks) > 0:
        return HttpResponse(status=404)

    playlist = ChirpBroadcast()

    minutes = 0
    tracks = Track.all().fetch(100)
    for track in tracks:
        pl_track = PlaylistTrack(playlist=playlist,
                                 selector=request.user,
                                 established=datetime.now() -
                                 timedelta(minutes=minutes),
                                 artist=track.album.album_artist,
                                 album=track.album,
                                 track=track)
        pl_track.put()
        if minutes > 0 and minutes % 25 == 0:
            pl_break = PlaylistBreak(playlist=playlist,
                                     established=datetime.now() -
                                     timedelta(minutes=minutes - 1))
            pl_break.put()
        minutes += 5

    return HttpResponseRedirect("/playlists/")
コード例 #9
0
    def save(self):
        if not self.current_user:
            raise ValueError("Cannot save() without a current_user")

        playlist_track = PlaylistTrack(playlist=self.playlist,
                                       selector=self.current_user)

        if self.cleaned_data['artist_key']:
            playlist_track.artist = Artist.get(self.cleaned_data['artist_key'])
        else:
            playlist_track.freeform_artist_name = self.cleaned_data['artist']
        if self.cleaned_data['song_key']:
            playlist_track.track = Track.get(self.cleaned_data['song_key'])
        else:
            playlist_track.freeform_track_title = self.cleaned_data['song']
        if self.cleaned_data['album_key']:
            playlist_track.album = Album.get(self.cleaned_data['album_key'])
        elif self.cleaned_data['album']:
            playlist_track.freeform_album_title = self.cleaned_data['album']
        if self.cleaned_data['label']:
            playlist_track.freeform_label = self.cleaned_data['label']
        if self.cleaned_data['song_notes']:
            playlist_track.notes = self.cleaned_data['song_notes']
        if self.cleaned_data['is_heavy_rotation']:
            playlist_track.categories.append('heavy_rotation')
        if self.cleaned_data['is_light_rotation']:
            playlist_track.categories.append('light_rotation')
        if self.cleaned_data['is_local_current']:
            playlist_track.categories.append('local_current')
        if self.cleaned_data['is_local_classic']:
            playlist_track.categories.append('local_classic')
        AutoRetry(playlist_track).save()

        return playlist_track
コード例 #10
0
ファイル: forms.py プロジェクト: kumar303/chirpradio
    def save(self):
        if not self.current_user:
            raise ValueError("Cannot save() without a current_user")

        playlist_track = PlaylistTrack(
                            playlist=self.playlist,
                            selector=self.current_user)

        if self.cleaned_data['artist_key']:
            playlist_track.artist = Artist.get(self.cleaned_data['artist_key'])
        else:
            playlist_track.freeform_artist_name = self.cleaned_data['artist']
        if self.cleaned_data['song_key']:
            playlist_track.track = Track.get(self.cleaned_data['song_key'])
        else:
            playlist_track.freeform_track_title = self.cleaned_data['song']
        if self.cleaned_data['album_key']:
            playlist_track.album = Album.get(self.cleaned_data['album_key'])
        elif self.cleaned_data['album']:
            playlist_track.freeform_album_title = self.cleaned_data['album']
        if self.cleaned_data['label']:
            playlist_track.freeform_label = self.cleaned_data['label']
        if self.cleaned_data['song_notes']:
            playlist_track.notes = self.cleaned_data['song_notes']
        if self.cleaned_data['is_heavy_rotation']:
            playlist_track.categories.append('heavy_rotation')
        if self.cleaned_data['is_light_rotation']:
            playlist_track.categories.append('light_rotation')
        if self.cleaned_data['is_local_current']:
            playlist_track.categories.append('local_current')
        if self.cleaned_data['is_local_classic']:
            playlist_track.categories.append('local_classic')
        AutoRetry(playlist_track).save()

        return playlist_track
コード例 #11
0
    def save(self):
        if not self.current_user:
            raise ValueError("Cannot save() without a current_user")

        playlist_track = PlaylistTrack(
                            playlist=self.playlist,
                            selector=self.current_user)

        if self.cleaned_data['artist_key']:
            playlist_track.artist = Artist.get(self.cleaned_data['artist_key'])
        else:
            playlist_track.freeform_artist_name = self.cleaned_data['artist']
        if self.cleaned_data['song_key']:
            playlist_track.track = Track.get(self.cleaned_data['song_key'])
        else:
            playlist_track.freeform_track_title = self.cleaned_data['song']
        if self.cleaned_data['album_key']:
            playlist_track.album = Album.get(self.cleaned_data['album_key'])
        elif self.cleaned_data['album']:
            playlist_track.freeform_album_title = self.cleaned_data['album']
        if self.cleaned_data['label']:
            playlist_track.freeform_label = self.cleaned_data['label']
        if self.cleaned_data['song_notes']:
            playlist_track.notes = self.cleaned_data['song_notes']
        if self.cleaned_data['is_heavy_rotation']:
            playlist_track.categories.append('heavy_rotation')
        if self.cleaned_data['is_light_rotation']:
            playlist_track.categories.append('light_rotation')
        if self.cleaned_data['is_local_current']:
            playlist_track.categories.append('local_current')
        if self.cleaned_data['is_local_classic']:
            playlist_track.categories.append('local_classic')
        AutoRetry(playlist_track).save()

        trk = playlist_track
        memcache.set('playlist.last_track', {
            'artist_name': trk.artist_name,
            'track_title': trk.track_title,
            'album_title_display': trk.album_title_display,
            'label_display': trk.label_display,
            'notes': trk.notes,
            'key': str(trk.key()),
            'categories': list(trk.categories),
            'selector_key': str(trk.selector.key()),
            'established_display': trk.established.timetuple()[0:7]
        }, 30)

        return playlist_track
コード例 #12
0
ファイル: forms.py プロジェクト: yogee007/chirpradio
    def save(self):
        if not self.current_user:
            raise ValueError("Cannot save() without a current_user")

        playlist_track = PlaylistTrack(playlist=self.playlist,
                                       selector=self.current_user)

        if self.cleaned_data['artist_key']:
            playlist_track.artist = Artist.get(self.cleaned_data['artist_key'])
        else:
            playlist_track.freeform_artist_name = self.cleaned_data['artist']
        if self.cleaned_data['song_key']:
            playlist_track.track = Track.get(self.cleaned_data['song_key'])
        else:
            playlist_track.freeform_track_title = self.cleaned_data['song']
        if self.cleaned_data['album_key']:
            playlist_track.album = Album.get(self.cleaned_data['album_key'])
        elif self.cleaned_data['album']:
            playlist_track.freeform_album_title = self.cleaned_data['album']
        if self.cleaned_data['label']:
            playlist_track.freeform_label = self.cleaned_data['label']
        if self.cleaned_data['song_notes']:
            playlist_track.notes = self.cleaned_data['song_notes']
        if self.cleaned_data['is_heavy_rotation']:
            playlist_track.categories.append('heavy_rotation')
        if self.cleaned_data['is_light_rotation']:
            playlist_track.categories.append('light_rotation')
        if self.cleaned_data['is_local_current']:
            playlist_track.categories.append('local_current')
        if self.cleaned_data['is_local_classic']:
            playlist_track.categories.append('local_classic')
        AutoRetry(playlist_track).save()

        trk = playlist_track
        memcache.set(
            'playlist.last_track', {
                'artist_name': trk.artist_name,
                'track_title': trk.track_title,
                'album_title_display': trk.album_title_display,
                'label_display': trk.label_display,
                'notes': trk.notes,
                'key': str(trk.key()),
                'categories': list(trk.categories),
                'selector_key': str(trk.selector.key()),
                'established_display': trk.established.timetuple()[0:7]
            }, 30)

        return playlist_track
コード例 #13
0
ファイル: tasks.py プロジェクト: lund5000/chirpradio
def play_count(request):
    """View for keeping track of play counts"""
    track_key = request.POST['id']
    track = PlaylistEvent.get(track_key)
    artist_name = track.artist_name
    album = track.album
    if not album:
        # Try to find a compilation album based on track name.
        qs = Track.all().filter('title =', track.track_title)
        for candidate in qs.run():
            if (candidate.track_artist and
                candidate.album.title == track.album_title and
                candidate.track_artist.name == track.artist_name):
                album = candidate.album
                break
        if not album:
            log.info('No album for %s / %s / %s'
                     % (track.artist_name, track.track_title,
                        track.album_title))
    if album and album.is_compilation:
        artist_name = 'Various'

    count = PlayCount.query(artist_name, track.album_title)
    if not count:
        count = PlayCount.create_first(artist_name,
                                       track.album_title,
                                       track.label)

    @db.transactional
    def increment(key):
        ob = db.get(key)
        ob.play_count += 1
        ob.put()

    increment(count.key())

    # See also:
    # https://developers.google.com/appengine/articles/sharding_counters
    return HttpResponse("OK")