~sumner/sublime-music

cc9ca65fd0502401b035ea62d3b6c819214622c1 — Sumner Evans 4 months ago 2679539 + 7cf13a9
Merge branch 'thelostpolaris:master' into 'master'

Fix confusing issues when hostname has no protocol

Closes #302

See merge request sublime-music/sublime-music!63
2 files changed, 31 insertions(+), 8 deletions(-)

M CONTRIBUTING.md
M sublime_music/adapters/subsonic/adapter.py
M CONTRIBUTING.md => CONTRIBUTING.md +1 -1
@@ 54,7 54,7 @@ had to install to develop the app. In general, the requirements are:
#### Specific Requirements for Various Distros/OSes

* **NixOS:** use the `shell.nix` which will also run the `poetry install`
* **Arch Linux:** `pacman -S libnm-glib libnotify python-gobject`
* **Arch Linux:** `pacman -S libnm-glib libnotify python-gobject gobject-introspection`
* **macOS (Homebrew):** `brew install mp3 gobject-introspection pkg-config pygobject3 gtk+3 adwaita-icon-theme`

### Installing

M sublime_music/adapters/subsonic/adapter.py => sublime_music/adapters/subsonic/adapter.py +30 -7
@@ 444,18 444,41 @@ class SubsonicAdapter(Adapter):
                logging.info("Using mock data")
                result = self._get_mock_data()
            else:
                result = requests.get(
                    url,
                    params=params,
                    verify=self.verify_cert,
                    timeout=timeout,
                )
                if url.startswith("http://") or url.startswith("https://"):
                    result = requests.get(
                        url,
                        params=params,
                        verify=self.verify_cert,
                        timeout=timeout,
                    )
                else:
                    # if user creates a serverconf address w/o protocol, we'll
                    # attempt to fix it and store it in hostname
                    # TODO (#305) #hostname currently preprends https:// if
                    # protocol isn't defined this might be able to be taken out
                    try:
                        logging.info("Hostname: %r has no protocol", self.hostname)
                        result = requests.get(
                            "https://" + url,
                            params=params,
                            verify=self.verify_cert,
                            timeout=timeout,
                        )
                        self.hostname = "https://" + url.split("/")[0]
                    except Exception:
                        result = requests.get(
                            "http://" + url,
                            params=params,
                            verify=self.verify_cert,
                            timeout=timeout,
                        )

                        self.hostname = "http://" + url.split("/")[0]

            if result.status_code != 200:
                raise ServerError(
                    result.status_code, f"{url} returned status={result.status_code}."
                )

            # Any time that a server request succeeds, then we win.
            self._server_available.value = True
            self._last_ping_timestamp.value = datetime.now().timestamp()