예제 #1
0
def start():
    song = Song()
    song = test_song_search_resolver(song)
    song = test_song_url_resolver(song)
    song = test_song_lyric_resolver(song)
    song = test_song_detail_resolver(song)
    print(song.to_string())
예제 #2
0
        def post(self, **kwargs):
            image = self.request.files.get('image_upload').read()
            datestring = self.request.form.get('start-date')
            start_date = self.castTime(datestring)
            #end_date = self.castTime(self.request.form.get('finish-date'), self.request.form.get('finish-time'))
            #start_date = datetime.datetime(self.request.form.get('start_time'))
            
            params = {
                        "file": images.resize(image, 90, 90),
                        "file150": images.resize(image, 150, 150),
                        "filetype": self.request.files.get('image_upload').filename,
                        "name" : self.request.form.get('name'),
                        "start_date" : start_date,
#                        "end_date" : end_date,
                        "description" : self.request.form.get('description'),
                        "creator" : self.auth.user,
                        "people_invited" : self.request.form.getlist('contacts[]'),
#                        "type" : self.request.form.get('type'),
                        "setlist" : self.request.form.getlist('songs[]')
                    
                  }
            manager = EventDelegate('Event')
            value = manager.add(params)
            songs = Song.all()
            
            return self.redirect('/dashboard')
예제 #3
0
 def add(self, params):
     artist = Artist.all().filter('name =', params["artist"]).get()
     
     if artist:
         a = artist
     else:
         a = Artist(
                    name = params["artist"]
                    )
         a.put()
     song = Song(
         name = params["name"],
         artist = a,
         url = params["url"]
     )
     song.put()
     
     return song
예제 #4
0
 def song(keyword, song=Song()):
     """
     song service
         获取音乐
         https://github.com/hanhuoer/Musicoo/wiki/web-api#5-%E8%8E%B7%E5%8F%96%E9%9F%B3%E4%B9%90
     :param keyword: 关键字
     :param song: [optional]
     :return:
     """
     search_results = MusicooService.songs_search(keyword, 0, 10)
     if search_results.get('count') > 0:
         song = Song.dict_to_object(search_results.get('data')[0], Song())
         song = MusicooService.song_url(song.get_id(), song)
         song = MusicooService.song_lyric(song.get_id(), song)
         song = MusicooService.song_detail(song.get_id(), song)
     else:
         pass
     return song
예제 #5
0
 def getFile(self, key):
 
     song = Song.get(key)
     result = {
             "file": song.file,
             "name": str(song.key())+"."+song.filetype
     
             }
     
     return result
예제 #6
0
 def song_search(keyword, song=Song()):
     """
     song search service
         搜索音乐
         https://github.com/hanhuoer/Musicoo/wiki/web-api#3-%E9%9F%B3%E4%B9%90%E8%AF%A6%E6%83%85
     :param keyword:
     :param song:
     :return:
     """
     netease = NetEase()
     result = netease.songs_search(keyword)
     song = NeteaseResolver.song_search_resolver(song, result)
     return song
예제 #7
0
 def song_detail(song_id, song=Song()):
     """
     song detail service
         获取音乐信息
         https://github.com/hanhuoer/Musicoo/wiki/web-api#4-%E9%9F%B3%E4%B9%90%E6%90%9C%E7%B4%A2
     :param song_id:
     :param song: [optional]
     :return:
     """
     netease = NetEase()
     result = netease.songs_detail(song_id)
     song = NeteaseResolver.song_detail_resolver(song, result)
     return song
예제 #8
0
 def song_url(song_id, song=Song()):
     """
     song url service
         获取音乐链接
         https://github.com/hanhuoer/Musicoo/wiki/web-api#1-%E8%8E%B7%E5%8F%96%E9%9F%B3%E4%B9%90%E9%93%BE%E6%8E%A5
     :param song_id:
     :param song:
     :return:
     """
     netease = NetEase()
     result = netease.songs_url(str(song_id))
     song = NeteaseResolver.song_url_resolver(song, result)
     return song
예제 #9
0
 def song_lyric(song_id, song=Song()):
     """
     song lyric service
         获取歌词
         https://github.com/hanhuoer/Musicoo/wiki/web-api#2-%E6%AD%8C%E8%AF%8D
     :param song_id:
     :param song:
     :return:
     """
     netease = NetEase()
     result = netease.songs_lyric(str(song_id))
     song = NeteaseResolver.song_lyric_resolver(song, result)
     song.set_id(song_id)
     return song
예제 #10
0
    def add(self, params):
        
        event = Event(
            name = params["name"],
            file = params["file"],
            file150 = params["file150"],
            filetype = params["filetype"].split('.')[1],
            start_date = params["start_date"],
#            end_date = params["end_date"],
            description = params["description"],
            creator = params["creator"],
#            people_invited = params["people_invited"],
#            type = params["type"],
            
            
        )
        event.put()
        list = params["people_invited"]
        for l in list:
            iu = InvitedUser(
                             email = l,
                             event = event
                             )
            queue = Queue('mail-queue')
            subject =  "You have been invited to the event " + event.name + " in Rockolin'"
            body = """     Hi!, You have been invited to the event """ + event.name + """
                    This event would be on: """ + str(event.start_date) + """ 
                    If you want to decide the music justo go to the following 
                    link: http://rockolinapp.appspot.com/event/""" +str(event.key())
            
            queue.add(Task(url='/task/mail', params = { 'to' : l, 'subject' : subject, 'body' : body }))        
            iu.put()
        queue.purge()
        song_list = params["setlist"] 
        
        for s in params["setlist"]:
            song = Song.get(s)
            slv = SetListVotes(
                               event = event,
                               song = song,
                               
                               votes = 0
                               
                               )
            slv.put()
            
            
        return event
예제 #11
0
 def song_lyric_resolver(song=Song(), json={}):
     """
     解析 netease 歌词 api 的响应结果
         可以拿到:原生歌词信息
     :param song: 解析结果
     :param json: netease api 响应 json 串
     :return: Song
     """
     try:
         lrc_json = json.get('lrc')
         if json is None or json.get('nolyric') is True:
             song.set_lyric(None)
         else:
             song.set_lyric(lrc_json.get('lyric'))
     except Exception as e:
         raise NeteaseResolverException(
             'resolver exception; song: {}, json: {}'.format(song, json))
     finally:
         return song
예제 #12
0
    def song_search_resolver(song=Song(), json={}):
        """
        解析音乐的搜索结果
            重点拿到 id 就好了,其余的交给 detail 去解析
        :param song:
        :param json:
        :return:
        """
        try:
            json = json.get('result')
            json = json.get('songs')
            if isinstance(json, list) and len(json) > 0:
                json = json[0]

            song.set_id(json.get('id'))
        except Exception as e:
            raise NeteaseResolverException(
                'resolver exception; song: {}, json: {}'.format(song, json))
        finally:
            return song
예제 #13
0
 def post(self, **kwargs):
     song = Song.get(self.request.form.get('idsong'))
     event = Event.get(self.request.form.get('idevent'))
     sum =  int(self.request.form.get('sum'))
     params = {
                 "event": event,
                 "song": song,
                 "sum": sum
             
           }
     manager = SetListVotesDelegate('SetListVotes')
     manager.update(params)
     slv = event.event_setlist.order('-votes')
     i = 0
     votes = 0
     for s in slv:
         if s.song.key() == song.key():
             votes = s.votes
             break
         i=i+1
     list = {'position' : i,'votes':votes}
     return json.dumps(list)
예제 #14
0
    def song_detail_resolver(song=Song(), json={}):
        """
        解析歌曲详情
            这里可以拿到:音乐名,音乐id,音乐时长,艺人,专辑名,专辑图片,专辑id
        :param song:
        :param json:
        :return:
        """
        try:
            json = json.get('songs')

            if isinstance(json, list) and len(json) > 0:
                json = json[0]

            album_json = json.get('al')
            artist_json = json.get('ar')
            if isinstance(artist_json, list) and len(artist_json) > 0:
                artist_json = artist_json[0]

            song.set_name(json.get('name'))
            song.set_id(json.get('id'))
            song.set_duration(json.get('dt'))
            song.set_picture_url(album_json.get('picUrl'))
            song.set_artist(artist_json.get('name'))

            album = Album()
            album.set_id(album_json.get('id'))
            album.set_name(album_json.get('name'))
            album.set_artist(artist_json.get('name'))
            album.set_picture_url(album_json.get('picUrl'))
            song.set_album(album)

        except Exception as e:
            raise NeteaseResolverException(
                'resolver exception; song: {}, json: {}'.format(song, json))
        finally:
            return song
예제 #15
0
    def song_url_resolver(song=Song(), json={}):
        """
        解析 netease 歌曲 api 的响应结果
            解析目标:音乐 id,音乐 url
        :param song: 解析结果
        :param json: netease api 响应 json 串
        :return: Song
        """
        try:
            json = json.get('data')

            if isinstance(json, list) and len(json) < 1:
                return song

            if isinstance(json, list) and len(json) > 0:
                json = json[0]

            song.set_id(json.get('id'))
            song.set_url(json.get('url'))
        except Exception as e:
            raise NeteaseResolverException(
                'resolver exception; song: {}, json: {}'.format(song, json))
        finally:
            return song
예제 #16
0
 def get(self, **kwargs):
     songs = Song.all()
     return self.render_response('create_event.html',section='create-event',form=self.form,songs=songs)
예제 #17
0
 def get(self, **kwargs):
     
     songs = Song.all()
     return self.render_response('event.html',section='event',songs=songs)
예제 #18
0
def test_song_url_resolver(song=Song()):
    resolver = NeteaseResolver.song_url_resolver(song, SONG_URL_RESULT)
    print(resolver.to_string())
    return resolver
예제 #19
0
def test_song_lyric_resolver(song=Song()):
    resolver = NeteaseResolver.song_lyric_resolver(song, SONG_LYRICS_RESULT)
    print(resolver.to_string())
    return resolver
예제 #20
0
def test_song_search_resolver(song=Song()):
    resolver = NeteaseResolver.song_search_resolver(song, SONG_SEARCH_RESULT)
    print(resolver.to_string())
    return resolver
예제 #21
0
def test_song_detail_resolver(song=Song()):
    resolver = NeteaseResolver.song_detail_resolver(song, SONG_DETAIL_RESULT)
    print(resolver.to_string())
    return resolver
예제 #22
0
 def listSongs(self,user):
     songs = Song.all().filter('creator =', user )
     return songs
예제 #23
0
 def get(self, **kwargs):
 
     songs = Song.all()
     return self.render_response('create_song.html',songs=songs)
예제 #24
0
    def songs_search_resolver(json={}):
        """
        解析音乐的搜索结果
            重点拿到 id 就好了,其余的交给 detail 去解析
        :param song:
        :param json:
        :return:
        """
        result = {'data': [], 'count': 0}

        try:
            if json.get('code') is 200:
                songs = json.get('result').get('songs')
                count = json.get('result').get('songCount')
                result['count'] = count

                for item in songs:
                    song = Song()
                    song.set_id(item.get('id'))
                    song.set_name(item.get('name'))
                    song.set_picture_url(item.get('al').get('picUrl'))
                    song.set_duration(item.get('dt'))
                    name = ''
                    ars = item.get('ar')
                    for ar in ars:
                        if len(ars) - 1 is ars.index(ar):
                            name += ar.get('name')
                        else:
                            name += ar.get('name') + '/'
                    song.set_artist(name)

                    album = Album()
                    album.set_id(item.get('al').get('id'))
                    album.set_name(item.get('al').get('name'))
                    album.set_picture_url(item.get('al').get('picUrl'))

                    song.set_album(album)

                    privilege = Privilege.dict_to_object(
                        item.get('privilege'), Privilege())
                    song.set_privilege(privilege)

                    result.get('data').append(song.to_json())

        except Exception as e:
            raise NeteaseResolverException(
                'resolver exception; json: {}'.format(json))
        finally:
            return result
예제 #25
0
 def get(self, **kwargs):
     songs = Song.all()
     return self.render_response('upload_song.html',form=self.form,songs=songs)