Skip to content

Commit 0449843

Browse files
authored
Add stats to channel call (#58)
1 parent 25177b6 commit 0449843

File tree

4 files changed

+20
-4
lines changed

4 files changed

+20
-4
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "youtubeaio"
3-
version = "1.1.0"
3+
version = "1.1.1"
44
description = "Asynchronous Python client for YouTube V3 API."
55
authors = ["Joost Lekkerkerker <[email protected]>"]
66
maintainers = ["Joost Lekkerkerker <[email protected]>"]

src/youtubeaio/models.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,15 @@ class YouTubeChannelContentDetails(BaseModel):
102102
)
103103

104104

105+
class YouTubeChannelStatistics(BaseModel):
106+
"""Model representing statistics of a channel."""
107+
108+
view_count: int = Field(..., alias="viewCount")
109+
subscriber_count: int = Field(..., alias="subscriberCount")
110+
subscriber_count_hidden: bool = Field(..., alias="hiddenSubscriberCount")
111+
video_count: int = Field(..., alias="videoCount")
112+
113+
105114
class YouTubeChannelSnippet(BaseModel):
106115
"""Model representing channel snippet."""
107116

@@ -121,6 +130,7 @@ class YouTubeChannel(BaseModel):
121130
None,
122131
alias="contentDetails",
123132
)
133+
statistics: YouTubeChannelStatistics | None = None
124134

125135
@property
126136
def upload_playlist_id(self) -> str:

src/youtubeaio/youtube.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ async def get_channels(
233233
) -> AsyncGenerator[YouTubeChannel, None]:
234234
"""Return list of channels."""
235235
param = {
236-
"part": "snippet",
236+
"part": "snippet,contentDetails,statistics",
237237
"id": channel_ids,
238238
}
239239
async for item in self._get_channels(param):

tests/fixtures/channel_response_snippet.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
{
22
"kind": "youtube#channelListResponse",
3-
"etag": "sM5ffk5W79swi2V870w6CmMlPgs",
3+
"etag": "9sIVzjSfOfk6gN357UcUDTWRTec",
44
"pageInfo": {
55
"totalResults": 1,
66
"resultsPerPage": 5
77
},
88
"items": [
99
{
1010
"kind": "youtube#channel",
11-
"etag": "ieb4dig-VKDKW3FEut81IwUEiog",
11+
"etag": "veRvdNDE9HmhyENPqeFNq-VH6NI",
1212
"id": "UC_x5XG1OV2P6uZZ5FSM9Ttw",
1313
"snippet": {
1414
"title": "Google for Developers",
@@ -37,6 +37,12 @@
3737
"description": "Subscribe to join a community of creative developers and learn the latest in Google technology — from AI and cloud, to mobile and web.\n\nExplore more at developers.google.com\n\n"
3838
},
3939
"country": "US"
40+
},
41+
"statistics": {
42+
"viewCount": "234084903",
43+
"subscriberCount": "2300000",
44+
"hiddenSubscriberCount": false,
45+
"videoCount": "5783"
4046
}
4147
}
4248
]

0 commit comments

Comments
 (0)