mirror of
https://github.com/dmunozv04/iSponsorBlockTV.git
synced 2025-12-15 00:16:43 +03:00
Compare commits
69 Commits
v2.5.0
...
dependabot
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b985309944 | ||
|
|
12bed77cca | ||
|
|
dab84dec96 | ||
|
|
aaf1f64ec7 | ||
|
|
49ea01dd9c | ||
|
|
2a2949f552 | ||
|
|
85b4124a52 | ||
|
|
da7dcf67fe | ||
|
|
b4d1feb3a9 | ||
|
|
6afd1bcbaa | ||
|
|
516326e0ff | ||
|
|
461b8bfde7 | ||
|
|
580ac5e3e1 | ||
|
|
52a221c4e0 | ||
|
|
e6dff63b19 | ||
|
|
8bab77237d | ||
|
|
31a6d260e5 | ||
|
|
34256b5c5e | ||
|
|
91842c18f2 | ||
|
|
accb685bf3 | ||
|
|
f68311cbf6 | ||
|
|
aa76d130d8 | ||
|
|
258239338e | ||
|
|
21f52537d8 | ||
|
|
f6bfd9af98 | ||
|
|
4a57cce9bb | ||
|
|
6524361d5d | ||
|
|
27ecc54d93 | ||
|
|
3b7617ef14 | ||
|
|
aa35610c67 | ||
|
|
d581f7ee07 | ||
|
|
8e01755550 | ||
|
|
56b42e26ff | ||
|
|
c88861822c | ||
|
|
315ac2c726 | ||
|
|
390eb68310 | ||
|
|
7652c9f260 | ||
|
|
acf074e860 | ||
|
|
123f3d4000 | ||
|
|
303d805e5d | ||
|
|
c779e83d96 | ||
|
|
aac4b333c2 | ||
|
|
fa83124002 | ||
|
|
76b82e8848 | ||
|
|
26fec272a3 | ||
|
|
3fdcee71fd | ||
|
|
1a58ce6a57 | ||
|
|
90d313049b | ||
|
|
cd7e5c83c7 | ||
|
|
bf1fe68089 | ||
|
|
d179fe2b79 | ||
|
|
4724ee1a39 | ||
|
|
bb7fdbfb06 | ||
|
|
930db16f53 | ||
|
|
8ed1cb4b00 | ||
|
|
65ecbb9193 | ||
|
|
f2155abad3 | ||
|
|
edbea793ed | ||
|
|
df629805c2 | ||
|
|
ad9834b9f0 | ||
|
|
97e7b31d9c | ||
|
|
b5d275e01e | ||
|
|
98c1211b09 | ||
|
|
57f33ec354 | ||
|
|
9f6a18a006 | ||
|
|
fd6f0d7283 | ||
|
|
166e238f41 | ||
|
|
8ecaa7e86f | ||
|
|
cafdf4f962 |
13
.github/workflows/build_docker_images.yml
vendored
13
.github/workflows/build_docker_images.yml
vendored
@@ -6,7 +6,8 @@ on:
|
|||||||
branches:
|
branches:
|
||||||
- '*'
|
- '*'
|
||||||
tags:
|
tags:
|
||||||
- 'v*'
|
- 'v*.*.*'
|
||||||
|
- 'v*.*.*-*'
|
||||||
pull_request:
|
pull_request:
|
||||||
branches:
|
branches:
|
||||||
- '*'
|
- '*'
|
||||||
@@ -27,7 +28,7 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
# Get the repository's code
|
# Get the repository's code
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v5
|
||||||
|
|
||||||
# Generate docker tags
|
# Generate docker tags
|
||||||
- name: Docker meta
|
- name: Docker meta
|
||||||
@@ -40,7 +41,9 @@ jobs:
|
|||||||
tags: |
|
tags: |
|
||||||
type=raw,value=develop,priority=900,enable=${{ github.ref == format('refs/heads/{0}', github.event.repository.default_branch) }}
|
type=raw,value=develop,priority=900,enable=${{ github.ref == format('refs/heads/{0}', github.event.repository.default_branch) }}
|
||||||
type=ref,enable=true,priority=600,prefix=pr-,suffix=,event=pr
|
type=ref,enable=true,priority=600,prefix=pr-,suffix=,event=pr
|
||||||
type=ref,event=tag
|
type=semver,pattern=v{{version}}
|
||||||
|
type=semver,pattern=v{{major}}
|
||||||
|
type=semver,pattern=v{{major}}.{{minor}}
|
||||||
type=ref,event=branch
|
type=ref,event=branch
|
||||||
type=schedule
|
type=schedule
|
||||||
|
|
||||||
@@ -53,7 +56,7 @@ jobs:
|
|||||||
uses: docker/setup-buildx-action@v3
|
uses: docker/setup-buildx-action@v3
|
||||||
|
|
||||||
- name: Login to DockerHub
|
- name: Login to DockerHub
|
||||||
if: github.event_name != 'pull_request'
|
if: github.event_name != 'pull_request' && env.DOCKERHUB_USERNAME != ''
|
||||||
uses: docker/login-action@v3
|
uses: docker/login-action@v3
|
||||||
with:
|
with:
|
||||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||||
@@ -71,7 +74,7 @@ jobs:
|
|||||||
uses: docker/build-push-action@v6
|
uses: docker/build-push-action@v6
|
||||||
with:
|
with:
|
||||||
context: .
|
context: .
|
||||||
platforms: linux/amd64, linux/arm64, linux/arm/v7
|
platforms: linux/amd64, linux/arm64, linux/arm/v7, linux/386, linux/arm/v6
|
||||||
push: ${{ github.event_name != 'pull_request' }}
|
push: ${{ github.event_name != 'pull_request' }}
|
||||||
tags: ${{ steps.meta.outputs.tags }}
|
tags: ${{ steps.meta.outputs.tags }}
|
||||||
labels: ${{ steps.meta.outputs.labels }}
|
labels: ${{ steps.meta.outputs.labels }}
|
||||||
|
|||||||
24
.github/workflows/release.yml
vendored
24
.github/workflows/release.yml
vendored
@@ -11,12 +11,9 @@ name: Release Package
|
|||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- '*'
|
- 'main'
|
||||||
tags:
|
tags:
|
||||||
- 'v*'
|
- 'v*'
|
||||||
pull_request:
|
|
||||||
branches:
|
|
||||||
- '*'
|
|
||||||
release:
|
release:
|
||||||
types: [published]
|
types: [published]
|
||||||
|
|
||||||
@@ -33,10 +30,10 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v5
|
||||||
|
|
||||||
- name: Set up Python ${{ env.PYTHON_VERSION }}
|
- name: Set up Python ${{ env.PYTHON_VERSION }}
|
||||||
uses: actions/setup-python@v5
|
uses: actions/setup-python@v6
|
||||||
with:
|
with:
|
||||||
python-version: ${{ env.PYTHON_VERSION }}
|
python-version: ${{ env.PYTHON_VERSION }}
|
||||||
|
|
||||||
@@ -103,17 +100,17 @@ jobs:
|
|||||||
CARGO_BUILD_TARGET: ${{ matrix.job.target }}
|
CARGO_BUILD_TARGET: ${{ matrix.job.target }}
|
||||||
PYAPP_DISTRIBUTION_VARIANT_CPU: ${{ matrix.job.cpu_variant }}
|
PYAPP_DISTRIBUTION_VARIANT_CPU: ${{ matrix.job.cpu_variant }}
|
||||||
PYAPP_REPO: pyapp # Use local copy of pyapp (needed for cross-compiling)
|
PYAPP_REPO: pyapp # Use local copy of pyapp (needed for cross-compiling)
|
||||||
PYAPP_VERSION: v0.27.0
|
PYAPP_VERSION: v0.28.0
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v5
|
||||||
|
|
||||||
- name: Clone PyApp
|
- name: Clone PyApp
|
||||||
run: git clone --depth 1 --branch $PYAPP_VERSION https://github.com/ofek/pyapp $PYAPP_REPO
|
run: git clone --depth 1 --branch $PYAPP_VERSION https://github.com/ofek/pyapp $PYAPP_REPO
|
||||||
|
|
||||||
- name: Set up Python ${{ env.PYTHON_VERSION }}
|
- name: Set up Python ${{ env.PYTHON_VERSION }}
|
||||||
uses: actions/setup-python@v5
|
uses: actions/setup-python@v6
|
||||||
with:
|
with:
|
||||||
python-version: ${{ env.PYTHON_VERSION }}
|
python-version: ${{ env.PYTHON_VERSION }}
|
||||||
|
|
||||||
@@ -144,7 +141,7 @@ jobs:
|
|||||||
hatch --version
|
hatch --version
|
||||||
|
|
||||||
- name: Get artifact
|
- name: Get artifact
|
||||||
uses: actions/download-artifact@v4
|
uses: actions/download-artifact@v5
|
||||||
with:
|
with:
|
||||||
name: sdist-and-wheel
|
name: sdist-and-wheel
|
||||||
path: ${{ github.workspace }}/dist
|
path: ${{ github.workspace }}/dist
|
||||||
@@ -162,9 +159,10 @@ jobs:
|
|||||||
mv dist/binary/iSponsorBlockTV* dist/binary/iSponsorBlockTV-${{ matrix.job.release_suffix }}
|
mv dist/binary/iSponsorBlockTV* dist/binary/iSponsorBlockTV-${{ matrix.job.release_suffix }}
|
||||||
|
|
||||||
- name: Attest build provenance
|
- name: Attest build provenance
|
||||||
uses: actions/attest-build-provenance@v2
|
uses: actions/attest-build-provenance@v3
|
||||||
with:
|
with:
|
||||||
subject-path: dist/binary/*
|
subject-path: dist/binary/*
|
||||||
|
continue-on-error: true # Continue if attestation fails (it will fail on forks)
|
||||||
|
|
||||||
- name: Upload built binary package
|
- name: Upload built binary package
|
||||||
uses: actions/upload-artifact@v4
|
uses: actions/upload-artifact@v4
|
||||||
@@ -183,7 +181,7 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Get artifact
|
- name: Get artifact
|
||||||
uses: actions/download-artifact@v4
|
uses: actions/download-artifact@v5
|
||||||
with:
|
with:
|
||||||
name: sdist-and-wheel
|
name: sdist-and-wheel
|
||||||
path: dist
|
path: dist
|
||||||
@@ -202,7 +200,7 @@ jobs:
|
|||||||
if: github.event_name == 'release' && github.event.action == 'published'
|
if: github.event_name == 'release' && github.event.action == 'published'
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/download-artifact@v4
|
- uses: actions/download-artifact@v5
|
||||||
name: Get artifact
|
name: Get artifact
|
||||||
with:
|
with:
|
||||||
path: dist
|
path: dist
|
||||||
|
|||||||
4
.github/workflows/update_docker_readme.yml
vendored
4
.github/workflows/update_docker_readme.yml
vendored
@@ -18,11 +18,11 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
# Get the repository's code
|
# Get the repository's code
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v5
|
||||||
|
|
||||||
# Update description
|
# Update description
|
||||||
- name: Update repo description
|
- name: Update repo description
|
||||||
uses: peter-evans/dockerhub-description@v4
|
uses: peter-evans/dockerhub-description@v5
|
||||||
with:
|
with:
|
||||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
# Inspired by textual pre-commit config
|
# Inspired by textual pre-commit config
|
||||||
repos:
|
repos:
|
||||||
- repo: https://github.com/pre-commit/pre-commit-hooks
|
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||||
rev: v5.0.0
|
rev: v6.0.0
|
||||||
hooks:
|
hooks:
|
||||||
- id: check-ast # simply checks whether the files parse as valid python
|
- id: check-ast # simply checks whether the files parse as valid python
|
||||||
- id: check-builtin-literals # requires literal syntax when initializing empty or zero python builtin types
|
- id: check-builtin-literals # requires literal syntax when initializing empty or zero python builtin types
|
||||||
@@ -19,13 +19,13 @@ repos:
|
|||||||
- id: mixed-line-ending # replaces or checks mixed line ending
|
- id: mixed-line-ending # replaces or checks mixed line ending
|
||||||
- id: trailing-whitespace # checks for trailing whitespace
|
- id: trailing-whitespace # checks for trailing whitespace
|
||||||
- repo: https://github.com/astral-sh/ruff-pre-commit
|
- repo: https://github.com/astral-sh/ruff-pre-commit
|
||||||
rev: v0.11.9
|
rev: v0.12.12
|
||||||
hooks:
|
hooks:
|
||||||
- id: ruff
|
- id: ruff
|
||||||
args: [ --fix, --exit-non-zero-on-fix ]
|
args: [ --fix, --exit-non-zero-on-fix ]
|
||||||
- id: ruff-format
|
- id: ruff-format
|
||||||
- repo: https://github.com/igorshubovych/markdownlint-cli
|
- repo: https://github.com/igorshubovych/markdownlint-cli
|
||||||
rev: v0.44.0
|
rev: v0.45.0
|
||||||
hooks:
|
hooks:
|
||||||
- id: markdownlint
|
- id: markdownlint
|
||||||
args: ["--fix"]
|
args: ["--fix"]
|
||||||
|
|||||||
31
README.md
31
README.md
@@ -5,10 +5,11 @@
|
|||||||
[](https://github.com/dmunozv04/iSponsorBlockTV/releases/latest)
|
[](https://github.com/dmunozv04/iSponsorBlockTV/releases/latest)
|
||||||
[](https://github.com/dmunozv04/isponsorblocktv)
|
[](https://github.com/dmunozv04/isponsorblocktv)
|
||||||
|
|
||||||
Skip sponsor segments in YouTube videos playing on a YouTube TV device (see
|
iSponsorBlockTV is a self-hosted application that connects to your YouTube TV
|
||||||
below for compatibility details).
|
app (see compatibility below) and automatically skips segments (like Sponsors
|
||||||
|
or intros) in YouTube videos using the [SponsorBlock](https://sponsor.ajay.app/)
|
||||||
This project is written in asynchronous python and should be pretty quick.
|
API. It can also auto mute and press the "Skip Ad" button the moment it becomes
|
||||||
|
available on YouTube ads.
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
@@ -22,7 +23,7 @@ Open an issue/pull request if you have tested a device that isn't listed here.
|
|||||||
|
|
||||||
| Device | Status |
|
| Device | Status |
|
||||||
|:-------------------|:------:|
|
|:-------------------|:------:|
|
||||||
| Apple TV | ✅ |
|
| Apple TV | ✅* |
|
||||||
| Samsung TV (Tizen) | ✅ |
|
| Samsung TV (Tizen) | ✅ |
|
||||||
| LG TV (WebOS) | ✅ |
|
| LG TV (WebOS) | ✅ |
|
||||||
| Android TV | ✅ |
|
| Android TV | ✅ |
|
||||||
@@ -35,17 +36,17 @@ Open an issue/pull request if you have tested a device that isn't listed here.
|
|||||||
| Xbox One/Series | ✅ |
|
| Xbox One/Series | ✅ |
|
||||||
| Playstation 4/5 | ✅ |
|
| Playstation 4/5 | ✅ |
|
||||||
|
|
||||||
|
*Ad muting won't work when using AirPlay to send the audio to another speaker.
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
Run iSponsorBlockTV on a computer that has network access.
|
Run iSponsorBlockTV on a computer that has network access. It doesn't need to
|
||||||
|
be on the same network as the device, only access to youtube.com is required.
|
||||||
|
|
||||||
Auto discovery will require the computer to be on the same network as the device
|
Auto discovery will require the computer to be on the same network as the device
|
||||||
during setup.
|
during setup.
|
||||||
The device can also be manually added to iSponsorBlockTV with a YouTube TV code.
|
The device can also be manually added to iSponsorBlockTV with a YouTube TV code.
|
||||||
This code can be found in the settings page of your YouTube application.
|
This code can be found in the settings page of your YouTube TV application.
|
||||||
|
|
||||||
It connects to the device, watches its activity and skips any sponsor segment
|
|
||||||
using the [SponsorBlock](https://sponsor.ajay.app/) API.
|
|
||||||
It can also skip/mute YouTube ads.
|
|
||||||
|
|
||||||
## Libraries used
|
## Libraries used
|
||||||
|
|
||||||
@@ -71,11 +72,9 @@ It can also skip/mute YouTube ads.
|
|||||||
|
|
||||||
## Contributors
|
## Contributors
|
||||||
|
|
||||||
- [dmunozv04](https://github.com/dmunozv04) - creator and maintainer
|
[](https://github.com/dmunozv04/iSponsorBlockTV/graphs/contributors)
|
||||||
- [HaltCatchFire](https://github.com/HaltCatchFire) - updated dependencies and
|
|
||||||
improved skip logic
|
Made with [contrib.rocks](https://contrib.rocks).
|
||||||
- [Oxixes](https://github.com/oxixes) - added support for channel whitelist and
|
|
||||||
minor improvements
|
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
|
|||||||
@@ -20,5 +20,6 @@
|
|||||||
{"id": "",
|
{"id": "",
|
||||||
"name": ""
|
"name": ""
|
||||||
}
|
}
|
||||||
]
|
],
|
||||||
|
"use_proxy": false
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
version: '3.3'
|
|
||||||
services:
|
services:
|
||||||
iSponsorBlockTV:
|
iSponsorBlockTV:
|
||||||
image: ghcr.io/dmunozv04/isponsorblocktv
|
image: ghcr.io/dmunozv04/isponsorblocktv
|
||||||
container_name: iSponsorBlockTV
|
container_name: iSponsorBlockTV
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
volumes:
|
volumes:
|
||||||
- /PATH_TO_YOUR_DATA_DIR:/app/data
|
- /PATH_TO_YOUR_DATA_DIR:/app/data
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[project]
|
[project]
|
||||||
name = "iSponsorBlockTV"
|
name = "iSponsorBlockTV"
|
||||||
version = "2.4.0"
|
version = "2.6.1"
|
||||||
authors = [
|
authors = [
|
||||||
{"name" = "dmunozv04"}
|
{"name" = "dmunozv04"}
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
aiohttp==3.11.18
|
aiohttp==3.13.1
|
||||||
appdirs==1.4.4
|
appdirs==1.4.4
|
||||||
async-cache==1.1.1
|
async-cache==1.1.1
|
||||||
pyytlounge==2.3.0
|
pyytlounge==2.3.0
|
||||||
rich==14.0.0
|
rich==14.1.0
|
||||||
ssdp==1.3.0
|
ssdp==1.3.1
|
||||||
textual==2.1.2
|
textual==5.3.0
|
||||||
textual-slider==0.2.0
|
textual-slider==0.2.0
|
||||||
xmltodict==0.14.2
|
xmltodict==0.15.1
|
||||||
rich_click==1.8.8
|
rich_click==1.8.9
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import aiohttp
|
|||||||
from . import api_helpers, ytlounge
|
from . import api_helpers, ytlounge
|
||||||
|
|
||||||
# Constants for user input prompts
|
# Constants for user input prompts
|
||||||
|
USE_PROXY_PROMPT = "Do you want to use system-wide proxy? (y/N)"
|
||||||
ATVS_REMOVAL_PROMPT = (
|
ATVS_REMOVAL_PROMPT = (
|
||||||
"Do you want to remove the legacy 'atvs' entry (the app won't start with it present)? (y/N) "
|
"Do you want to remove the legacy 'atvs' entry (the app won't start with it present)? (y/N) "
|
||||||
)
|
)
|
||||||
@@ -45,8 +46,8 @@ def get_yn_input(prompt):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
async def create_web_session():
|
async def create_web_session(use_proxy):
|
||||||
return aiohttp.ClientSession()
|
return aiohttp.ClientSession(trust_env=use_proxy)
|
||||||
|
|
||||||
|
|
||||||
async def pair_device(web_session: aiohttp.ClientSession):
|
async def pair_device(web_session: aiohttp.ClientSession):
|
||||||
@@ -75,8 +76,12 @@ async def pair_device(web_session: aiohttp.ClientSession):
|
|||||||
|
|
||||||
def main(config, debug: bool) -> None:
|
def main(config, debug: bool) -> None:
|
||||||
print("Welcome to the iSponsorBlockTV cli setup wizard")
|
print("Welcome to the iSponsorBlockTV cli setup wizard")
|
||||||
|
|
||||||
|
choice = get_yn_input(USE_PROXY_PROMPT)
|
||||||
|
config.use_proxy = choice == "y"
|
||||||
|
|
||||||
loop = asyncio.get_event_loop_policy().get_event_loop()
|
loop = asyncio.get_event_loop_policy().get_event_loop()
|
||||||
web_session = loop.run_until_complete(create_web_session())
|
web_session = loop.run_until_complete(create_web_session(config.use_proxy))
|
||||||
if debug:
|
if debug:
|
||||||
loop.set_debug(True)
|
loop.set_debug(True)
|
||||||
asyncio.set_event_loop(loop)
|
asyncio.set_event_loop(loop)
|
||||||
|
|||||||
25
src/iSponsorBlockTV/debug_helpers.py
Normal file
25
src/iSponsorBlockTV/debug_helpers.py
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
class AiohttpTracer:
|
||||||
|
def __init__(self, logger):
|
||||||
|
self.logger = logger
|
||||||
|
|
||||||
|
async def on_request_start(self, session, context, params):
|
||||||
|
self.logger.debug(f"Request started ({id(context):#x}): {params.method} {params.url}")
|
||||||
|
|
||||||
|
async def on_request_end(self, session, context, params):
|
||||||
|
self.logger.debug(f"Request ended ({id(context):#x}): {params.response.status}")
|
||||||
|
|
||||||
|
async def on_request_exception(self, session, context, params):
|
||||||
|
self.logger.debug(f"Request exception ({id(context):#x}): {params.exception}")
|
||||||
|
|
||||||
|
async def on_response_chunk_received(self, session, context, params):
|
||||||
|
chunk_size = len(params.chunk)
|
||||||
|
try:
|
||||||
|
# Try to decode as text
|
||||||
|
text = params.chunk.decode("utf-8")
|
||||||
|
self.logger.debug(f"Response chunk ({id(context):#x}) {chunk_size} bytes: {text}")
|
||||||
|
except UnicodeDecodeError:
|
||||||
|
# If not valid UTF-8, show as hex
|
||||||
|
hex_data = params.chunk.hex()
|
||||||
|
self.logger.debug(
|
||||||
|
f"Response chunk ({id(context):#x}) ({chunk_size} bytes) [HEX]: {hex_data}"
|
||||||
|
)
|
||||||
@@ -44,6 +44,7 @@ class Config:
|
|||||||
self.minimum_skip_length = 1
|
self.minimum_skip_length = 1
|
||||||
self.auto_play = True
|
self.auto_play = True
|
||||||
self.join_name = "iSponsorBlockTV"
|
self.join_name = "iSponsorBlockTV"
|
||||||
|
self.use_proxy = False
|
||||||
self.__load()
|
self.__load()
|
||||||
|
|
||||||
def validate(self):
|
def validate(self):
|
||||||
@@ -131,6 +132,7 @@ class Config:
|
|||||||
help="data directory",
|
help="data directory",
|
||||||
)
|
)
|
||||||
@click.option("--debug", is_flag=True, help="debug mode")
|
@click.option("--debug", is_flag=True, help="debug mode")
|
||||||
|
@click.option("--http-tracing", is_flag=True, help="Enable HTTP request/response tracing")
|
||||||
# legacy commands as arguments
|
# legacy commands as arguments
|
||||||
@click.option("--setup", is_flag=True, help="Setup the program graphically", hidden=True)
|
@click.option("--setup", is_flag=True, help="Setup the program graphically", hidden=True)
|
||||||
@click.option(
|
@click.option(
|
||||||
@@ -140,11 +142,12 @@ class Config:
|
|||||||
hidden=True,
|
hidden=True,
|
||||||
)
|
)
|
||||||
@click.pass_context
|
@click.pass_context
|
||||||
def cli(ctx, data, debug, setup, setup_cli):
|
def cli(ctx, data, debug, http_tracing, setup, setup_cli):
|
||||||
"""iSponsorblockTV"""
|
"""iSponsorblockTV"""
|
||||||
ctx.ensure_object(dict)
|
ctx.ensure_object(dict)
|
||||||
ctx.obj["data_dir"] = data
|
ctx.obj["data_dir"] = data
|
||||||
ctx.obj["debug"] = debug
|
ctx.obj["debug"] = debug
|
||||||
|
ctx.obj["http_tracing"] = http_tracing
|
||||||
|
|
||||||
logger = logging.getLogger()
|
logger = logging.getLogger()
|
||||||
ctx.obj["logger"] = logger
|
ctx.obj["logger"] = logger
|
||||||
@@ -189,7 +192,7 @@ def start(ctx):
|
|||||||
"""Start the main program"""
|
"""Start the main program"""
|
||||||
config = Config(ctx.obj["data_dir"])
|
config = Config(ctx.obj["data_dir"])
|
||||||
config.validate()
|
config.validate()
|
||||||
main.main(config, ctx.obj["debug"])
|
main.main(config, ctx.obj["debug"], ctx.obj["http_tracing"])
|
||||||
|
|
||||||
|
|
||||||
# Create fake "self" group to show pyapp options in help menu
|
# Create fake "self" group to show pyapp options in help menu
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ from typing import Optional
|
|||||||
import aiohttp
|
import aiohttp
|
||||||
|
|
||||||
from . import api_helpers, ytlounge
|
from . import api_helpers, ytlounge
|
||||||
|
from .debug_helpers import AiohttpTracer
|
||||||
|
|
||||||
|
|
||||||
class DeviceListener:
|
class DeviceListener:
|
||||||
@@ -153,14 +154,30 @@ def handle_signal(signum, frame):
|
|||||||
raise KeyboardInterrupt()
|
raise KeyboardInterrupt()
|
||||||
|
|
||||||
|
|
||||||
async def main_async(config, debug):
|
async def main_async(config, debug, http_tracing):
|
||||||
loop = asyncio.get_event_loop_policy().get_event_loop()
|
loop = asyncio.get_event_loop_policy().get_event_loop()
|
||||||
tasks = [] # Save the tasks so the interpreter doesn't garbage collect them
|
tasks = [] # Save the tasks so the interpreter doesn't garbage collect them
|
||||||
devices = [] # Save the devices to close them later
|
devices = [] # Save the devices to close them later
|
||||||
if debug:
|
if debug:
|
||||||
loop.set_debug(True)
|
loop.set_debug(True)
|
||||||
|
|
||||||
tcp_connector = aiohttp.TCPConnector(ttl_dns_cache=300)
|
tcp_connector = aiohttp.TCPConnector(ttl_dns_cache=300)
|
||||||
web_session = aiohttp.ClientSession(connector=tcp_connector)
|
|
||||||
|
# Configure session with tracing if enabled
|
||||||
|
if http_tracing:
|
||||||
|
root_logger = logging.getLogger("aiohttp_trace")
|
||||||
|
tracer = AiohttpTracer(root_logger)
|
||||||
|
trace_config = aiohttp.TraceConfig()
|
||||||
|
trace_config.on_request_start.append(tracer.on_request_start)
|
||||||
|
trace_config.on_response_chunk_received.append(tracer.on_response_chunk_received)
|
||||||
|
trace_config.on_request_end.append(tracer.on_request_end)
|
||||||
|
trace_config.on_request_exception.append(tracer.on_request_exception)
|
||||||
|
web_session = aiohttp.ClientSession(
|
||||||
|
trust_env=config.use_proxy, connector=tcp_connector, trace_configs=[trace_config]
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
web_session = aiohttp.ClientSession(trust_env=config.use_proxy, connector=tcp_connector)
|
||||||
|
|
||||||
api_helper = api_helpers.ApiHelper(config, web_session)
|
api_helper = api_helpers.ApiHelper(config, web_session)
|
||||||
for i in config.devices:
|
for i in config.devices:
|
||||||
device = DeviceListener(api_helper, config, i, debug, web_session)
|
device = DeviceListener(api_helper, config, i, debug, web_session)
|
||||||
@@ -184,5 +201,5 @@ async def main_async(config, debug):
|
|||||||
print("Exited")
|
print("Exited")
|
||||||
|
|
||||||
|
|
||||||
def main(config, debug):
|
def main(config, debug, http_tracing):
|
||||||
asyncio.run(main_async(config, debug))
|
asyncio.run(main_async(config, debug, http_tracing))
|
||||||
|
|||||||
@@ -383,3 +383,9 @@ MigrationScreen {
|
|||||||
padding: 1;
|
padding: 1;
|
||||||
height: auto;
|
height: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Use Proxy */
|
||||||
|
#useproxy-container{
|
||||||
|
padding: 1;
|
||||||
|
height: auto;
|
||||||
|
}
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ from textual.containers import (
|
|||||||
ScrollableContainer,
|
ScrollableContainer,
|
||||||
Vertical,
|
Vertical,
|
||||||
)
|
)
|
||||||
|
from textual.css.query import NoMatches
|
||||||
from textual.events import Click
|
from textual.events import Click
|
||||||
from textual.screen import Screen
|
from textual.screen import Screen
|
||||||
from textual.validation import Function
|
from textual.validation import Function
|
||||||
@@ -233,7 +234,7 @@ class AddDevice(ModalWithClickExit):
|
|||||||
def __init__(self, config, **kwargs) -> None:
|
def __init__(self, config, **kwargs) -> None:
|
||||||
super().__init__(**kwargs)
|
super().__init__(**kwargs)
|
||||||
self.config = config
|
self.config = config
|
||||||
self.web_session = aiohttp.ClientSession()
|
self.web_session = aiohttp.ClientSession(trust_env=config.use_proxy)
|
||||||
self.api_helper = api_helpers.ApiHelper(config, self.web_session)
|
self.api_helper = api_helpers.ApiHelper(config, self.web_session)
|
||||||
self.devices_discovered_dial = []
|
self.devices_discovered_dial = []
|
||||||
|
|
||||||
@@ -301,7 +302,11 @@ class AddDevice(ModalWithClickExit):
|
|||||||
|
|
||||||
async def task_discover_devices(self):
|
async def task_discover_devices(self):
|
||||||
devices_found = await self.api_helper.discover_youtube_devices_dial()
|
devices_found = await self.api_helper.discover_youtube_devices_dial()
|
||||||
list_widget: SelectionList = self.query_one("#dial-devices-list")
|
try:
|
||||||
|
list_widget: SelectionList = self.query_one("#dial-devices-list")
|
||||||
|
except NoMatches:
|
||||||
|
# The widget was not found, probably the screen was dismissed
|
||||||
|
return
|
||||||
list_widget.clear_options()
|
list_widget.clear_options()
|
||||||
if devices_found:
|
if devices_found:
|
||||||
# print(devices_found)
|
# print(devices_found)
|
||||||
@@ -336,7 +341,7 @@ class AddDevice(ModalWithClickExit):
|
|||||||
pairing_code = int(
|
pairing_code = int(
|
||||||
pairing_code.replace("-", "").replace(" ", "")
|
pairing_code.replace("-", "").replace(" ", "")
|
||||||
) # remove dashes and spaces
|
) # remove dashes and spaces
|
||||||
device_name = self.parent.query_one("#device-name-input").value
|
device_name = self.query_one("#device-name-input").value
|
||||||
paired = False
|
paired = False
|
||||||
try:
|
try:
|
||||||
paired = await lounge_controller.pair(pairing_code)
|
paired = await lounge_controller.pair(pairing_code)
|
||||||
@@ -382,7 +387,7 @@ class AddChannel(ModalWithClickExit):
|
|||||||
def __init__(self, config, **kwargs) -> None:
|
def __init__(self, config, **kwargs) -> None:
|
||||||
super().__init__(**kwargs)
|
super().__init__(**kwargs)
|
||||||
self.config = config
|
self.config = config
|
||||||
web_session = aiohttp.ClientSession()
|
web_session = aiohttp.ClientSession(trust_env=config.use_proxy)
|
||||||
self.api_helper = api_helpers.ApiHelper(config, web_session)
|
self.api_helper = api_helpers.ApiHelper(config, web_session)
|
||||||
|
|
||||||
def compose(self) -> ComposeResult:
|
def compose(self) -> ComposeResult:
|
||||||
@@ -659,7 +664,7 @@ class ApiKeyManager(Vertical):
|
|||||||
|
|
||||||
@on(Button.Pressed, "#api-key-view")
|
@on(Button.Pressed, "#api-key-view")
|
||||||
def pressed_api_key_view(self, event: Button.Pressed):
|
def pressed_api_key_view(self, event: Button.Pressed):
|
||||||
if "Show" in event.button.label:
|
if "Show" in str(event.button.label):
|
||||||
event.button.label = "Hide key"
|
event.button.label = "Hide key"
|
||||||
self.query_one("#api-key-input").password = False
|
self.query_one("#api-key-input").password = False
|
||||||
else:
|
else:
|
||||||
@@ -820,10 +825,7 @@ class ChannelWhitelistManager(Vertical):
|
|||||||
id="channel-whitelist-subtitle",
|
id="channel-whitelist-subtitle",
|
||||||
)
|
)
|
||||||
yield Label(
|
yield Label(
|
||||||
(
|
("⚠️ [#FF0000]You need to set your YouTube Api Key in order to use this feature"),
|
||||||
":warning: [#FF0000]You need to set your YouTube Api Key in order to"
|
|
||||||
" use this feature"
|
|
||||||
),
|
|
||||||
id="warning-no-key",
|
id="warning-no-key",
|
||||||
)
|
)
|
||||||
with Horizontal(id="add-channel-button-container"):
|
with Horizontal(id="add-channel-button-container"):
|
||||||
@@ -890,11 +892,45 @@ class AutoPlayManager(Vertical):
|
|||||||
self.config.auto_play = event.checkbox.value
|
self.config.auto_play = event.checkbox.value
|
||||||
|
|
||||||
|
|
||||||
class ISponsorBlockTVSetupMainScreen(Screen):
|
class UseProxyManager(Vertical):
|
||||||
|
"""Manager for proxy use, allows enabling/disabling use of proxy."""
|
||||||
|
|
||||||
|
def __init__(self, config, **kwargs) -> None:
|
||||||
|
super().__init__(**kwargs)
|
||||||
|
self.config = config
|
||||||
|
|
||||||
|
def compose(self) -> ComposeResult:
|
||||||
|
yield Label("Use proxy", classes="title")
|
||||||
|
yield Label(
|
||||||
|
"This feature allows application to use system proxy,"
|
||||||
|
" if it is set in environment variables."
|
||||||
|
" This parameter will be passed in all [i]aiohttp.ClientSession[/i]"
|
||||||
|
' calls. For further information, see "[i]trust_env[/i]" section at'
|
||||||
|
" [link='https://docs.aiohttp.org/en/stable/client_reference.html']"
|
||||||
|
"aiohttp documentation[/link].",
|
||||||
|
classes="subtitle",
|
||||||
|
id="useproxy-subtitle",
|
||||||
|
)
|
||||||
|
with Horizontal(id="useproxy-container"):
|
||||||
|
yield Checkbox(
|
||||||
|
value=self.config.use_proxy,
|
||||||
|
id="useproxy-switch",
|
||||||
|
label="Use proxy",
|
||||||
|
)
|
||||||
|
|
||||||
|
@on(Checkbox.Changed, "#useproxy-switch")
|
||||||
|
def changed_skip(self, event: Checkbox.Changed):
|
||||||
|
self.config.use_proxy = event.checkbox.value
|
||||||
|
|
||||||
|
|
||||||
|
class ISponsorBlockTVSetup(App):
|
||||||
TITLE = "iSponsorBlockTV"
|
TITLE = "iSponsorBlockTV"
|
||||||
SUB_TITLE = "Setup Wizard"
|
SUB_TITLE = "Setup Wizard"
|
||||||
BINDINGS = [("q,ctrl+c", "exit_modal", "Exit"), ("s", "save", "Save")]
|
BINDINGS = [("q,ctrl+c", "exit_modal", "Exit"), ("s", "save", "Save")]
|
||||||
AUTO_FOCUS = None
|
AUTO_FOCUS = None
|
||||||
|
CSS_PATH = ( # tcss is the recommended extension for textual css files
|
||||||
|
"setup-wizard-style.tcss"
|
||||||
|
)
|
||||||
|
|
||||||
def __init__(self, config, **kwargs) -> None:
|
def __init__(self, config, **kwargs) -> None:
|
||||||
super().__init__(**kwargs)
|
super().__init__(**kwargs)
|
||||||
@@ -926,6 +962,7 @@ class ISponsorBlockTVSetupMainScreen(Screen):
|
|||||||
)
|
)
|
||||||
yield ApiKeyManager(config=self.config, id="api-key-manager", classes="container")
|
yield ApiKeyManager(config=self.config, id="api-key-manager", classes="container")
|
||||||
yield AutoPlayManager(config=self.config, id="autoplay-manager", classes="container")
|
yield AutoPlayManager(config=self.config, id="autoplay-manager", classes="container")
|
||||||
|
yield UseProxyManager(config=self.config, id="useproxy-manager", classes="container")
|
||||||
|
|
||||||
def on_mount(self) -> None:
|
def on_mount(self) -> None:
|
||||||
if self.check_for_old_config_entries():
|
if self.check_for_old_config_entries():
|
||||||
@@ -949,36 +986,13 @@ class ISponsorBlockTVSetupMainScreen(Screen):
|
|||||||
@on(Input.Changed, "#api-key-input")
|
@on(Input.Changed, "#api-key-input")
|
||||||
def changed_api_key(self, event: Input.Changed):
|
def changed_api_key(self, event: Input.Changed):
|
||||||
try: # ChannelWhitelist might not be mounted
|
try: # ChannelWhitelist might not be mounted
|
||||||
# Show if no api key is set and at least one channel is in the whitelist
|
self.app.query_one("#warning-no-key").display = bool(
|
||||||
self.app.query_one("#warning-no-key").display = (
|
(not event.input.value) and self.config.channel_whitelist
|
||||||
not event.input.value
|
)
|
||||||
) and self.config.channel_whitelist
|
except NoMatches:
|
||||||
except BaseException:
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class ISponsorBlockTVSetup(App):
|
|
||||||
CSS_PATH = ( # tcss is the recommended extension for textual css files
|
|
||||||
"setup-wizard-style.tcss"
|
|
||||||
)
|
|
||||||
# Bindings for the whole app here, so they are available in all screens
|
|
||||||
BINDINGS = [("q,ctrl+c", "exit_modal", "Exit"), ("s", "save", "Save")]
|
|
||||||
|
|
||||||
def __init__(self, config, **kwargs) -> None:
|
|
||||||
super().__init__(**kwargs)
|
|
||||||
self.config = config
|
|
||||||
self.main_screen = ISponsorBlockTVSetupMainScreen(config=self.config)
|
|
||||||
|
|
||||||
def on_mount(self) -> None:
|
|
||||||
self.push_screen(self.main_screen)
|
|
||||||
|
|
||||||
def action_save(self) -> None:
|
|
||||||
self.main_screen.action_save()
|
|
||||||
|
|
||||||
def action_exit_modal(self) -> None:
|
|
||||||
self.main_screen.action_exit_modal()
|
|
||||||
|
|
||||||
|
|
||||||
def main(config):
|
def main(config):
|
||||||
app = ISponsorBlockTVSetup(config)
|
app = ISponsorBlockTVSetup(config)
|
||||||
app.run()
|
app.run()
|
||||||
|
|||||||
@@ -1,10 +1,14 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
import json
|
import json
|
||||||
|
import sys
|
||||||
from typing import Any, List
|
from typing import Any, List
|
||||||
|
|
||||||
import pyytlounge
|
import pyytlounge
|
||||||
from aiohttp import ClientSession
|
from aiohttp import ClientSession
|
||||||
|
|
||||||
|
from pyytlounge.wrapper import NotLinkedException, api_base, as_aiter, Dict
|
||||||
|
from uuid import uuid4
|
||||||
|
|
||||||
from .constants import youtube_client_blacklist
|
from .constants import youtube_client_blacklist
|
||||||
|
|
||||||
create_task = asyncio.create_task
|
create_task = asyncio.create_task
|
||||||
@@ -236,3 +240,110 @@ class YtLoungeApi(pyytlounge.YtLoungeApi):
|
|||||||
if self.conn is not None:
|
if self.conn is not None:
|
||||||
await self.conn.close()
|
await self.conn.close()
|
||||||
self.session = web_session
|
self.session = web_session
|
||||||
|
|
||||||
|
def _common_connection_parameters(self) -> Dict[str, Any]:
|
||||||
|
return {
|
||||||
|
"name": self.device_name,
|
||||||
|
"loungeIdToken": self.auth.lounge_id_token,
|
||||||
|
"SID": self._sid,
|
||||||
|
"AID": self._last_event_id,
|
||||||
|
"gsessionid": self._gsession,
|
||||||
|
"device": "REMOTE_CONTROL",
|
||||||
|
"app": "ytios-phone-20.15.1",
|
||||||
|
"VER": "8",
|
||||||
|
"v": "2",
|
||||||
|
}
|
||||||
|
|
||||||
|
async def connect(self) -> bool:
|
||||||
|
"""Attempt to connect using the previously set tokens"""
|
||||||
|
if not self.linked():
|
||||||
|
raise NotLinkedException("Not linked")
|
||||||
|
|
||||||
|
connect_body = {
|
||||||
|
"id": self.auth.screen_id,
|
||||||
|
"mdx-version": "3",
|
||||||
|
"TYPE": "xmlhttp",
|
||||||
|
"theme": "cl",
|
||||||
|
"sessionSource": "MDX_SESSION_SOURCE_UNKNOWN",
|
||||||
|
"connectParams": '{"setStatesParams": "{"playbackSpeed":0}"}',
|
||||||
|
"RID": "1",
|
||||||
|
"CVER": "1",
|
||||||
|
"capabilities": "que,dsdtr,atp,vsp",
|
||||||
|
"ui": "false",
|
||||||
|
"app": "ytios-phone-20.15.1",
|
||||||
|
"pairing_type": "manual",
|
||||||
|
"VER": "8",
|
||||||
|
"loungeIdToken": self.auth.lounge_id_token,
|
||||||
|
"device": "REMOTE_CONTROL",
|
||||||
|
"name": self.device_name,
|
||||||
|
}
|
||||||
|
connect_url = f"{api_base}/bc/bind"
|
||||||
|
async with self.session.post(url=connect_url, data=connect_body) as resp:
|
||||||
|
try:
|
||||||
|
text = await resp.text()
|
||||||
|
if resp.status == 401:
|
||||||
|
if "Connection denied" in text:
|
||||||
|
self._logger.warning(
|
||||||
|
"Connection denied, attempting to circumvent the issue"
|
||||||
|
)
|
||||||
|
await self.connect_as_screen()
|
||||||
|
# self._lounge_token_expired()
|
||||||
|
return False
|
||||||
|
|
||||||
|
if resp.status != 200:
|
||||||
|
self._logger.warning("Unknown reply to connect %i %s", resp.status, resp.reason)
|
||||||
|
return False
|
||||||
|
lines = text.splitlines()
|
||||||
|
async for events in self._parse_event_chunks(as_aiter(lines)):
|
||||||
|
self._process_events(events)
|
||||||
|
self._command_offset = 1
|
||||||
|
return self.connected()
|
||||||
|
except:
|
||||||
|
self._logger.exception(
|
||||||
|
"Handle connect failed, status %s reason %s",
|
||||||
|
resp.status,
|
||||||
|
resp.reason,
|
||||||
|
)
|
||||||
|
raise
|
||||||
|
|
||||||
|
async def connect_as_screen(self) -> bool:
|
||||||
|
"""Attempt to connect using the previously set tokens"""
|
||||||
|
if not self.linked():
|
||||||
|
raise NotLinkedException("Not linked")
|
||||||
|
|
||||||
|
connect_body = {
|
||||||
|
"id": str(uuid4()),
|
||||||
|
"mdx-version": "3",
|
||||||
|
"TYPE": "xmlhttp",
|
||||||
|
"theme": "cl",
|
||||||
|
"sessionSource": "MDX_SESSION_SOURCE_UNKNOWN",
|
||||||
|
"connectParams": '{"setStatesParams": "{"playbackSpeed":0}"}',
|
||||||
|
"sessionNonce": str(uuid4()),
|
||||||
|
"RID": "1",
|
||||||
|
"CVER": "1",
|
||||||
|
"capabilities": "que,dsdtr,atp,vsp",
|
||||||
|
"ui": "false",
|
||||||
|
"app": "ytios-phone-20.15.1",
|
||||||
|
"pairing_type": "manual",
|
||||||
|
"VER": "8",
|
||||||
|
"loungeIdToken": self.auth.lounge_id_token,
|
||||||
|
"device": "LOUNGE_SCREEN",
|
||||||
|
"name": self.device_name,
|
||||||
|
}
|
||||||
|
connect_url = f"{api_base}/bc/bind"
|
||||||
|
async with self.session.post(url=connect_url, data=connect_body) as resp:
|
||||||
|
try:
|
||||||
|
await resp.text()
|
||||||
|
self.logger.error(
|
||||||
|
"Connected as screen: please force close the app on the device for iSponsorBlockTV to work properly"
|
||||||
|
)
|
||||||
|
self.logger.warn("Exiting in 5 seconds")
|
||||||
|
await asyncio.sleep(5)
|
||||||
|
sys.exit(0)
|
||||||
|
except:
|
||||||
|
self._logger.exception(
|
||||||
|
"Handle connect failed, status %s reason %s",
|
||||||
|
resp.status,
|
||||||
|
resp.reason,
|
||||||
|
)
|
||||||
|
raise
|
||||||
|
|||||||
Reference in New Issue
Block a user