Enmn / KickApi

A Python package for interacting with the Kick API to retrieve channel and video data.
MIT License
5 stars 2 forks source link

Broken Package? #1

Open Abdu865 opened 4 months ago

Abdu865 commented 4 months ago

When running the sample code

kick_api = KickAPI()

# Fetch channel data by username
channel = kick_api.channel("{some_username}")

# Access channel attributes
print("Channel ID:", channel.id)
print("Username:", channel.username)
print("Bio:", channel.bio)
print("Avatar URL:", channel.avatar)
print("Followers:", channel.followers)
print("Playback URL:", channel.playback)

channel value is equal to None.

Curl seems to be blocked however the closet workaround i found to getting the data is to use selenium

from selenium import webdriver
from selenium.webdriver.firefox.options import Options
from bs4 import BeautifulSoup
import json

# Configure Selenium to use headless Firefox
options = Options()
options.headless = True
driver = webdriver.Firefox(options=options)

# Define the URL to fetch data from
url = "https://kick.com/api/v2/channels/{some_username}"

# Open the URL
driver.get(url)

# Get the page source
page_source = driver.page_source

# Close the driver
driver.quit()

# Parse the page source using BeautifulSoup
soup = BeautifulSoup(page_source, 'html.parser')

# Assuming the JSON data is directly within the body tag
body_text = soup.find('body').get_text()

# Try to parse the text as JSON
try:
    data = json.loads(body_text)
    # Access channel attributes
    print("Channel ID:", data["id"])
    print("Username:", data["user"]["username"])
    print("Bio:", data["user"]["bio"])
    print("Avatar URL:", data["user"]["profile_pic"])
    print("Followers:", data["followers_count"])
    print("Playback URL:", data["playback_url"])
    try:
        print("Current live viewers:", data["livestream"]["viewer_count"])
    except KeyError:
        print("Channel is not live")

except json.JSONDecodeError as e:
    print(f"Failed to parse JSON response: {e}")
    print("Body text:", body_text)

While this isnt perfect it does seem to get the job done in getting the data. Im sure someone with more experince then me can make a better fix

Abdu865 commented 4 months ago

Updating Requests fixed the issues

ParasiteDelta commented 2 months ago

As of Requests 2.32.3, doesn't work. Going to attempt the workaround.

ParasiteDelta commented 2 months ago

Yeah, so the workaround does work, most likely meaning that some kind of restructuring needs to happen for the library.