示例#1
0
    def post(self):
        list_title = self.get_argument('list_title', '')
        track_id = self.get_argument('id', '')
        title = self.get_argument('title', '')
        artist = self.get_argument('artist', '')
        url = self.get_argument('url', '')
        artist_id = self.get_argument('artist_id', '')
        album = self.get_argument('album', '')
        album_id = self.get_argument('album_id', '')
        source = self.get_argument('source', '')
        source_url = self.get_argument('source_url', '')

        track = {
            'id': track_id,
            'title': title,
            'artist': artist,
            'url': url,
            'artist_id': artist_id,
            'album': album,
            'album_id': album_id,
            'source': source,
            'source_url': source_url,
        }

        newlist_id = PlaylistManager.shared_instance()\
            .create_playlist(list_title)

        PlaylistManager.shared_instance()\
            .add_track_in_playlist(track, newlist_id)

        result = dict(result='success')
        self.write(result)
示例#2
0
    def post(self):
        list_title = self.get_argument('list_title', '')
        track_id = self.get_argument('id', '')
        title = self.get_argument('title', '')
        artist = self.get_argument('artist', '')
        url = self.get_argument('url', '')
        artist_id = self.get_argument('artist_id', '')
        album = self.get_argument('album', '')
        album_id = self.get_argument('album_id', '')
        source = self.get_argument('source', '')
        source_url = self.get_argument('source_url', '')

        track = {
            'id': track_id,
            'title': title,
            'artist': artist,
            'url': url,
            'artist_id': artist_id,
            'album': album,
            'album_id': album_id,
            'source': source,
            'source_url': source_url,
        }

        newlist_id = PlaylistManager.shared_instance()\
            .create_playlist(list_title)

        PlaylistManager.shared_instance()\
            .add_track_in_playlist(track, newlist_id)

        result = dict(result='success')
        self.write(result)
示例#3
0
    def post(self):
        list_id = self.get_argument('list_id', '')
        provider = get_provider(list_id)
        if list_id[2:].startswith('album'):
            album_id = list_id.split('_')[1]
            album = provider.get_album(album_id)
            tracks = album['tracks']
            info = album['info']
        elif list_id[2:].startswith('artist'):
            artist_id = list_id.split('_')[1]
            artist = provider.get_artist(artist_id)
            tracks = artist['tracks']
            info = artist['info']
        elif list_id[2:].startswith('playlist'):
            playlist_id = list_id.split('_')[1]
            playlist = provider.get_playlist(playlist_id)
            tracks = playlist['tracks']
            info = playlist['info']

        list_title = info['title']
        cover_img_url = info['cover_img_url']
        newlist_id = PlaylistManager.shared_instance()\
            .create_playlist(list_title, cover_img_url)
        for track in tracks:
            PlaylistManager.shared_instance()\
                .add_track_in_playlist(track, newlist_id)
        result = dict(result='success')
        self.write(result)
示例#4
0
    def post(self):
        list_id = self.get_argument('list_id', '')
        provider = get_provider(list_id)
        if list_id[2:].startswith('album'):
            album_id = list_id.split('_')[1]
            album = provider.get_album(album_id)
            tracks = album['tracks']
            info = album['info']
        elif list_id[2:].startswith('artist'):
            artist_id = list_id.split('_')[1]
            artist = provider.get_artist(artist_id)
            tracks = artist['tracks']
            info = artist['info']
        elif list_id[2:].startswith('playlist'):
            playlist_id = list_id.split('_')[1]
            playlist = provider.get_playlist(playlist_id)
            tracks = playlist['tracks']
            info = playlist['info']

        list_title = info['title']
        cover_img_url = info['cover_img_url']
        newlist_id = PlaylistManager.shared_instance()\
            .create_playlist(list_title, cover_img_url)
        for track in tracks:
            PlaylistManager.shared_instance()\
                .add_track_in_playlist(track, newlist_id)
        result = dict(result='success')
        self.write(result)
示例#5
0
 def post(self):
     track_id = self.get_argument('track_id', '')
     list_id = self.get_argument('list_id', '')
     PlaylistManager.shared_instance().remove_track_in_playlist(
         track_id, list_id)
     result = dict(result='success')
     PlaylistManager.shared_instance()
     self.write(result)
示例#6
0
 def post(self):
     track_id = self.get_argument('track_id', '')
     list_id = self.get_argument('list_id', '')
     PlaylistManager.shared_instance().remove_track_in_playlist(
         track_id, list_id)
     result = dict(result='success')
     PlaylistManager.shared_instance()
     self.write(result)
    def _on_download2(self, response=None):
        if response is not None:
            for d in json.loads(response.body):
                real_url = d['url']
                url = '/track_file?' + urllib.urlencode(
                    dict(url=real_url,
                         artist=d['singers'][0]['name'].encode("utf8"),
                         album=d['albumtitle'].encode("utf8"),
                         title=d['title'].encode("utf8"),
                         id=d['sid'],
                         source='douban'))
                track = {
                    'id':
                    'dbtrack_' + str(d['sid']),
                    'title':
                    d['title'],
                    'artist':
                    d['singers'][0]['name'],
                    'artist_id':
                    'dbartist_' + d['singers'][0]['id'],
                    'album':
                    d['albumtitle'],
                    'album_id':
                    'dbalbum_' + d['aid'],
                    'img_url':
                    d['picture'],
                    'url':
                    url,
                    'source':
                    'douban',
                    'source_url':
                    'https://music.douban.com/subject/%s/' % d['aid'],
                }
                self.result.append(track)

        url = 'http://douban.fm/j/v2/redheart/songs'
        handle_list = self.sid_list[:self.step]

        if handle_list == []:
            self.status = 'finished'
            # create playlist for douban red heart songs
            PlaylistManager.shared_instance()\
                .create_playlist(u'豆瓣红心', tracks=self.result)
            return

        self.sid_list = self.sid_list[self.step:]
        sids = '|'.join(handle_list)
        v = dict(sids=sids, kbps="192", ck=self.ck)
        request = tornado.httpclient.HTTPRequest(url=url,
                                                 method='POST',
                                                 body=urllib.urlencode(v),
                                                 headers=self.headers)
        self.client.fetch(request, self._on_download2)
        logger.debug('fetch url for douban red heart:' + url)
示例#8
0
文件: douban.py 项目: 123de7/listen1
    def _on_download2(self, response=None):
        if response is not None:
            for d in json.loads(response.body):
                real_url = d['url']
                url = '/track_file?' + urllib.urlencode(dict(
                    url=real_url,
                    artist=d['singers'][0]['name'].encode("utf8"),
                    album=d['albumtitle'].encode("utf8"),
                    title=d['title'].encode("utf8"),
                    id=d['sid'],
                    source='douban'))
                track = {
                    'id': 'dbtrack_' + str(d['sid']),
                    'title': d['title'],
                    'artist': d['singers'][0]['name'],
                    'artist_id': 'dbartist_' + d['singers'][0]['id'],
                    'album': d['albumtitle'],
                    'album_id': 'dbalbum_' + d['aid'],
                    'img_url': d['picture'],
                    'url': url,
                    'source': 'douban',
                    'source_url': 'https://music.douban.com/subject/%s/' %
                    d['aid'],
                }
                self.result.append(track)

        url = 'http://douban.fm/j/v2/redheart/songs'
        handle_list = self.sid_list[:self.step]

        if handle_list == []:
            self.status = 'finished'
            # create playlist for douban red heart songs
            PlaylistManager.shared_instance()\
                .create_playlist(u'豆瓣红心', tracks=self.result)
            return

        self.sid_list = self.sid_list[self.step:]
        sids = '|'.join(handle_list)
        v = dict(sids=sids, kbps="192", ck=self.ck)
        request = tornado.httpclient.HTTPRequest(
            url=url, method='POST',
            body=urllib.urlencode(v), headers=self.headers)
        self.client.fetch(request, self._on_download2)
        logger.debug('fetch url for douban red heart:' + url)
    def get(self):
        list_id = self.get_argument('list_id', '')
        if list_id.startswith('my_'):
            playlist = PlaylistManager.shared_instance().get_playlist(list_id)

            info = dict(
                cover_img_url=playlist['cover_img_url'],
                title=playlist['title'], id=playlist['id'])

            result = dict(
                status='1', tracks=playlist['tracks'], info=info, is_mine='1')
        else:
            provider = get_provider(list_id)
            item_id = list_id.split('_')[1]
            result = provider.get_playlist(item_id)
            result.update(dict(is_mine='0'))
        self.write(result)
示例#10
0
 def get(self):
     resultlist = PlaylistManager.shared_instance().\
         list_playlist()
     result = dict(result=resultlist)
     self.write(result)
示例#11
0
 def get(self):
     resultlist = PlaylistManager.shared_instance().\
         list_playlist()
     result = dict(result=resultlist)
     self.write(result)