Skip to content

Commit

Permalink
Implement ResponseContext models
Browse files Browse the repository at this point in the history
  • Loading branch information
tombulled committed Aug 12, 2023
1 parent 22d1166 commit dd4c605
Show file tree
Hide file tree
Showing 6 changed files with 442 additions and 218 deletions.
5 changes: 0 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,5 @@ dmypy.json
.vscode/

# Custom
app.py
app.*.py
tst.py
tst.*.py
_.*.py
_.*/
.ignore/
13 changes: 13 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from innertube import InnerTube
from innertube.raw_models import ResponseContext

WEB = InnerTube("WEB", "2.20230728.00.00")
WEB_REMIX = InnerTube("WEB_REMIX", "1.20220607.03.01")
IOS = InnerTube("IOS", "17.14.2")
IOS_MUSIC = InnerTube("IOS_MUSIC", "4.16.1")

channel_id: str = "UC8Yu1_yfN5qPh601Y4btsYw" # Arctic Monkeys

d = data = WEB_REMIX.adaptor.dispatch("browse", body={"browseId": channel_id})

rc = ResponseContext.parse_obj(data["responseContext"])
5 changes: 5 additions & 0 deletions innertube/raw_enums.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from enum import Enum, auto


class SharePanelType(Enum):
SHARE_PANEL_TYPE_UNIFIED_SHARE_PANEL = auto()
48 changes: 48 additions & 0 deletions innertube/raw_models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import pydantic
import humps
from typing import Optional, Sequence

from .raw_enums import SharePanelType


class BaseModel(pydantic.BaseModel):
class Config:
alias_generator = humps.camelize


class ServiceTrackingParam(BaseModel):
key: str
value: str


class ServiceTrackingParams(BaseModel):
service: str
params: Sequence[ServiceTrackingParam]


class MainAppWebResponseContext(BaseModel):
logged_out: bool
tracking_param: str


class WebResponseContextExtensionData(BaseModel):
has_decorated: bool


class ResponseContext(BaseModel):
visitor_data: str
service_tracking_params: Sequence[ServiceTrackingParams]
max_age_seconds: int
main_app_web_response_context: Optional[MainAppWebResponseContext] = None
web_response_context_extension_data: Optional[
WebResponseContextExtensionData
] = None


class Response(BaseModel):
response_context: ResponseContext


class ShareEntityEndpoint(BaseModel):
serialized_share_entity: str
share_panel_type: SharePanelType
Loading

0 comments on commit dd4c605

Please sign in to comment.