예제 #1
0
    def search(self, content, page, num):
        """
        双引擎搜索
        :param content: 搜索内容
        :param page: 页数
        :param num: 每页大小
        :return: 歌曲列表
        """
        result = Songs()
        result_qq = []
        result_netease = []
        if self.use_qq:
            result_qq = self.qq.search_songs(content, page, num)
        if self.use_netease:
            result_netease = self.netease.search_songs(content, num * page,
                                                       num)

        for nsong in result_netease:
            for qsong in result_qq:
                if qsong == nsong:
                    result.append(SONG.merger_song(qsong, nsong))
                    break
        for song in result:
            result_qq.remove(song)
            result_netease.remove(song)
        result += result_qq
        result += result_netease
        return result
예제 #2
0
    def post(self):
        """
        Add song records in response to POST requests containing JSON encoded
        data in the request body. Body data must be a list of dicts:
        [{'title': <string>, 'artist': <string>, 'year': <string>}, ...]
        """
        entity = Key(urlsafe=API_ENTITY_KEY).get()
        if self.request.headers['API_KEY'] != entity.api_key:
            self.error(401)
            return
        logging.info("POST - message body:\n {}".format(self.request.body))
        keys = []
        data = json.loads(self.request.body)
        for song in data:
            song_ent = Songs.query(Songs.title == song['title'],
                                   Songs.artist == song['artist'],
                                   Songs.year == song['year']).get()
            if not song_ent:
                new_key = Songs(**song).put()
                keys.append(new_key.id())
            else:
                keys.append(song_ent.key.id())

        self.response.headers.add_header('Content-Type', 'application/json')
        self.response.out.write(json.dumps(keys))
예제 #3
0
파일: main.py 프로젝트: rookie/Resound-App
    def post(self):
        """
        Add song records in response to POST requests containing JSON encoded
        data in the request body. Body data must be a list of dicts:
        [{'title': <string>, 'artist': <string>, 'year': <string>}, ...]
        """
        entity = Key(urlsafe=API_ENTITY_KEY).get()
        if self.request.headers['API_KEY'] != entity.api_key:
            self.error(401)
            return
        logging.info("POST - message body:\n {}".format(self.request.body))
        keys = []
        data = json.loads(self.request.body)
        for song in data:
            song_ent = Songs.query(Songs.title == song['title'],
                                   Songs.artist == song['artist'],
                                   Songs.year == song['year']).get()
            if not song_ent:
                new_key = Songs(**song).put()
                keys.append(new_key.id())
            else:
                keys.append(song_ent.key.id())

        self.response.headers.add_header('Content-Type', 'application/json')
        self.response.out.write(json.dumps(keys))
예제 #4
0
def songs_create():
    name = request.form['name']
    title_text = request.form['title_text']
    text = Lyrics.get(Lyrics.title_text == title_text).id
    bpm_start = request.form['bpm']
    bpm = Metronome.get(Metronome.name == bpm_start).id
    link_start = request.form['link']
    link = Tabs.get(Tabs.name == link_start).id
    option = request.form['optionsRadios']
    if option == "option1":
        cover = True
    else:
        cover = False
    Songs.get_or_create(name=name, text=text, tabs=link, bpm=bpm, cover=cover)
    return redirect(url_for('songs_list'))
예제 #5
0
파일: app.py 프로젝트: chrizandr/Genrenome
def songs():
    """Index Page."""
    context = {"songs": True}
    if 'admin' in session:
        return redirect(url_for("admin"))
    if 'user' in session:
        if request.method == "GET":
            submitted = db_session.query(Songs).filter(
                Songs.user_id == session['user']).all()
            if len(submitted) > 0:
                context["submitted"] = submitted
            return render_template("songs.html", **context)
        if request.method == "POST":
            songs = {}
            for k in request.form:
                field, num = k.split('_')
                if num not in songs:
                    songs[num] = {}
                songs[num][field] = request.form[k]
            for s in songs:
                print(s)
                db_session.add(Songs(session['user'], **songs[s]))
            db_session.commit()
            return redirect(url_for('songs'))
    else:
        return redirect(url_for("login"))
예제 #6
0
 def upload(self, chat_id, order_list, tmp_dir, cover_path, artist, album,
            cover_url):
     try:
         #save album in db
         a = Albums(name=album, cover=cover_url, artist=artist)
         db.session.add(a)
         db.session.commit()
         album_id = a.id
         album_messages = []
         #upload cover to storage group
         cover = open(cover_path, 'rb')
         bot.send_photo(STORAGE_GROUP_ID,
                        cover,
                        caption='{} - {}'.format(artist, album),
                        disable_notification=True)
         for info in order_list:
             file = info[1]
             name = info[2]
             try:
                 audio = open(file, 'rb')
                 message = bot.send_audio(STORAGE_GROUP_ID,
                                          audio,
                                          performer=artist,
                                          title=name,
                                          disable_notification=True)
                 album_messages.append([name, message.message_id])
             except Exception as e:
                 bot.send_message(
                     chat_id,
                     '⚠️ Error, skipping track - {}. Reason:\n{}'.format(
                         name, e))
             os.remove(file)
         #upload cover to chat
         cover = open(cover_path, 'rb')
         bot.send_photo(chat_id,
                        cover,
                        caption='{} - {}'.format(artist, album),
                        disable_notification=True)
         os.remove(cover_path)
         os.rmdir('{}/{}'.format(UPLOAD_DIR, tmp_dir))
         #forward from storage group
         order_id = 0
         for album_message in album_messages:
             name = album_message[0]
             message_id = album_message[1]
             bot.forward_message(chat_id, STORAGE_GROUP_ID, message_id)
             #save in db
             s = Songs(id=message_id,
                       name=name,
                       album_id=album_id,
                       order_id=order_id)
             db.session.add(s)
             order_id += 1
         db.session.commit()
     except Exception as e:
         bot.send_message(
             chat_id,
             '⚠️ Oooops, an error occurred during album upload, we are on it'
         )
         log.error(e)
예제 #7
0
def songs_list():
    rows_bpm = list(
        Metronome.select(Metronome.name, Metronome.bpm, Metronome.id))
    rows_title_text = list(Lyrics.select(Lyrics.title_text, Lyrics.id))
    rows_link = list(Tabs.select(Tabs.name, Tabs.id, Tabs.link))

    results = Songs.select(Songs.name, Songs.id, Songs.text, Songs.tabs,
                           Songs.bpm)
    cover = request.args.get('cover')
    if cover:
        results = results.where(Songs.cover == int(cover))
    return render_template('songs.html',
                           rows=list(results),
                           rows_bpm=rows_bpm,
                           rows_title_text=rows_title_text,
                           rows_link=rows_link)
def populate_data_into_db(
        itunes_result
):  # this is my list # "song" represents each search thing.
    for song in itunes_result:
        if not Genres.query.filter_by(genre=song['primaryGenreName']).first():
            # add new genre using Genres class
            new_genre = Genres(genre=song['primaryGenreName'])
            db.session.add(new_genre)
            db.session.commit()
        # if genre exists in table, check if there is a song in that genre in the Songs table
        if Songs.query.filter_by(name=song["trackName"]).first():
            continue
        else:  # add new song using Songs class
            find_id = Genres.query.filter_by(
                genre=song['primaryGenreName']).first().id
            new_song = Songs(name=song['trackName'],
                             artist=song['artistName'],
                             album=song['collectionName'],
                             genre_id=find_id)
            db.session.add(new_song)
            db.session.commit()
예제 #9
0
 def post(self):
     music_path = self.get_argument("music_path")
     cover_path = self.get_argument("cover_path")
     music_type = self.get_argument("music_type")
     song_name = self.get_argument("song_name")
     origin = self.get_argument("origin")
     desc = self.get_argument("desc")
     artist = self.get_argument("artist")
     uploader = self.current_user("user_id")
     song = Songs(
         uploader=int(uploader),
         name=song_name,
         cover_path=DOMAIN + cover_path,
         author=artist,
         file_path=DOMAIN + music_path,
         description=desc,
         type_id=music_type,
         origin=origin,
     )
     self.session.add(song)
     self.session.commit()
     self.write(dict(ret=0))
예제 #10
0
def create_songs():
    db.session.query(Songs).delete()
    songs = load_json('songs.json')
    for (k, song) in songs.items():
        name = song['name']['name-USen']
        buyPrice = song['buy-price']
        if buyPrice == None:
            buyPrice = -1
        sellPrice = song['sell-price']
        isOrderable = "Yes"
        if song['isOrderable'] == False:
            isOrderable = "No"
        image = song['image_uri']
        music = song['music_uri']
        id = song['id']
        new_song = Songs(name=name,
                         buyPrice=buyPrice,
                         sellPrice=sellPrice,
                         isOrderable=isOrderable,
                         image=image,
                         music=music,
                         id=id)
        db.session.add(new_song)
        db.session.commit()
예제 #11
0
def songs_delete_id(ID):
    query = Songs.delete().where(Songs.id == ID)
    query.execute()
    return redirect(url_for('songs_list'))
예제 #12
0
def addSong(request, song_name):
    s = Songs()
    s.title = "New"
    s.save()
    return getSongs(request)
예제 #13
0
from models import Songs
from app import db

rtj = Songs('A Christmas F*****g Miracle', 'Run the Jewels', 2013)
gambino = Songs('Freaks and Geeks', 'Childish Gambino', 2011)

db.session.add(rtj)
db.session.add(gambino)
db.session.commit()
예제 #14
0
def addSong(request, song_name):
    s = Songs()
    s.title = "New"
    s.save()
    return getSongs(request)
예제 #15
0
def songs_id(ID):
    song = Songs.get(Songs.id == ID)
    return render_template('songs_id.html', song=song)
예제 #16
0
from models import Songs
from app import db

song = Songs('Cant stop', 'Red Hot Chili Peppers', 2000)

db.session.add(song)
db.session.commit()
예제 #17
0
from models import Songs
from app import db

song1 = Songs('Divided Sky', 'Phish', 1989)
song2 = Songs('Brokedown Palace', 'Grateful Dead', 1971)
song3 = Songs('Take Five', 'Dave Brubeck', 1954)

db.session.add(song1)
db.session.add(song2)
db.session.add(song3)

db.session.commit()