Skip to content

Commit

Permalink
feat: add support for streaming URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
vzhd1701 committed Jun 8, 2022
1 parent 84d5569 commit 9425343
Show file tree
Hide file tree
Showing 69 changed files with 73,030 additions and 69,361 deletions.
13 changes: 10 additions & 3 deletions gridplayer/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@
import sys
from multiprocessing import freeze_support

from gridplayer.main.init_app import setup_app_env
from gridplayer.main.init_utils import exit_if_delegated, init_log
from gridplayer.main.init_app_env import init_app_env
from gridplayer.main.init_log import init_log
from gridplayer.main.run import run_app
from gridplayer.settings import Settings
from gridplayer.utils.excepthook import excepthook
from gridplayer.utils.log import log_environment
from gridplayer.utils.single_instance import is_delegated_to_primary


def main():
freeze_support()

setup_app_env()
init_app_env()

init_log()

Expand All @@ -29,5 +31,10 @@ def main():
sys.exit(ret)


def exit_if_delegated():
if Settings().get("player/one_instance") and is_delegated_to_primary(sys.argv):
sys.exit(0)


if __name__ == "__main__":
main()
165 changes: 82 additions & 83 deletions gridplayer/dialogs/about.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,95 +65,94 @@ def __init__(self, parent):

self.info.setText(about_info)

attributions_general = [
Attribution(
"Python",
sys.version.split(" ")[0],
"Python Software Foundation",
"Python Software Foundation License",
"https://www.python.org/",
),
Attribution(
"Qt",
QT_VERSION_STR,
"Qt Project",
"GPL 2.0, GPL 3.0, and LGPL 3.0",
"https://www.qt.io/",
),
Attribution(
"VLC",
None,
"VideoLAN",
"GPL 2.0 or later",
"https://www.videolan.org/",
),
]

attributions_python = [
Attribution(
"PyQt",
PYQT_VERSION_STR,
"Riverbank Computing",
"Riverbank Commercial License and GPL v3",
"https://riverbankcomputing.com/",
),
Attribution(
"python-vlc",
params_env.VLC_PYTHON_VERSION,
"Olivier Aubert",
"GPL 2.0 and LGPL 2.1",
"https://github.com/oaubert/python-vlc",
),
Attribution(
"pydantic",
PYDANTIC_VERSION,
"Samuel Colvin",
"MIT License",
"https://github.com/samuelcolvin/pydantic",
),
]

attributions_gui = [
Attribution(
"Hack Font",
"3.003",
"Source Foundry",
"MIT License",
"http://sourcefoundry.org/hack/",
),
Attribution(
"Basic Icons",
None,
"Icongeek26",
"Flaticon License",
"https://www.flaticon.com/authors/icongeek26",
),
Attribution(
"Suru Icons",
None,
"Sam Hewitt",
"Creative Commons Attribution-Share Alike 4.0",
"https://snwh.org/",
),
]

attributions_translation = [
AttributionTranslation(
"Hungarian",
"samu112",
"https://crowdin.com/profile/samu112",
),
]
attributions = {
"general": [
Attribution(
"Python",
sys.version.split(" ")[0],
"Python Software Foundation",
"Python Software Foundation License",
"https://www.python.org/",
),
Attribution(
"Qt",
QT_VERSION_STR,
"Qt Project",
"GPL 2.0, GPL 3.0, and LGPL 3.0",
"https://www.qt.io/",
),
Attribution(
"VLC",
None,
"VideoLAN",
"GPL 2.0 or later",
"https://www.videolan.org/",
),
],
"python": [
Attribution(
"PyQt",
PYQT_VERSION_STR,
"Riverbank Computing",
"Riverbank Commercial License and GPL v3",
"https://riverbankcomputing.com/",
),
Attribution(
"python-vlc",
params_env.VLC_PYTHON_VERSION,
"Olivier Aubert",
"GPL 2.0 and LGPL 2.1",
"https://github.com/oaubert/python-vlc",
),
Attribution(
"pydantic",
PYDANTIC_VERSION,
"Samuel Colvin",
"MIT License",
"https://github.com/samuelcolvin/pydantic",
),
],
"gui": [
Attribution(
"Hack Font",
"3.003",
"Source Foundry",
"MIT License",
"http://sourcefoundry.org/hack/",
),
Attribution(
"Basic Icons",
None,
"Icongeek26",
"Flaticon License",
"https://www.flaticon.com/authors/icongeek26",
),
Attribution(
"Suru Icons",
None,
"Sam Hewitt",
"Creative Commons Attribution-Share Alike 4.0",
"https://snwh.org/",
),
],
"translation": [
AttributionTranslation(
"Hungarian",
"samu112",
"https://crowdin.com/profile/samu112",
),
],
}

attributions_txt = [
"<style>p, h3 {text-align: center;}</style>",
self.generate_attributions(attributions_general),
self.generate_attributions(attributions["general"]),
"<h3>{0}</h3>".format(self.tr("Python packages")),
self.generate_attributions(attributions_python),
self.generate_attributions(attributions["python"]),
"<h3>{0}</h3>".format(self.tr("Graphics")),
self.generate_attributions(attributions_gui),
self.generate_attributions(attributions["gui"]),
"<h3>{0}</h3>".format(self.tr("Translations")),
self.generate_attributions_translations(attributions_translation),
self.generate_attributions_translations(attributions["translation"]),
]

self.attributionsBox.setText("\n".join(attributions_txt))
Expand Down
161 changes: 161 additions & 0 deletions gridplayer/dialogs/add_urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
from itertools import starmap
from typing import Dict, Iterable

from PyQt5.QtCore import Qt
from PyQt5.QtGui import QIcon
from PyQt5.QtWidgets import (
QDialog,
QDialogButtonBox,
QLabel,
QLayout,
QLineEdit,
QTextEdit,
QVBoxLayout,
)

from gridplayer.utils.misc import tr

DIALOG_WIDTH = 500
MULTILINE_HEIGHT = 300


class QAddURLsDialog(QDialog):
def __init__(
self,
supported_schemas: Iterable[str],
supported_urls: Dict[str, str],
**kwargs,
):
super().__init__(**kwargs)

self._input_single = QLineEdit(self)
self._input_multiline = QTextEdit(self)

self._supported_info = self._init_info(supported_schemas, supported_urls)

self._buttons = self._init_buttons()

self._expand_button = self._buttons.addButton("+", QDialogButtonBox.ResetRole)
self._expand_button.clicked.connect(self._switch_multiline)

self._is_expanded = False

self._ui_setup()

@property
def urls(self):
if self._is_expanded:
return [
url.strip()
for url in self._input_multiline.toPlainText().splitlines()
if url.strip()
]

url = self._input_single.text().strip()
return [url] if url else []

@classmethod
def get_urls(
cls,
parent,
title: str,
supported_schemas: Iterable[str],
supported_urls: Dict[str, str],
):
dialog = cls(
parent=parent,
supported_schemas=supported_schemas,
supported_urls=supported_urls,
)

dialog.setWindowTitle(title)

if dialog.exec():
return dialog.urls

return []

def _init_info(self, schemas: Iterable[str], supported_urls: Dict[str, str]):
supported_info = QLabel(self)

info_txt = _init_info_txt(schemas, supported_urls)

supported_info.setText(info_txt)

return supported_info

def _init_buttons(self):
buttons = QDialogButtonBox(
QDialogButtonBox.Ok | QDialogButtonBox.Cancel,
Qt.Horizontal,
self,
)

buttons.accepted.connect(self.accept)
buttons.rejected.connect(self.reject)

for btn in buttons.buttons():
btn.setIcon(QIcon())

return buttons

def _ui_setup(self):
main_layout = QVBoxLayout(self)
main_layout.setSizeConstraint(QLayout.SetFixedSize)

self._supported_info.setOpenExternalLinks(True)

self._input_single.setMinimumWidth(DIALOG_WIDTH)

self._input_multiline.setMinimumSize(DIALOG_WIDTH, MULTILINE_HEIGHT)
self._input_multiline.setAcceptRichText(False)
self._input_multiline.hide()

main_layout_stack = [
self._input_single,
self._input_multiline,
self._supported_info,
self._buttons,
]

for widget in main_layout_stack:
main_layout.addWidget(widget)

def _switch_multiline(self):
url = self.urls[0] if self.urls else ""

if self._is_expanded:
self._input_single.setText(url)

self._input_single.show()
self._input_multiline.hide()
self._expand_button.setText("+")
else:
self._input_multiline.setText(url)

self._input_single.hide()
self._input_multiline.show()
self._expand_button.setText("-")

self._is_expanded = not self._is_expanded


def _init_info_txt(schemas, supported_urls):
supported_info_template = "<br>".join(
(tr("Supported URL schemas: {SCHEMAS}"), tr("Supported sites: {SERVICES}"))
)

tokens = {
"{SCHEMAS}": ", ".join(sorted(schemas)),
"{SERVICES}": ", ".join(_convert_urls(supported_urls)),
}

for token, token_value in tokens.items():
supported_info_template = supported_info_template.replace(token, token_value)

return supported_info_template


def _convert_urls(urls: Dict[str, str]) -> Iterable[str]:
url_template = "<a href='{1}'>{0}</a>"
return starmap(url_template.format, urls.items())
Loading

0 comments on commit 9425343

Please sign in to comment.