mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-05-04 22:19:38 +00:00
98_GOOGLECAST: fix speak, play, displayWebsite
git-svn-id: https://svn.fhem.de/fhem/trunk/fhem@16379 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
15db6af50d
commit
92710bb2b7
@ -7,10 +7,14 @@
|
|||||||
# FHEM module to communicate with Google Cast devices
|
# FHEM module to communicate with Google Cast devices
|
||||||
# e.g. Chromecast Video, Chromecast Audio, Google Home
|
# e.g. Chromecast Video, Chromecast Audio, Google Home
|
||||||
#
|
#
|
||||||
# Version: 2.1.1
|
# Version: 2.1.2
|
||||||
#
|
#
|
||||||
#############################################################
|
#############################################################
|
||||||
#
|
#
|
||||||
|
# v2.1.2 - 20180310
|
||||||
|
# - BUGFIX: fix speak, play, displayWebsite
|
||||||
|
# - FEATURE: added German commandref (thx@Sailor)
|
||||||
|
#
|
||||||
# v2.1.1 - 20180303
|
# v2.1.1 - 20180303
|
||||||
# - BUGFIX: fix crash on connection failures
|
# - BUGFIX: fix crash on connection failures
|
||||||
# - BUGFIX: update FHEM socket on pychromecast reconnect
|
# - BUGFIX: update FHEM socket on pychromecast reconnect
|
||||||
@ -146,7 +150,7 @@ sub GOOGLECAST_Initialize($) {
|
|||||||
$hash->{AttrList} = "favoriteURL_1 favoriteURL_2 favoriteURL_3 favoriteURL_4 ".
|
$hash->{AttrList} = "favoriteURL_1 favoriteURL_2 favoriteURL_3 favoriteURL_4 ".
|
||||||
"favoriteURL_5 ".$readingFnAttributes;
|
"favoriteURL_5 ".$readingFnAttributes;
|
||||||
|
|
||||||
Log3 $hash, 3, "GOOGLECAST: GoogleCast v2.1.1";
|
Log3 $hash, 3, "GOOGLECAST: GoogleCast v2.1.2";
|
||||||
|
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
@ -176,7 +180,7 @@ sub GOOGLECAST_findChromecasts {
|
|||||||
my ($name) = split("\\|", $string);
|
my ($name) = split("\\|", $string);
|
||||||
my $result = "$name";
|
my $result = "$name";
|
||||||
|
|
||||||
my @ccResult = GOOGLECAST_findChromecastsPython();
|
my @ccResult = GOOGLECAST_PyFindChromecasts();
|
||||||
foreach my $ref_cc (@ccResult) {
|
foreach my $ref_cc (@ccResult) {
|
||||||
my @cc = @$ref_cc;
|
my @cc = @$ref_cc;
|
||||||
$result .= "|CCDEVICE|".$cc[0]."|".$cc[1]."|".$cc[2]."|".$cc[3]."|".Encode::encode('UTF-8', $cc[4]);
|
$result .= "|CCDEVICE|".$cc[0]."|".$cc[1]."|".$cc[2]."|".$cc[3]."|".Encode::encode('UTF-8', $cc[4]);
|
||||||
@ -206,7 +210,7 @@ sub GOOGLECAST_findChromecastsResult {
|
|||||||
if($ccResult[$i] eq "CCDEVICE" and $ccResult[$i+5] eq $devName) {
|
if($ccResult[$i] eq "CCDEVICE" and $ccResult[$i+5] eq $devName) {
|
||||||
Log3 $hash, 4, "GOOGLECAST ($hash->{NAME}): init cast device $devName";
|
Log3 $hash, 4, "GOOGLECAST ($hash->{NAME}): init cast device $devName";
|
||||||
eval {
|
eval {
|
||||||
$hash->{helper}{ccdevice} = GOOGLECAST_createChromecastPython($ccResult[$i+1],$ccResult[$i+2],$ccResult[$i+3],$ccResult[$i+4],$ccResult[$i+5]);
|
$hash->{helper}{ccdevice} = GOOGLECAST_PyCreateChromecast($ccResult[$i+1],$ccResult[$i+2],$ccResult[$i+3],$ccResult[$i+4],$ccResult[$i+5]);
|
||||||
};
|
};
|
||||||
if($@) {
|
if($@) {
|
||||||
$hash->{helper}{ccdevice} = "";
|
$hash->{helper}{ccdevice} = "";
|
||||||
@ -301,7 +305,7 @@ sub GOOGLECAST_setWebsite {
|
|||||||
my ($hash, $url) = @_;
|
my ($hash, $url) = @_;
|
||||||
|
|
||||||
eval {
|
eval {
|
||||||
GOOGLECAST_loadDashCast($hash->{helper}{ccdevice}, $url);
|
GOOGLECAST_PyLoadDashCast($hash->{helper}{ccdevice}, $url);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -317,7 +321,7 @@ sub GOOGLECAST_setSpeak {
|
|||||||
Log3 $hash, 4, "GOOGLECAST($hash->{NAME}): setSpeak $ttsUrl";
|
Log3 $hash, 4, "GOOGLECAST($hash->{NAME}): setSpeak $ttsUrl";
|
||||||
|
|
||||||
eval {
|
eval {
|
||||||
$hash->{helper}{ccdevice}->{media_controller}->play_media($ttsUrl, "audio/mpeg");
|
GOOGLECAST_PyPlayMedia($hash->{helper}{ccdevice}, $ttsUrl, "audio/mpeg");
|
||||||
};
|
};
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
@ -333,7 +337,7 @@ sub GOOGLECAST_setPlayType {
|
|||||||
} else {
|
} else {
|
||||||
eval {
|
eval {
|
||||||
Log3 $hash, 4, "GOOGLECAST($hash->{NAME}): start play_media";
|
Log3 $hash, 4, "GOOGLECAST($hash->{NAME}): start play_media";
|
||||||
$hash->{helper}{ccdevice}->{media_controller}->play_media($url, $mime);
|
GOOGLECAST_PyPlayMedia($hash->{helper}{ccdevice}, $url, $mime);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -410,7 +414,7 @@ sub GOOGLECAST_setPlayYtDlBlocking {
|
|||||||
my $videoUrl = "";
|
my $videoUrl = "";
|
||||||
|
|
||||||
eval {
|
eval {
|
||||||
$videoUrl = GOOGLECAST_getYTVideoURLPython($ytUrl);
|
$videoUrl = GOOGLECAST_PyGetYTVideoURL($ytUrl);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -452,7 +456,7 @@ sub GOOGLECAST_setPlay {
|
|||||||
#https://github.com/rg3/youtube-dl/blob/master/docs/supportedsites.md
|
#https://github.com/rg3/youtube-dl/blob/master/docs/supportedsites.md
|
||||||
GOOGLECAST_setPlayMedia($hash, $url);
|
GOOGLECAST_setPlayMedia($hash, $url);
|
||||||
} else {
|
} else {
|
||||||
GOOGLECAST_playYouTube($hash->{helper}{ccdevice}, $url);
|
GOOGLECAST_PyPlayYouTube($hash->{helper}{ccdevice}, $url);
|
||||||
}
|
}
|
||||||
|
|
||||||
return undef;
|
return undef;
|
||||||
@ -684,16 +688,22 @@ import youtube_dl
|
|||||||
import pychromecast.controllers.dashcast as dashcast
|
import pychromecast.controllers.dashcast as dashcast
|
||||||
import pychromecast.controllers.youtube as youtube
|
import pychromecast.controllers.youtube as youtube
|
||||||
|
|
||||||
def GOOGLECAST_findChromecastsPython():
|
def GOOGLECAST_PyFindChromecasts():
|
||||||
logging.basicConfig(level=logging.CRITICAL)
|
logging.basicConfig(level=logging.CRITICAL)
|
||||||
return pychromecast.discovery.discover_chromecasts()
|
return pychromecast.discovery.discover_chromecasts()
|
||||||
|
|
||||||
def GOOGLECAST_createChromecastPython(ip, port, uuid, model_name, friendly_name):
|
def GOOGLECAST_PyCreateChromecast(ip, port, uuid, model_name, friendly_name):
|
||||||
logging.basicConfig(level=logging.CRITICAL)
|
logging.basicConfig(level=logging.CRITICAL)
|
||||||
cast = pychromecast._get_chromecast_from_host((ip, int(port), uuid, model_name, friendly_name), blocking=False, timeout=0.1, tries=1, retry_wait=0.1)
|
cast = pychromecast._get_chromecast_from_host((ip.decode("utf-8"), int(port), uuid.decode("utf-8"), model_name.decode("utf-8"), friendly_name.decode("utf-8")), blocking=False, timeout=0.1, tries=1, retry_wait=0.1)
|
||||||
return cast
|
return cast
|
||||||
|
|
||||||
def GOOGLECAST_getYTVideoURLPython(yt_url):
|
def GOOGLECAST_PyPlayMedia(cast, url, mime):
|
||||||
|
logging.basicConfig(level=logging.CRITICAL)
|
||||||
|
cast.play_media(url.decode("utf-8"), mime.decode("utf-8"))
|
||||||
|
return undef
|
||||||
|
|
||||||
|
def GOOGLECAST_PyGetYTVideoURL(yt_url):
|
||||||
|
yt_url = yt_url.decode("utf-8")
|
||||||
ydl = youtube_dl.YoutubeDL({'forceurl': True, 'simulate': True, 'quiet': '1', 'no_warnings': '1', 'skip_download': True, 'format': 'best', 'youtube_include_dash_manifest': False})
|
ydl = youtube_dl.YoutubeDL({'forceurl': True, 'simulate': True, 'quiet': '1', 'no_warnings': '1', 'skip_download': True, 'format': 'best', 'youtube_include_dash_manifest': False})
|
||||||
|
|
||||||
result = ydl.extract_info(yt_url, download=False)
|
result = ydl.extract_info(yt_url, download=False)
|
||||||
@ -708,12 +718,14 @@ def GOOGLECAST_getYTVideoURLPython(yt_url):
|
|||||||
video_url = video['url']
|
video_url = video['url']
|
||||||
return video_url
|
return video_url
|
||||||
|
|
||||||
def GOOGLECAST_loadDashCast(cast, url):
|
def GOOGLECAST_PyLoadDashCast(cast, url):
|
||||||
|
url = url.decode("utf-8")
|
||||||
d = dashcast.DashCastController()
|
d = dashcast.DashCastController()
|
||||||
cast.register_handler(d)
|
cast.register_handler(d)
|
||||||
d.load_url(url,reload_seconds=60)
|
d.load_url(url,reload_seconds=60)
|
||||||
|
|
||||||
def GOOGLECAST_playYouTube(cast, videoId):
|
def GOOGLECAST_PyPlayYouTube(cast, videoId):
|
||||||
|
videoId = videoId.decode("utf-8")
|
||||||
yt = youtube.YouTubeController()
|
yt = youtube.YouTubeController()
|
||||||
cast.register_handler(yt)
|
cast.register_handler(yt)
|
||||||
yt.play_video(videoId)
|
yt.play_video(videoId)
|
||||||
@ -801,5 +813,77 @@ PYTHON_CODE_END
|
|||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
=end html
|
=end html
|
||||||
|
=begin html_DE
|
||||||
|
|
||||||
|
<a name="GOOGLECAST"></a>
|
||||||
|
<h3>GOOGLECAST</h3>
|
||||||
|
<ul>
|
||||||
|
GOOGLECAST wird zur Steueung deines Google Cast Devices verwendet<br><br>
|
||||||
|
<b>Note</b><br>Es ist sicherzustellen, dass python3 installiert ist. Zusätzlich werden folgende Pakete benötigt:
|
||||||
|
<ul>
|
||||||
|
<li>sudo apt-get install libwww-perl python-enum34 python-dev libextutils-makemaker-cpanfile-perl python3-pip cpanminus</li>
|
||||||
|
<li>sudo pip3 install pychromecast --upgrade</li>
|
||||||
|
<li>sudo pip3 install youtube-dl --upgrade</li>
|
||||||
|
<li>sudo INLINE_PYTHON_EXECUTABLE=/usr/bin/python3 cpanm Inline::Python</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<br>
|
||||||
|
<br>
|
||||||
|
<a name="GOOGLECASTdefine" id="GOOGLECASTdefine"></a>
|
||||||
|
<b>Define</b>
|
||||||
|
<ul>
|
||||||
|
<code>define <name> GOOGLECAST <name></code><br>
|
||||||
|
<br>
|
||||||
|
Beispiel:
|
||||||
|
<ul>
|
||||||
|
<code>define livingroom.chromecast GOOGLECAST livingroom</code><br><br>
|
||||||
|
Warte ein paar Sekunden bis das Gerät als ONLINE angezeigt wird...<br><br>
|
||||||
|
<code>set livingroom.chromecast play https://www.youtube.com/watch?v=YE7VzlLtp-4</code><br>
|
||||||
|
</ul>
|
||||||
|
<br>
|
||||||
|
Die folgenden Medienformate werden unterstützt:<br>
|
||||||
|
<a href="https://developers.google.com/cast/docs/media">Unterstützte Medienformate</a><br>
|
||||||
|
Das Abspielen mittels youtube-dl funktioniert für die folgenden URLs:<br>
|
||||||
|
<a href="https://rg3.github.io/youtube-dl/supportedsites.html">Unterstützte youtube-dl - Seiten</a><br>
|
||||||
|
<br>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<br>
|
||||||
|
|
||||||
|
<a name="GOOGLECASTset" id="GOOGLECASTset"></a>
|
||||||
|
<b>Set</b>
|
||||||
|
<ul>
|
||||||
|
<code>set <name> <command> [<parameter>]</code><br>
|
||||||
|
Die folgenden Befehle sind definiert:<br><br>
|
||||||
|
<ul>
|
||||||
|
<li><code><b>play</b> URL</code> - Abspielen einer URL</li>
|
||||||
|
<li><code><b>play</b></code> - Abspielen im Sinne von Wiederaufnahme eines zuvor pausierten Abspielvorgangs</li>
|
||||||
|
<li><code><b>playFavorite</b></code> - spielt die URL aus den Favoriten favoriteURL_[1-5] ab</li>
|
||||||
|
<li><code><b>stop</b></code> - unterbricht den augenblicklichen Abspielvorgang</li>
|
||||||
|
<li><code><b>pause</b></code> - pause</li>
|
||||||
|
<li><code><b>quitApp</b></code> - schließt die gegenwärtige Applikation wie beispielsweise YouTube</li>
|
||||||
|
<li><code><b>skip</b></code> - unterbricht das gegenwärtige Kapitel bzw. Lied und springt zum Nächsten</li>
|
||||||
|
<li><code><b>rewind</b></code> - springt zum Anfang des gegenwärtigen Kapitels bzw. Liedes</li>
|
||||||
|
<li><code><b>displayWebsite</b></code> - anzeigen einer Webseite auf Chromecast Video</li>
|
||||||
|
</ul>
|
||||||
|
<br>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<a name="GOOGLECASTattr" id="GOOGLECASTattr"></a>
|
||||||
|
<b>Attribute</b>
|
||||||
|
<ul>
|
||||||
|
<li><code><b>favoriteURL_[1-5]</b></code> - Abspeichern von URL - Favoriten um mittels playFavorite [1-5] - Befehl abgespielt zu werden.</li>
|
||||||
|
</ul>
|
||||||
|
<br>
|
||||||
|
|
||||||
|
<a name="GOOGLECASTget" id="GOOGLECASTget"></a>
|
||||||
|
<b>Get</b>
|
||||||
|
<ul>
|
||||||
|
<code>n/a</code>
|
||||||
|
</ul>
|
||||||
|
<br>
|
||||||
|
|
||||||
|
</ul>
|
||||||
|
=end html_DE
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user