Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LG WebOS Play Youtube URL using Launch App Params #13588

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion homeassistant/components/media_player/webostv.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import asyncio
from datetime import timedelta
import logging
from urllib.parse import urlparse
from urllib.parse import urlparse, parse_qs

# pylint: disable=unused-import
from typing import Dict # noqa: F401
Expand Down Expand Up @@ -343,6 +343,39 @@ def select_source(self, source):
self._current_source = source_dict['label']
self._client.set_input(source_dict['id'])

def play_media(self, media_type, media_id, **kwargs):
"""Find app for media_id and initialize with url"""
youtube_id = self.youtube_video_id(media_id)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not do this. Just add support for a media_type with value youtube and have the user pass in the video ID as media_id. Remove all the YouTube url parsing from this PR, that does not belong in Home Assistant.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, what does mean "Just add support for a media_type". Which class or file? Is it then the correct place to put Youtube parsing urls here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this function. Just check if media_type == "youtube"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should remove all YouTube url parsing. The user will need to pass in the ID themselves

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No no no no, I have to stand against this. The correct approach would be to create new class "MediaTypes.Youtube" or something like that and insert the parsing here. The parsing is required. I did not know where to put it, so I put it here. Why? Because it is tied for this particular case, but it is true that it might be valuable also for someone else. Why is it required? Because you see only part of code. This was my first pull request just to try how it works here. It is required in order to give voice commands to TV like "Play {event or artist or video name} on Youtube" intent. Then it will correctly search Youtube and return the id. You don't want to let user tell a voice command: "Play youtube id" and then spell hex encoded characters lol.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You know if you would help right away, we both save some time. Now it's your turn to show you are not what I think you are :-)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@balloob where to put youtube code, so I can maybe put it in 2nd pull request, please?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already answered this. #13588 (comment)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But that's the problem: "You have to add Youtube parsing to your own intent handler.". What if this functionality is required by some other components? How to make it user friendly, so other people can use it like a directive or something? Do you have some example? Also your default intent handlers are a mess. A lot of users here and on forums complaining it does not even support TTS. I did a lot of work on this subject, added also optional TTS configuration if u don't want to use Alexa. Then I added also multilanguage support, so you can speak in your native language, then u get answer in your native language. It just supports your natural language out of the box together with english. I just add simple pull request to try out the process, but I feel you are really arrogant & don't care bro.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you have specific requirements for Youtube functionality to be used globally or together with LG package, please provide some example than 1 simple answer not telling anything and not providing solution to my problem. It will also save us time for pull requests, so I do it how you want. If you would provide this information a month ago in simple and professional manner, we would not have to do this exhausting conversation.

if youtube_id is not None:
app = "youtube.leanback.v4"
media_id = youtube_id
self._client.launch_app_with_params(app, contentId=media_id)
else:
self._client.open_url(media_id)

def youtube_video_id(self, value):
"""
Examples:

http://youtu.be/SA2iWivDJiE
http://www.youtube.com/watch?v=_oPAwA_Udwc&feature=feedu
http://www.youtube.com/embed/SA2iWivDJiE
http://www.youtube.com/v/SA2iWivDJiE?version=3&hl=en_US
"""
query = urlparse(value)
if query.hostname == 'youtu.be':
return query.path[1:]
if query.hostname in ('www.youtube.com', 'youtube.com'):
if query.path == '/watch':
p = parse_qs(query.query)
return p['v'][0]
if query.path[:7] == '/embed/':
return query.path.split('/')[2]
if query.path[:3] == '/v/':
return query.path.split('/')[2]
# fail?
return None

def media_play(self):
"""Send play command."""
self._playing = True
Expand Down