-
Notifications
You must be signed in to change notification settings - Fork 381
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for NRK TV and NRK Radio apps (#777)
* Add support for NRK TV and NRK Radio apps * Update pychromecast/quick_play.py --------- Co-authored-by: Erik Montnemery <[email protected]>
- Loading branch information
1 parent
7e867ad
commit 7a125c0
Showing
6 changed files
with
196 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
""" | ||
Example on how to use the NRK Radio Controller | ||
""" | ||
# pylint: disable=invalid-name | ||
|
||
import argparse | ||
import logging | ||
import sys | ||
from time import sleep | ||
|
||
import zeroconf | ||
|
||
import pychromecast | ||
from pychromecast import quick_play | ||
|
||
# Change to the friendly name of your Chromecast | ||
CAST_NAME = "Living Room" | ||
|
||
# Note: Media ID can be found in the URL, e.g: | ||
# For the live channel https://radio.nrk.no/direkte/p1, the media ID is p1 | ||
# For the podcast https://radio.nrk.no/podkast/tazte_priv/l_8457deb0-4f2c-4ef3-97de-b04f2c6ef314, | ||
# the media ID is l_8457deb0-4f2c-4ef3-97de-b04f2c6ef314 | ||
# For the on-demand program https://radio.nrk.no/serie/radiodokumentaren/sesong/201011/MDUP01004510, | ||
# the media id is MDUP01004510 | ||
MEDIA_ID = "l_8457deb0-4f2c-4ef3-97de-b04f2c6ef314" | ||
|
||
parser = argparse.ArgumentParser( | ||
description="Example on how to use the NRK Radio Controller to play a media stream." | ||
) | ||
parser.add_argument( | ||
"--cast", help='Name of cast device (default: "%(default)s")', default=CAST_NAME | ||
) | ||
parser.add_argument( | ||
"--known-host", | ||
help="Add known host (IP), can be used multiple times", | ||
action="append", | ||
) | ||
parser.add_argument("--show-debug", help="Enable debug log", action="store_true") | ||
parser.add_argument( | ||
"--show-zeroconf-debug", help="Enable zeroconf debug log", action="store_true" | ||
) | ||
parser.add_argument( | ||
"--media_id", help='MediaID (default: "%(default)s")', default=MEDIA_ID | ||
) | ||
args = parser.parse_args() | ||
|
||
if args.show_debug: | ||
logging.basicConfig(level=logging.DEBUG) | ||
if args.show_zeroconf_debug: | ||
print("Zeroconf version: " + zeroconf.__version__) | ||
logging.getLogger("zeroconf").setLevel(logging.DEBUG) | ||
|
||
chromecasts, browser = pychromecast.get_listed_chromecasts( | ||
friendly_names=[args.cast], known_hosts=args.known_host | ||
) | ||
if not chromecasts: | ||
print(f'No chromecast with name "{args.cast}" discovered') | ||
sys.exit(1) | ||
|
||
cast = chromecasts[0] | ||
# Start socket client's worker thread and wait for initial status update | ||
cast.wait() | ||
print(f'Found chromecast with name "{args.cast}", attempting to play "{args.media_id}"') | ||
|
||
app_name = "nrkradio" | ||
app_data = { | ||
"media_id": args.media_id, | ||
} | ||
quick_play.quick_play(cast, app_name, app_data) | ||
|
||
sleep(10) | ||
|
||
browser.stop_discovery() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
""" | ||
Example on how to use the NRK TV Controller | ||
""" | ||
# pylint: disable=invalid-name | ||
|
||
import argparse | ||
import logging | ||
import sys | ||
from time import sleep | ||
|
||
import zeroconf | ||
|
||
import pychromecast | ||
from pychromecast import quick_play | ||
|
||
# Change to the friendly name of your Chromecast | ||
CAST_NAME = "Living Room" | ||
|
||
# Note: Media ID for live programs can be found in the URL | ||
# e.g. for https://tv.nrk.no/direkte/nrk1, the media ID is nrk1 | ||
# Media ID for non-live programs can be found by clicking the share button | ||
# e.g. https://tv.nrk.no/serie/uti-vaar-hage/sesong/2/episode/2 shows: | ||
# "https://tv.nrk.no/se?v=OUHA43000207", the media ID is OUHA43000207 | ||
MEDIA_ID = "OUHA43000207" | ||
|
||
parser = argparse.ArgumentParser( | ||
description="Example on how to use the NRK TV Controller to play a media stream." | ||
) | ||
parser.add_argument( | ||
"--cast", help='Name of cast device (default: "%(default)s")', default=CAST_NAME | ||
) | ||
parser.add_argument( | ||
"--known-host", | ||
help="Add known host (IP), can be used multiple times", | ||
action="append", | ||
) | ||
parser.add_argument("--show-debug", help="Enable debug log", action="store_true") | ||
parser.add_argument( | ||
"--show-zeroconf-debug", help="Enable zeroconf debug log", action="store_true" | ||
) | ||
parser.add_argument( | ||
"--media_id", help='MediaID (default: "%(default)s")', default=MEDIA_ID | ||
) | ||
|
||
args = parser.parse_args() | ||
|
||
if args.show_debug: | ||
logging.basicConfig(level=logging.DEBUG) | ||
if args.show_zeroconf_debug: | ||
print("Zeroconf version: " + zeroconf.__version__) | ||
logging.getLogger("zeroconf").setLevel(logging.DEBUG) | ||
|
||
chromecasts, browser = pychromecast.get_listed_chromecasts( | ||
friendly_names=[args.cast], known_hosts=args.known_host | ||
) | ||
if not chromecasts: | ||
print(f'No chromecast with name "{args.cast}" discovered') | ||
sys.exit(1) | ||
|
||
cast = chromecasts[0] | ||
# Start socket client's worker thread and wait for initial status update | ||
cast.wait() | ||
print(f'Found chromecast with name "{args.cast}", attempting to play "{args.media_id}"') | ||
|
||
app_name = "nrktv" | ||
app_data = { | ||
"media_id": args.media_id, | ||
} | ||
quick_play.quick_play(cast, app_name, app_data) | ||
|
||
sleep(10) | ||
|
||
browser.stop_discovery() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
""" | ||
Controller to interface with NRK Radio. | ||
""" | ||
# Note: Media ID can be found in the URL, e.g: | ||
# For the live channel https://radio.nrk.no/direkte/p1, the media ID is p1 | ||
# For the podcast https://radio.nrk.no/podkast/tazte_priv/l_8457deb0-4f2c-4ef3-97de-b04f2c6ef314, | ||
# the Media ID is l_8457deb0-4f2c-4ef3-97de-b04f2c6ef314 | ||
# For the on-demand program https://radio.nrk.no/serie/radiodokumentaren/sesong/201011/MDUP01004510, | ||
# the media id is MDUP01004510 | ||
|
||
from .media import BaseMediaPlayer | ||
from ..config import APP_NRKRADIO | ||
|
||
APP_NAMESPACE = "urn:x-cast:com.google.cast.media" | ||
|
||
|
||
class NrkRadioController(BaseMediaPlayer): | ||
"""Controller to interact with NRK Radio.""" | ||
|
||
def __init__(self): | ||
super().__init__(supporting_app_id=APP_NRKRADIO) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
""" | ||
Controller to interface with NRK TV. | ||
""" | ||
# Note: Media ID for live programs can be found in the URL | ||
# e.g. for https://tv.nrk.no/direkte/nrk1, the media ID is nrk1 | ||
# Media ID for non-live programs can be found by clicking the share button | ||
# e.g. https://tv.nrk.no/serie/uti-vaar-hage/sesong/2/episode/2 shows: | ||
# "https://tv.nrk.no/se?v=OUHA43000207", the media ID is OUHA43000207 | ||
|
||
from .media import BaseMediaPlayer | ||
from ..config import APP_NRKTV | ||
|
||
APP_NAMESPACE = "urn:x-cast:com.google.cast.media" | ||
|
||
|
||
class NrkTvController(BaseMediaPlayer): | ||
"""Controller to interact with NRK TV.""" | ||
|
||
def __init__(self): | ||
super().__init__(supporting_app_id=APP_NRKTV) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters