Coder Social home page Coder Social logo

pyytlounge's People

Contributors

dmunozv04 avatar fabiognr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

pyytlounge's Issues

Connection eventually gets detached from screen

Using code that continually reconnects and refreshes authorization, eventually the real connection to the lounge session is lost.
Instead a sort of phantom session becomes active, where no events are being sent, but there's no errors from the API.
Calling refresh_auth usually fixes this situation, however it should automatically be detected and prevented.

The following sample code can be used to observe this:

import asyncio
from pyytlounge import YtLoungeApi, PlaybackState, State
from ast import literal_eval
import os

AUTH_STATE_FILE = "auth_state"
CONNECT_RETRY_INTERVAL = 10
ERROR_RETRY_INTERVAL = 30
SUBSCRIBE_RETRY_INTERVAL = 1

async def go():
    api = YtLoungeApi("Test")
    if os.path.exists(AUTH_STATE_FILE):
        with open(AUTH_STATE_FILE, "r") as f:
            content = f.read()
            api.load_auth_state(literal_eval(content))
            print("Loaded from file")
    else:
        pairing_code = input("Enter pairing code: ")
        print(f"Pairing with code {pairing_code}...")
        paired = await api.pair(pairing_code)
        print(paired and "success" or "failed")
        if not paired:
            exit()
        auth_state = api.auth.serialize()
        with open(AUTH_STATE_FILE, "w") as f:
            f.write(str(auth_state))
    print("Connecting...")
    connected = await api.connect()
    print(connected and "success" or "failed")
    if not connected:
        exit()

    async def receive_state(state: PlaybackState):
        print(f"New state: {state}")
        if state.videoId:
            print(
                f"Image should be at: https://img.youtube.com/vi/{state.videoId}/0.jpg"
            )

    async def subscribe_and_keep_alive():
        if not api.connected():
            await api.connect()

        while True:
            while not api.connected():
                print("subscribe_and_keep_alive: reconnecting")
                await asyncio.sleep(CONNECT_RETRY_INTERVAL)
                if not api.linked():
                    await api.refresh_auth()
                await api.connect()
            print("subscribe_and_keep_alive: subscribing")
            await api.subscribe(receive_state)
            await asyncio.sleep(SUBSCRIBE_RETRY_INTERVAL)

    while True:
        try:
            print("Starting subscribe and keep alive")
            await subscribe_and_keep_alive()
        except asyncio.CancelledError:
            break
        except:
            print("Subscribe and keep alive encountered error, waiting seconds: ", ERROR_RETRY_INTERVAL)
            await asyncio.sleep(ERROR_RETRY_INTERVAL)


asyncio.run(go())

In my experience it can take a few days or up to a week before this problem occurs, in this time the screen (and thus youtube app) is turned on/off a few times.

Question: building wheels for this package

Hi, I was wondering if it would be possible to build wheels for this project, since it would make it much easier when using it as a library and installing it. I could try to make a PR with a GitHub action, if that sounds ok.

deviceInfo Key not always present on loungeStatus event

As the title says, on some devices like the Nintendo Switch, the loungeStatus event seems to not always include the deviceInfo key, causing an error and disconnecting from the events subscription.

The message received (with the key missing): {'app': 'lb-v4', 'capabilities': 'dsp,mic,dpa,ntb,vsp,que,mus', 'clientName': 'tvhtml5', 'experiments': '', 'name': 'Nintendo Switch', 'theme': 'cl', 'id': 'XXXXXXXXXXXXXXXXXXX', 'type': 'LOUNGE_SCREEN', 'hasCc': 'true', 'receiverIdentityMatchStatus': 'IS_RECEIVER'}

The traceback: Traceback (most recent call last): File "/venv/lib/python3.9/site-packages/pyytlounge/wrapper.py", line 374, in connect self.__process_events(events) File "/venv/lib/python3.9/site-packages/pyytlounge/wrapper.py", line 290, in __process_events self.__process_event(event_id, event_type, args) File "/venv/lib/python3.9/site-packages/pyytlounge/wrapper.py", line 271, in __process_event self.__device_info = json.loads(device["deviceInfo"]) KeyError: 'deviceInfo'

If you are fine with it, I'd be willing to make a PR myself to fix this.
Also, thanks for creating this amazing wrapper for the youtube lounge api

What is the Data Format in use for the player state?

Do you know what format is being used for the playback State? It doesn't appear to be JSON(I am unable to parse it, errors continue to occur). How are you handling this to extract relevant information? Here is an image with the format that I am talking about.
Screenshot 2023-01-09 at 11 07 50 PM

Any help is appreciated.
Thank You!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.