Skip to content

Commit

Permalink
v1.4.12.41 beta 3
Browse files Browse the repository at this point in the history
  • Loading branch information
sebdelsol committed Mar 20, 2024
1 parent ec4acaa commit bdfc6a7
Show file tree
Hide file tree
Showing 38 changed files with 468 additions and 347 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"python.analysis.diagnosticMode": "workspace",
// formatter & import sort
"ruff.format.args": ["--line-length=115"],
"ruff.lint.args": ["--line-length=115"],
"[python]": {
"editor.codeActionsOnSave": {
"source.organizeImports": "explicit",
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Insert an _All_ category when missing so you can easily **search your entire catalog**.
<kbd><img src="resources/readme/all.png"></kbd>
* Update ***[Mpv](https://mpv.io/)*** and **Sfvip Player** so you can enjoy their latest features.
* Cache MAC acccounts all categories to access it faster.
* Translated in all **Sfvip Player** languages.
* Support an **external EPG**[^1].

Expand Down Expand Up @@ -43,7 +44,7 @@ You'll find them in the app folder:

# Build
[![version](https://custom-icon-badges.demolab.com/badge/Build%201.4.12.41-informational?logo=github)](/build_config.py#L27)
[![Sloc](https://custom-icon-badges.demolab.com/badge/Sloc%208.3k-informational?logo=file-code)](https://api.codetabs.com/v1/loc/?github=sebdelsol/sfvip-all)
[![Sloc](https://custom-icon-badges.demolab.com/badge/Sloc%208.4k-informational?logo=file-code)](https://api.codetabs.com/v1/loc/?github=sebdelsol/sfvip-all)
[![Ruff](https://custom-icon-badges.demolab.com/badge/Ruff-informational?logo=ruff-color)](https://docs.astral.sh/ruff/)
[![Python](https://custom-icon-badges.demolab.com/badge/Python%203.11.8-linen?logo=python-color)](https://www.python.org/downloads/release/python-3118/)
[![mitmproxy](https://custom-icon-badges.demolab.com/badge/Mitmproxy%2010.2.4-linen?logo=mitmproxy-black)](https://mitmproxy.org/)
Expand Down
3 changes: 3 additions & 0 deletions build/changelog.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
## 1.4.12.41
* Faster MAC accounts cache for all categories.
* MAC accounts cache handles partial update.
* All categories are added only when needed.
* Tooltips added.

## 1.4.12.40
Expand Down
8 changes: 1 addition & 7 deletions dev/tools/release.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
from pathlib import Path
from typing import Optional

from github import (
Auth,
BadCredentialsException,
Github,
GithubException,
UnknownObjectException,
)
from github import Auth, BadCredentialsException, Github, GithubException, UnknownObjectException
from github.GitRelease import GitRelease

from api_keys import GITHUB_TOKEN
Expand Down
8 changes: 1 addition & 7 deletions dev/tools/templater.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,7 @@
from .scanner.file import ScanFile
from .utils.color import Low, Ok, Title, Warn
from .utils.dist import human_format, repr_size
from .utils.protocols import (
CfgBuild,
CfgEnvironments,
CfgGithub,
CfgTemplate,
CfgTemplates,
)
from .utils.protocols import CfgBuild, CfgEnvironments, CfgGithub, CfgTemplate, CfgTemplates


def _version_of(python_envs: PythonEnvs, name: str) -> Optional[str]:
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# packages to run the app for both environments
mitmproxy>=10.1.6
msgspec>=0.18.6
tkinter-tooltip>=2.2.0
watchdog>=3.0.0
# for downloading the player and libmpv
Expand Down
1 change: 1 addition & 0 deletions resources/README_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Insert an _All_ category when missing so you can easily **search your entire catalog**.
<kbd><img src="resources/readme/all.png"></kbd>
* Update ***[Mpv](https://mpv.io/)*** and **Sfvip Player** so you can enjoy their latest features.
* Cache MAC acccounts all categories to access it faster.
* Translated in all **Sfvip Player** languages.
* Support an **external EPG**[^1].

Expand Down
3 changes: 0 additions & 3 deletions sfvip_all_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,3 @@ class EPG:
confidence: int = 30
requests_timeout: int = 5
prefer_internal: bool = True

class AllCategory:
inject_in_live: bool = False
101 changes: 55 additions & 46 deletions src/mitm/addon/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from mitmproxy import http
from mitmproxy.proxy.server_hooks import ServerConnectionHookData

from ..cache import AllUpdated, MACCache, UpdateCacheProgressT
from ..cache import AllCached, MACCache, UpdateCacheProgressT
from ..epg import EPG, EpgCallbacks
from ..utils import APItype, get_query_key, response_json
from .all import AllCategoryName, AllPanels
Expand Down Expand Up @@ -63,16 +63,20 @@ def set_epg_server(flow: http.HTTPFlow, epg: EPG, api: APItype) -> None:


class ApiRequest:
_api = {"portal.php?": APItype.MAC, "player_api.php?": APItype.XC}
_api = {
"player_api.php": APItype.XC,
"stalker_portal": APItype.MAC,
"portal.php": APItype.MAC,
"load.php": APItype.MAC,
}

def __init__(self, accounts_urls: set[str]) -> None:
self.accounts_urls = accounts_urls

def __call__(self, flow: http.HTTPFlow) -> Optional[APItype]:
async def __call__(self, flow: http.HTTPFlow) -> Optional[APItype]:
request = flow.request
for request_part, api in ApiRequest._api.items():
if request_part in request.path:
return api
if api := ApiRequest._api.get(request.path_components[0]):
return api
return APItype.M3U if request.url in self.accounts_urls else None


Expand Down Expand Up @@ -135,7 +139,7 @@ def disconnect(self, data: ServerConnectionHookData) -> None:

class AddonAllConfig(NamedTuple):
all_name: AllCategoryName
all_updated: AllUpdated
all_cached: AllCached


class SfVipAddOn:
Expand All @@ -152,7 +156,7 @@ def __init__(
timeout: int,
) -> None:
self.api_request = ApiRequest(accounts_urls)
self.mac_cache = MACCache(roaming, update_progress, all_config.all_updated)
self.mac_cache = MACCache(roaming, update_progress, all_config.all_cached)
self.epg = EPG(roaming, epg_callbacks, timeout)
self.m3u_stream = M3UStream(self.epg)
self.panels = AllPanels(all_config.all_name)
Expand All @@ -176,56 +180,61 @@ def wait_running(self, timeout: int) -> bool:
return self.epg.wait_running(timeout)

async def request(self, flow: http.HTTPFlow) -> None:
logger.debug("REQUEST %s", flow.request.pretty_url)
if api := self.api_request(flow):
# logger.debug("REQUEST %s", flow.request.pretty_url)
if api := await self.api_request(flow):
match api, get_query_key(flow, "action"):
case APItype.MAC, "get_ordered_list":
self.mac_cache.load_response(flow)
await self.mac_cache.load_response(flow)
case APItype.MAC, _:
self.mac_cache.stop(flow)
case APItype.XC, action if action:
self.panels.serve_all(flow, action)

async def response(self, flow: http.HTTPFlow) -> None:
logger.debug("RESPONSE %s %s", flow.request.pretty_url, flow.response and flow.response.status_code)
if not self.m3u_stream.start(flow):
if flow.response and not flow.response.stream:
if api := self.api_request(flow):
match api, get_query_key(flow, "action"):
case APItype.M3U, _:
set_epg_server(flow, self.epg, api)
case APItype.MAC, "get_short_epg":
get_short_epg(flow, self.epg, api)
case APItype.MAC, "get_all_channels":
set_epg_server(flow, self.epg, api)
case APItype.MAC, "get_ordered_list":
self.mac_cache.save_response(flow)
case APItype.MAC, "get_categories":
self.mac_cache.inject_all_cached_category(flow)
case APItype.XC, "get_series_info":
fix_series_info(flow.response)
case APItype.XC, "get_live_streams":
set_epg_server(flow, self.epg, api)
case APItype.XC, "get_short_epg" if not get_query_key(flow, "category_id"):
get_short_epg(flow, self.epg, api)
case APItype.XC, action if action:
self.panels.inject_all(flow, action)
async def responseheaders(self, flow: http.HTTPFlow) -> None:
"""all reponses are streamed except the api requests"""
# logger.debug("STREAM %s", flow.request.pretty_url)
if not await self.api_request(flow):
if flow.response:
flow.response.stream = True

async def response(self, flow: http.HTTPFlow) -> None:
# logger.debug("RESPONSE %s %s", flow.request.pretty_url, flow.response and flow.response.status_code)
if not flow.response:
return
if not flow.response.stream:
if api := await self.api_request(flow):
match api, get_query_key(flow, "action"):
case APItype.MAC, "get_ordered_list":
await self.mac_cache.save_response(flow)
case APItype.MAC, "get_short_epg":
get_short_epg(flow, self.epg, api)
case APItype.MAC, "get_all_channels":
set_epg_server(flow, self.epg, api)
case APItype.MAC, "get_categories":
self.mac_cache.inject_all_cached_category(flow)
case APItype.XC, "get_series_info":
fix_series_info(flow.response)
case APItype.XC, "get_live_streams":
set_epg_server(flow, self.epg, api)
case APItype.XC, "get_short_epg" if not get_query_key(flow, "category_id"):
get_short_epg(flow, self.epg, api)
case APItype.XC, action if action:
self.panels.inject_all(flow, action)
case APItype.M3U, _:
set_epg_server(flow, self.epg, api)
else:
self.m3u_stream.start(flow)
self.mac_cache.stop_all()

# TODO progress for MAC Cache not hiding !! nee to call self.mac_cache.stop_all(), but where?
async def error(self, flow: http.HTTPFlow):
logger.debug("ERROR %s", flow.request.pretty_url)
# logger.debug("ERROR %s", flow.request.pretty_url)
if not self.m3u_stream.stop(flow):
if api := self.api_request(flow):
if api := await self.api_request(flow):
match api, get_query_key(flow, "action"):
case APItype.MAC, "get_ordered_list":
self.mac_cache.stop(flow)

async def responseheaders(self, flow: http.HTTPFlow) -> None:
"""all reponses are streamed except the api requests"""
logger.debug("STREAM %s", flow.request.pretty_url)
if not self.api_request(flow):
if flow.response:
flow.response.stream = True

async def server_disconnected(self, data: ServerConnectionHookData) -> None:
logger.debug("DISCONNECT %s %s", data.server.peername, data.server.transport_protocol)
def server_disconnected(self, data: ServerConnectionHookData) -> None:
# logger.debug("DISCONNECT %s %s", data.server.peername, data.server.transport_protocol)
self.m3u_stream.disconnect(data)
13 changes: 7 additions & 6 deletions src/mitm/addon/all.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

class AllCategoryName(NamedTuple):
live: Optional[str]
series: str
vod: str
series: Optional[str]
vod: Optional[str]


@dataclass
Expand Down Expand Up @@ -56,10 +56,11 @@ def _log(verb: str, panel: Panel, action: str) -> None:

class AllPanels:
def __init__(self, all_name: AllCategoryName) -> None:
panels = [
_get_panel(PanelType.VOD, all_name.vod),
_get_panel(PanelType.SERIES, all_name.series, streams=False),
]
panels = []
if all_name.series:
panels.append(_get_panel(PanelType.SERIES, all_name.series, streams=False))
if all_name.vod:
panels.append(_get_panel(PanelType.VOD, all_name.vod))
if all_name.live:
panels.append(_get_panel(PanelType.LIVE, all_name.live))
self.category_panel = {panel.get_category: panel for panel in panels}
Expand Down
Loading

0 comments on commit bdfc6a7

Please sign in to comment.