Giter Club home page Giter Club logo

Comments (5)

KingofGnome avatar KingofGnome commented on May 27, 2024 1

As i said, it depends if we want to make a yt-api key mandatory.
If so, we could also just go with the origin google-api-python-client, no need for any "middleware". After all, for now its just a simple request against /search.

Also, did someone consider music.youtube.com?
Mby for another skill like "JARVIS play music mozart" (i don't actually know if theres any difference in the videos/music)?
Just stumbled upon https://github.com/sigma67/ytmusicapi

However, lots of possibilities :D
I guess for now i'll just upload the simple webscrape-fix, its done anyway and we postpone the yt-api till later.

from python-ai-assistant.

89Q12 avatar 89Q12 commented on May 27, 2024

Yeah its probably outdated and I wanted to rework the implementation of the yt search but it would be great if you could do it 👍
I wanted to use the youtubei api, references on how to use the internal youtube api can be found here from the invidious project or here. But you're of course free to do implementation however you want

from python-ai-assistant.

KingofGnome avatar KingofGnome commented on May 27, 2024

Yeah, i had a look on the youtube api, we could use that. But its another api-key you need to have.

The "problem" with the current solution (using requests.get) is, that the yt-searchresult page is build with lots of javascript, meaning you wont get the full page without something like selenium.
But on the bright side, yt initializes the javascript part with a custom jsonstring, containing every information we need.
So without using bs4 u can extract the json from the responsetext with
reg_ex = re.search( "var ytInitialData = (.*);<\/script>", page)
load it as json
json_dict = json.loads(reg_ex.group(1))
and work your way through the dictionary, like
contentList = json_dict["contents"]["twoColumnSearchResultsRenderer"]["primaryContents"]["sectionListRenderer"]["contents"]
ans further...

It works, but obviously it will break again as soon as yt will change a single character in there :/

How are your thought on dependencys?
Thinking about using glom for a better handling on the json 'datastucture'.

Also we could just implement both ways:
If you added a yt api-key in the settings, Jarvis will use the api, otherwise the get-request with some custom regex&json-magic (that might break again in the future).

from python-ai-assistant.

89Q12 avatar 89Q12 commented on May 27, 2024

Sounds solid but as you mentioned it can break when YouTube changes things. When I think about it why don't we use ytdl?

from python-ai-assistant.

Akul2010 avatar Akul2010 commented on May 27, 2024

I really think the simplest way is just using pywhatkit:

import pywhatkit as kit

kit.playonyt("url/keywords")

from python-ai-assistant.

Related Issues (20)

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.