Esempio n. 1
0
    def find_songs_by_title(self, title):
        "노래 제목으로 곡을 찾는다."

        cursor = self.db.cursor()
        sql = '''\
select id, uid, title, artist, url, img_url, played_count, created_at, description, duration FROM SONGS where title like ?
'''
        cursor.execute(sql, (title, ))
        ret = []

        for data in cursor.fetchmany(5):
            if data:
                song = Song()

                song.dbid = data[0]
                song.uid = data[1]
                song.title = data[2]
                song.artist = data[3]
                song.url = data[4]
                song.img_url = data[5]
                song.played_count = data[6]
                song.created_at = data[7]
                song.description = data[8]
                song.duration = data[9]

                ret.append(song)
        
        return ret
Esempio n. 2
0
    def get_songs(self):
        cursor = self.db.cursor()
        sql = '''\
select id, uid, title, artist, url, img_url, played_count, created_at, description, duration FROM SONGS
'''
        cursor.execute(sql)
        ret = []

        while True:
            data = cursor.fetchone()
            if data:
                song = Song()

                song.dbid = data[0]
                song.uid = data[1]
                song.title = data[2]
                song.artist = data[3]
                song.url = data[4]
                song.img_url = data[5]
                song.played_count = data[6]
                song.created_at = data[7]
                song.description = data[8]
                song.duration = data[9]
                
                yield song
            else:
                break
Esempio n. 3
0
    def get_songs(self):
        cursor = self.db.cursor()
        sql = '''\
select id, uid, title, artist, url, img_url, played_count, created_at, description, duration FROM SONGS
'''
        cursor.execute(sql)
        ret = []

        while True:
            data = cursor.fetchone()
            if data:
                song = Song()

                song.dbid = data[0]
                song.uid = data[1]
                song.title = data[2]
                song.artist = data[3]
                song.url = data[4]
                song.img_url = data[5]
                song.played_count = data[6]
                song.created_at = data[7]
                song.description = data[8]
                song.duration = data[9]

                yield song
            else:
                break
Esempio n. 4
0
    def find_songs_by_title(self, title):
        "노래 제목으로 곡을 찾는다."

        cursor = self.db.cursor()
        sql = '''\
select id, uid, title, artist, url, img_url, played_count, created_at, description, duration FROM SONGS where title like ?
'''
        cursor.execute(sql, (title, ))
        ret = []

        for data in cursor.fetchmany(5):
            if data:
                song = Song()

                song.dbid = data[0]
                song.uid = data[1]
                song.title = data[2]
                song.artist = data[3]
                song.url = data[4]
                song.img_url = data[5]
                song.played_count = data[6]
                song.created_at = data[7]
                song.description = data[8]
                song.duration = data[9]

                ret.append(song)

        return ret
Esempio n. 5
0
def add_song():
    """노래 추가.

    youtube link를 주면 곡 정보를 DB에 추가한다.
    가능한 링크
      - youtube 노래 link
      - youtube playlist link
    """

    # web browser에서 요청한 데이터를 받는다. body 영역 데이터
    data = request.get_json(silent=True)

    # 그중에 url, list_url, add_playlist 정보를 가져온다.
    # url는 노래 link
    # list_url는 플레이 리스트 link
    # add_playlist는 현재 연주되고 있는 플레이 리스트에 바로 추가할지 결정
    url = data.get("url", None)
    list_url = data.get("list_url", None)
    add_playlist = data.get('add_playlist', False)

    # 노래 link 라면
    if url:

        # 노래 정보를 구해서
        info = youtube.get_video_info(url)
        # song 객체로 만들어
        song = Song()
        song.url = info["url"]
        song.uid = info["uid"]
        song.title = info["title"]
        song.img_url = info["image_url"]
        song.duration = info['duration']

        if song.title and song.duration:
            # 데이터가 valid 할 때만 추가
        
            # DB에 추가한다.
            jukebox.append_song_to_db(song)

            # 플레이 리스트에 추가해야 하면 그렇게 한다.
            if add_playlist:
                jukebox.append_song_playlist(song)

    elif list_url:
        # 노래 목록이면
        # 별도의 처리 쓰레드를 통해서 처리한다.
        thread = AddYoutubeListThread(jukebox, list_url, add_playlist)
        thread.start()

    # 잘 처리되었다고 반환
    ret = { 'code': 0, 'msg': 'ok' }        
    return jsonify(**ret)
Esempio n. 6
0
def add_song():
    """노래 추가.

    youtube link를 주면 곡 정보를 DB에 추가한다.
    가능한 링크
      - youtube 노래 link
      - youtube playlist link
    """

    # web browser에서 요청한 데이터를 받는다. body 영역 데이터
    data = request.get_json(silent=True)

    # 그중에 url, list_url, add_playlist 정보를 가져온다.
    # url는 노래 link
    # list_url는 플레이 리스트 link
    # add_playlist는 현재 연주되고 있는 플레이 리스트에 바로 추가할지 결정
    url = data.get("url", None)
    list_url = data.get("list_url", None)
    add_playlist = data.get('add_playlist', False)

    # 노래 link 라면
    if url:

        # 노래 정보를 구해서
        info = youtube.get_video_info(url)
        # song 객체로 만들어
        song = Song()
        song.url = info["url"]
        song.uid = info["uid"]
        song.title = info["title"]
        song.img_url = info["image_url"]
        song.duration = info['duration']

        if song.title and song.duration:
            # 데이터가 valid 할 때만 추가

            # DB에 추가한다.
            jukebox.append_song_to_db(song)

            # 플레이 리스트에 추가해야 하면 그렇게 한다.
            if add_playlist:
                jukebox.append_song_playlist(song)

    elif list_url:
        # 노래 목록이면
        # 별도의 처리 쓰레드를 통해서 처리한다.
        thread = AddYoutubeListThread(jukebox, list_url, add_playlist)
        thread.start()

    # 잘 처리되었다고 반환
    ret = {'code': 0, 'msg': 'ok'}
    return jsonify(**ret)
Esempio n. 7
0
    def run(self):
        infos = youtube.get_video_infos_from_list(self.list_url)
        for info in infos:
            print(info)
            try:
                song = Song()
                song.url = info["url"]
                song.uid = info["uid"]
                song.title = info["title"]
                song.img_url = info["image_url"]
                song.duration = info['duration']

                if song.title and song.duration:
                    # 데이터가 valid 할 때만 추가
                    
                    self.store.update_or_new(song)

                    if self.add_playlist:
                        self.jukebox.append_song_playlist(song)
                
            except Exception as e:
                print(e)
Esempio n. 8
0
    def run(self):
        infos = youtube.get_video_infos_from_list(self.list_url)
        for info in infos:
            print(info)
            try:
                song = Song()
                song.url = info["url"]
                song.uid = info["uid"]
                song.title = info["title"]
                song.img_url = info["image_url"]
                song.duration = info['duration']

                if song.title and song.duration:
                    # 데이터가 valid 할 때만 추가

                    self.store.update_or_new(song)

                    if self.add_playlist:
                        self.jukebox.append_song_playlist(song)

            except Exception as e:
                print(e)
Esempio n. 9
0
    def find_by_id(self, dbid):
        "UID로 노래를 찾는다."
        cursor = self.db.cursor()
        sql = '''\
select id, uid, title, artist, url, img_url, played_count, created_at, description, duration FROM SONGS where id = ?
'''
        cursor.execute(sql, (dbid, ))
        data = cursor.fetchone()
        if data:
            song = Song()

            song.dbid = data[0]
            song.uid = data[1]
            song.title = data[2]
            song.artist = data[3]
            song.url = data[4]
            song.img_url = data[5]
            song.played_count = data[6]
            song.created_at = data[7]
            song.description = data[8]
            song.duration = data[9]
            
        return song
Esempio n. 10
0
    def find_by_id(self, dbid):
        "UID로 노래를 찾는다."
        cursor = self.db.cursor()
        sql = '''\
select id, uid, title, artist, url, img_url, played_count, created_at, description, duration FROM SONGS where id = ?
'''
        cursor.execute(sql, (dbid, ))
        data = cursor.fetchone()
        if data:
            song = Song()

            song.dbid = data[0]
            song.uid = data[1]
            song.title = data[2]
            song.artist = data[3]
            song.url = data[4]
            song.img_url = data[5]
            song.played_count = data[6]
            song.created_at = data[7]
            song.description = data[8]
            song.duration = data[9]

        return song