コード例 #1
0
def connect_kkbox():
    #call kkbox api to search song url
    auth = KKBOXOAuth(
        config.client_id, config.client_secret
    )  # Replace CLIENT_ID and CLIENT_SECRET with your ID and Secret
    token = auth.fetch_access_token_by_client_credentials()
    kkboxapi = KKBOXAPI(token)
    return kkboxapi
コード例 #2
0
def getkkboxtoken():
    client_id = 'a8a677cd3602a46a7d591955a2682dbc'
    client_secret = '80b89ef5f0e28d1599e30b2b1be8b409'
    print('CLIENT_ID = ', client_id, ' , CLIENT_SECRET = ', client_secret)
    auth = KKBOXOAuth(client_id, client_secret)
    token = auth.fetch_access_token_by_client_credentials()
    print(token.access_token)
    return token.access_token
コード例 #3
0
 def testReadMeExample(self):
     from kkbox_developer_sdk.auth_flow import KKBOXOAuth
     from .env import ClientInfo
     auth = KKBOXOAuth(ClientInfo.client_id, ClientInfo.client_secret)
     token = auth.fetch_access_token_by_client_credentials()
     from kkbox_developer_sdk.api import KKBOXAPI
     kkboxapi = KKBOXAPI(token)
     artist_id = '8q3_xzjl89Yakn_7GB'
     artist = kkboxapi.artist_fetcher.fetch_artist(artist_id)
     assert(artist != None)
コード例 #4
0
def main():
    CLIENT_ID = "460c75bbc275c0694737a476c09d2a3d"
    CLIENT_SECRET = "6cb1d4094ff089250df8b7ff9f48e48b"

    auth = KKBOXOAuth(CLIENT_ID, CLIENT_SECRET)
    token = auth.fetch_access_token_by_client_credentials()

    conn = http.client.HTTPSConnection("api.kkbox.com")

    headers = {
        'accept': "application/json",
        'authorization': "Bearer " + token.access_token
    }

    conn.request("GET", "/v1.1/charts?territory=TW", headers=headers)

    res = conn.getresponse()
    data = res.read()

    # print(data.decode("utf-8"))

    json_obj = json.loads(data)
    keys = json_obj['data'][0].keys(
    )  # ['id', 'title', 'description', 'url', 'images', 'updated_at', 'owner']
    daily_url = json_obj['data'][2]['url']

    res = requests.get(daily_url)
    soup = BeautifulSoup(res.text, 'html.parser')

    titles = [
        x.text.strip().replace('\n', '') for x in soup.select('a.song-title')
    ]

    artist_album = soup.select('div.song-artist-album')  # 有些沒有專輯名稱,直接選取會分不清楚
    artist_album = [x.select('a') for x in artist_album]
    artists = [x[0]['title'] for x in artist_album]

    albums = []

    for item in artist_album:
        if len(item) == 1:  # 只有歌手名稱
            albums.append('')
            continue
        albums.append(item[1]['title'])

    for i in range(len(titles)):
        print('歌曲:' + titles[i], end='')
        print(' 歌手:' + artists[i], end='')
        print(' 專輯:' + albums[i])
コード例 #5
0
def get_token(token_file, client_id, client_secret):
    """Helper function for getting the token.

    If the specified file exists, try to load it with pickle.
    Else use the given client ID and Secret to request the token.
    """
    if path.exists(token_file):
        with open(token_file, 'rb') as f:
            return pickle.load(f)
    else:
        auth = KKBOXOAuth(client_id, client_secret)
        token = auth.fetch_access_token_by_client_credentials()
        with open(token_file, 'wb') as f:
            pickle.dump(token, f)
        return token
コード例 #6
0
def before_request():
    token = None

    if path.exists(TOKEN_FILE):
        with open(TOKEN_FILE, 'rb') as f:
            token = pickle.load(f)
        g.kkbox = KKBOXAPI(token)
        return

    auth = KKBOXOAuth(app.config['CLIENT_ID'], app.config['CLIENT_SECRET'])
    token = auth.fetch_access_token_by_client_credentials()
    g.kkbox = KKBOXAPI(token)

    with open(TOKEN_FILE, 'wb') as f:
        pickle.dump(token, f)
コード例 #7
0
def init():
    global auth, token, kkboxapi
    auth = KKBOXOAuth(CLIENT_ID, CLIENT_SECRET)
    token = auth.fetch_access_token_by_client_credentials()
    kkboxapi = KKBOXAPI(token)
コード例 #8
0
import os
import lyricwikia
import lyricsgenius
import requests
import pandas as pd
from tqdm import tqdm
import time
import datetime
from bs4 import BeautifulSoup
from kkbox_developer_sdk.auth_flow import KKBOXOAuth

# KKBOX API setup
auth = KKBOXOAuth('70c7e34eb87791c22919e8022ff8ef2a',
                  '874a427a0829434c423f69e9f364e644')
token = auth.fetch_access_token_by_client_credentials()

from kkbox_developer_sdk.api import KKBOXAPI
kkboxapi = KKBOXAPI(token)

# Genius API setup
genius = lyricsgenius.Genius(
    "s1t9yyg-jOQWjkHZ7nNEEp4iHYlyMMWw7GNtV3xk3t2m8CAC-lDQoZEl4jHCvL-M")
genius.verbose = False
genius.skip_non_songs = True

script_dir = os.path.dirname(__file__)
chunk_size = 50
pbar = 0


def lyric_wikia(artist, song):
コード例 #9
0
ファイル: client.py プロジェクト: a8s287/Heroku
"""
Created on Sun Oct 18 21:37:15 2020

@author: Eva
"""
import http.client
from kkbox_developer_sdk.auth_flow import KKBOXOAuth
from kkbox_developer_sdk.api import KKBOXAPI

class ClientInfo():
    client_id = "bca3a776e63a2a9813c7c4646980bfba"
    client_secret = "da4e7e8eb8ed3dbb0686ddc5f49784c4"

a = ClientInfo(); 

auth = KKBOXOAuth(a.client_id, a.client_secret)
token = auth.fetch_access_token_by_client_credentials()


#print(token)
kkboxapi = KKBOXAPI(token)
artist_id = '8q3_xzjl89Yakn_7GB'
artist = kkboxapi.artist_fetcher.fetch_artist(artist_id)

conn = http.client.HTTPSConnection("api.kkbox.com")

headers = {
    'accept': "application/json",
    'authorization':  "Bearer o3M1esXZRj9d7GvWUoj2Hg=="
    }
コード例 #10
0
ファイル: app.py プロジェクト: zonble/k2y
@evalcontextfilter
def linebreaks(eval_ctx, value):
    """Converts newlines into <p> and <br />s."""
    value = re.sub(r'\r\n|\r|\n', '\n', value)  # normalize newlines
    paras = re.split('\n{2,}', value)
    paras = [u'<p>%s</p>' % p.replace('\n', '<br />') for p in paras]
    paras = u'\n\n'.join(paras)
    return Markup(paras)


# refers to application_top
APP_ROOT = os.path.dirname(os.path.abspath(__file__))
APP_STATIC = os.path.join(APP_ROOT, 'static')
CLIENT_ID = 'YOUR_API_KEY'
CLIENT_SECRET = 'YOUR_API_SECRET'
auth = KKBOXOAuth(CLIENT_ID, CLIENT_SECRET)
token = auth.fetch_access_token_by_client_credentials()
api = KKBOXAPI(token)
youtube = Youtube()


def get_chart_category():
    try:
        categories = api.chart_fetcher.fetch_charts().get('data')
        cache.set('chart_category', categories, timeout=60 * 60 * 12)
        return categories
    except Exception as e:
        return []


def get_playlist_category():