File: config.py

package info (click to toggle)
pychromecast 0.7.7-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 288 kB
  • ctags: 936
  • sloc: python: 1,495; makefile: 6
file content (41 lines) | stat: -rw-r--r-- 1,012 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
"""
Data and methods to retrieve app specific configuration
"""
import json

import requests

APP_BACKDROP = "E8C28D3C"
APP_YOUTUBE = "YouTube"
APP_MEDIA_RECEIVER = "CC1AD845"
APP_PLEX = "06ee44ee-e7e3-4249-83b6-f5d0b6f07f34_1"


def get_possible_app_ids():
    """ Returns all possible app ids. """

    try:
        req = requests.get(
            "https://clients3.google.com/cast/chromecast/device/baseconfig")
        data = json.loads(req.text[4:])

        return [app['app_id'] for app in data['applications']] + \
            data["enabled_app_ids"]

    except ValueError:
        # If json fails to parse
        return []


def get_app_config(app_id):
    """ Get specific configuration for 'app_id'. """
    try:
        req = requests.get(
            ("https://clients3.google.com/"
             "cast/chromecast/device/app?a={}").format(app_id))

        return json.loads(req.text[4:]) if req.status_code == 200 else {}

    except ValueError:
        # If json fails to parse
        return {}