ytstudio-cli 0.1.0__tar.gz → 0.1.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ytstudio_cli-0.1.1/.editorconfig +15 -0
- {ytstudio_cli-0.1.0 → ytstudio_cli-0.1.1}/.gitignore +1 -0
- {ytstudio_cli-0.1.0 → ytstudio_cli-0.1.1}/PKG-INFO +27 -12
- {ytstudio_cli-0.1.0 → ytstudio_cli-0.1.1}/README.md +26 -11
- {ytstudio_cli-0.1.0 → ytstudio_cli-0.1.1}/pyproject.toml +1 -1
- {ytstudio_cli-0.1.0 → ytstudio_cli-0.1.1}/src/ytstudio/commands/videos.py +11 -13
- {ytstudio_cli-0.1.0 → ytstudio_cli-0.1.1}/tests/conftest.py +6 -0
- ytstudio_cli-0.1.1/tests/test_videos.py +249 -0
- ytstudio_cli-0.1.0/tests/test_videos.py +0 -43
- {ytstudio_cli-0.1.0 → ytstudio_cli-0.1.1}/.github/workflows/ci.yml +0 -0
- {ytstudio_cli-0.1.0 → ytstudio_cli-0.1.1}/.pre-commit-config.yaml +0 -0
- {ytstudio_cli-0.1.0 → ytstudio_cli-0.1.1}/.python-version +0 -0
- {ytstudio_cli-0.1.0 → ytstudio_cli-0.1.1}/LICENSE +0 -0
- {ytstudio_cli-0.1.0 → ytstudio_cli-0.1.1}/demo.gif +0 -0
- {ytstudio_cli-0.1.0 → ytstudio_cli-0.1.1}/src/ytstudio/__init__.py +0 -0
- {ytstudio_cli-0.1.0 → ytstudio_cli-0.1.1}/src/ytstudio/api.py +0 -0
- {ytstudio_cli-0.1.0 → ytstudio_cli-0.1.1}/src/ytstudio/commands/__init__.py +0 -0
- {ytstudio_cli-0.1.0 → ytstudio_cli-0.1.1}/src/ytstudio/commands/analytics.py +0 -0
- {ytstudio_cli-0.1.0 → ytstudio_cli-0.1.1}/src/ytstudio/commands/comments.py +0 -0
- {ytstudio_cli-0.1.0 → ytstudio_cli-0.1.1}/src/ytstudio/config.py +0 -0
- {ytstudio_cli-0.1.0 → ytstudio_cli-0.1.1}/src/ytstudio/demo.py +0 -0
- {ytstudio_cli-0.1.0 → ytstudio_cli-0.1.1}/src/ytstudio/demo_data/analytics_metrics.json +0 -0
- {ytstudio_cli-0.1.0 → ytstudio_cli-0.1.1}/src/ytstudio/demo_data/channel.json +0 -0
- {ytstudio_cli-0.1.0 → ytstudio_cli-0.1.1}/src/ytstudio/demo_data/comments.json +0 -0
- {ytstudio_cli-0.1.0 → ytstudio_cli-0.1.1}/src/ytstudio/demo_data/playlist_items.json +0 -0
- {ytstudio_cli-0.1.0 → ytstudio_cli-0.1.1}/src/ytstudio/demo_data/videos.json +0 -0
- {ytstudio_cli-0.1.0 → ytstudio_cli-0.1.1}/src/ytstudio/main.py +0 -0
- {ytstudio_cli-0.1.0 → ytstudio_cli-0.1.1}/src/ytstudio/registry.py +0 -0
- {ytstudio_cli-0.1.0 → ytstudio_cli-0.1.1}/src/ytstudio/services.py +0 -0
- {ytstudio_cli-0.1.0 → ytstudio_cli-0.1.1}/src/ytstudio/ui.py +0 -0
- {ytstudio_cli-0.1.0 → ytstudio_cli-0.1.1}/src/ytstudio/version.py +0 -0
- {ytstudio_cli-0.1.0 → ytstudio_cli-0.1.1}/tests/__init__.py +0 -0
- {ytstudio_cli-0.1.0 → ytstudio_cli-0.1.1}/tests/test_analytics.py +0 -0
- {ytstudio_cli-0.1.0 → ytstudio_cli-0.1.1}/tests/test_api.py +0 -0
- {ytstudio_cli-0.1.0 → ytstudio_cli-0.1.1}/tests/test_comments.py +0 -0
- {ytstudio_cli-0.1.0 → ytstudio_cli-0.1.1}/tests/test_config.py +0 -0
- {ytstudio_cli-0.1.0 → ytstudio_cli-0.1.1}/tests/test_registry.py +0 -0
- {ytstudio_cli-0.1.0 → ytstudio_cli-0.1.1}/uv.lock +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: ytstudio-cli
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.1
|
|
4
4
|
Summary: CLI tool to manage and analyze your YouTube channel from the terminal
|
|
5
5
|
Project-URL: Homepage, https://github.com/jdwit/ytstudio-cli
|
|
6
6
|
Project-URL: Repository, https://github.com/jdwit/ytstudio-cli
|
|
@@ -37,10 +37,11 @@ Manage and analyze your YouTube channel from the terminal. Ideal for automation
|
|
|
37
37
|
|
|
38
38
|
## Motivation
|
|
39
39
|
|
|
40
|
-
I built this because I needed to bulk update video titles for a YouTube channel I manage with 300+
|
|
41
|
-
Studio does not support bulk search-replace operations, which made it a tedious
|
|
42
|
-
YouTube Data API to perform bulk operations on video metadata.
|
|
43
|
-
comment moderation, all accesible from the
|
|
40
|
+
I built this because I needed to bulk update video titles for a YouTube channel I manage with 300+
|
|
41
|
+
videos. YouTube Studio does not support bulk search-replace operations, which made it a tedious
|
|
42
|
+
manual process. This tool uses the YouTube Data API to perform bulk operations on video metadata.
|
|
43
|
+
Furthermore, it provides features for analytics and comment moderation, all accesible from the
|
|
44
|
+
command line.
|
|
44
45
|
|
|
45
46
|
## Installation
|
|
46
47
|
|
|
@@ -53,19 +54,19 @@ uv tool install ytstudio-cli
|
|
|
53
54
|
## Setup
|
|
54
55
|
|
|
55
56
|
1. Create a [Google Cloud project](https://console.cloud.google.com/)
|
|
56
|
-
|
|
57
|
-
|
|
57
|
+
1. Enable **YouTube Data API v3** and **YouTube Analytics API**
|
|
58
|
+
1. Configure OAuth consent screen:
|
|
58
59
|
- Go to **APIs & Services** → **OAuth consent screen**
|
|
59
60
|
- Select **External** and create
|
|
60
61
|
- Fill in app name and your email
|
|
61
62
|
- Skip scopes, then add yourself as a test user
|
|
62
63
|
- Leave the app in "Testing" mode (no verification needed)
|
|
63
|
-
|
|
64
|
+
1. Create OAuth credentials:
|
|
64
65
|
- Go to **APIs & Services** → **Credentials**
|
|
65
|
-
- Click **Create Credentials** → **OAuth client ID**
|
|
66
|
+
- Click **Create Credentials** → **OAuth client ID**how
|
|
66
67
|
- Select **Desktop app** as application type
|
|
67
68
|
- Download the JSON file
|
|
68
|
-
|
|
69
|
+
1. Configure ytstudio:
|
|
69
70
|
|
|
70
71
|
```bash
|
|
71
72
|
ytstudio init --client-secrets path/to/client_secret_<id>.json
|
|
@@ -74,7 +75,21 @@ ytstudio login
|
|
|
74
75
|
|
|
75
76
|
Credentials stored in `~/.config/ytstudio/`.
|
|
76
77
|
|
|
78
|
+
## API quota
|
|
79
|
+
|
|
80
|
+
The YouTube Data API enforces a default quota of 10_000 units per project per day. Most read
|
|
81
|
+
operations (listing videos, comments, channel info) cost 1 unit, while write operations like
|
|
82
|
+
updating video metadata or moderating comments cost 50 units each. Bulk updates can consume quota
|
|
83
|
+
quickly. When exceeded, the API returns a 403 error; quota resets at midnight Pacific Time.
|
|
84
|
+
|
|
85
|
+
You can request a quota increase via **IAM & Admin** → **Quotas** in the
|
|
86
|
+
[Google Cloud Console](https://console.cloud.google.com/). See the
|
|
87
|
+
[official quota documentation](https://developers.google.com/youtube/v3/getting-started#quota) for
|
|
88
|
+
full details.
|
|
89
|
+
|
|
77
90
|
## Disclaimer
|
|
78
91
|
|
|
79
|
-
This project is not affiliated with or endorsed by Google. YouTube and YouTube Studio are trademarks
|
|
80
|
-
All channel data is accessed exclusively through the official
|
|
92
|
+
This project is not affiliated with or endorsed by Google. YouTube and YouTube Studio are trademarks
|
|
93
|
+
of Google. All channel data is accessed exclusively through the official
|
|
94
|
+
[YouTube Data API](https://developers.google.com/youtube/v3) and
|
|
95
|
+
[YouTube Analytics API](https://developers.google.com/youtube/analytics).
|
|
@@ -11,10 +11,11 @@ Manage and analyze your YouTube channel from the terminal. Ideal for automation
|
|
|
11
11
|
|
|
12
12
|
## Motivation
|
|
13
13
|
|
|
14
|
-
I built this because I needed to bulk update video titles for a YouTube channel I manage with 300+
|
|
15
|
-
Studio does not support bulk search-replace operations, which made it a tedious
|
|
16
|
-
YouTube Data API to perform bulk operations on video metadata.
|
|
17
|
-
comment moderation, all accesible from the
|
|
14
|
+
I built this because I needed to bulk update video titles for a YouTube channel I manage with 300+
|
|
15
|
+
videos. YouTube Studio does not support bulk search-replace operations, which made it a tedious
|
|
16
|
+
manual process. This tool uses the YouTube Data API to perform bulk operations on video metadata.
|
|
17
|
+
Furthermore, it provides features for analytics and comment moderation, all accesible from the
|
|
18
|
+
command line.
|
|
18
19
|
|
|
19
20
|
## Installation
|
|
20
21
|
|
|
@@ -27,19 +28,19 @@ uv tool install ytstudio-cli
|
|
|
27
28
|
## Setup
|
|
28
29
|
|
|
29
30
|
1. Create a [Google Cloud project](https://console.cloud.google.com/)
|
|
30
|
-
|
|
31
|
-
|
|
31
|
+
1. Enable **YouTube Data API v3** and **YouTube Analytics API**
|
|
32
|
+
1. Configure OAuth consent screen:
|
|
32
33
|
- Go to **APIs & Services** → **OAuth consent screen**
|
|
33
34
|
- Select **External** and create
|
|
34
35
|
- Fill in app name and your email
|
|
35
36
|
- Skip scopes, then add yourself as a test user
|
|
36
37
|
- Leave the app in "Testing" mode (no verification needed)
|
|
37
|
-
|
|
38
|
+
1. Create OAuth credentials:
|
|
38
39
|
- Go to **APIs & Services** → **Credentials**
|
|
39
|
-
- Click **Create Credentials** → **OAuth client ID**
|
|
40
|
+
- Click **Create Credentials** → **OAuth client ID**how
|
|
40
41
|
- Select **Desktop app** as application type
|
|
41
42
|
- Download the JSON file
|
|
42
|
-
|
|
43
|
+
1. Configure ytstudio:
|
|
43
44
|
|
|
44
45
|
```bash
|
|
45
46
|
ytstudio init --client-secrets path/to/client_secret_<id>.json
|
|
@@ -48,7 +49,21 @@ ytstudio login
|
|
|
48
49
|
|
|
49
50
|
Credentials stored in `~/.config/ytstudio/`.
|
|
50
51
|
|
|
52
|
+
## API quota
|
|
53
|
+
|
|
54
|
+
The YouTube Data API enforces a default quota of 10_000 units per project per day. Most read
|
|
55
|
+
operations (listing videos, comments, channel info) cost 1 unit, while write operations like
|
|
56
|
+
updating video metadata or moderating comments cost 50 units each. Bulk updates can consume quota
|
|
57
|
+
quickly. When exceeded, the API returns a 403 error; quota resets at midnight Pacific Time.
|
|
58
|
+
|
|
59
|
+
You can request a quota increase via **IAM & Admin** → **Quotas** in the
|
|
60
|
+
[Google Cloud Console](https://console.cloud.google.com/). See the
|
|
61
|
+
[official quota documentation](https://developers.google.com/youtube/v3/getting-started#quota) for
|
|
62
|
+
full details.
|
|
63
|
+
|
|
51
64
|
## Disclaimer
|
|
52
65
|
|
|
53
|
-
This project is not affiliated with or endorsed by Google. YouTube and YouTube Studio are trademarks
|
|
54
|
-
All channel data is accessed exclusively through the official
|
|
66
|
+
This project is not affiliated with or endorsed by Google. YouTube and YouTube Studio are trademarks
|
|
67
|
+
of Google. All channel data is accessed exclusively through the official
|
|
68
|
+
[YouTube Data API](https://developers.google.com/youtube/v3) and
|
|
69
|
+
[YouTube Analytics API](https://developers.google.com/youtube/analytics).
|
|
@@ -367,27 +367,26 @@ def search_replace(
|
|
|
367
367
|
):
|
|
368
368
|
"""Bulk update videos using search and replace"""
|
|
369
369
|
service = get_data_service()
|
|
370
|
-
uploads_playlist_id = get_channel_uploads_playlist(service)
|
|
371
370
|
|
|
372
371
|
changes = []
|
|
373
372
|
page_token = None
|
|
374
373
|
|
|
375
|
-
while
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
374
|
+
while True:
|
|
375
|
+
search_response = api(
|
|
376
|
+
service.search().list(
|
|
377
|
+
part="id",
|
|
378
|
+
forMine=True,
|
|
379
|
+
type="video",
|
|
381
380
|
maxResults=50,
|
|
382
381
|
pageToken=page_token,
|
|
383
382
|
)
|
|
384
383
|
)
|
|
385
384
|
|
|
386
|
-
items =
|
|
385
|
+
items = search_response.get("items", [])
|
|
387
386
|
if not items:
|
|
388
387
|
break
|
|
389
388
|
|
|
390
|
-
video_ids = [item["
|
|
389
|
+
video_ids = [item["id"]["videoId"] for item in items]
|
|
391
390
|
|
|
392
391
|
videos_response = api(
|
|
393
392
|
service.videos().list(
|
|
@@ -397,9 +396,6 @@ def search_replace(
|
|
|
397
396
|
)
|
|
398
397
|
|
|
399
398
|
for video in videos_response.get("items", []):
|
|
400
|
-
if len(changes) >= limit:
|
|
401
|
-
break
|
|
402
|
-
|
|
403
399
|
old_value = video["snippet"].get(field, "")
|
|
404
400
|
if regex:
|
|
405
401
|
new_value = re.sub(search, replace, old_value)
|
|
@@ -416,10 +412,12 @@ def search_replace(
|
|
|
416
412
|
}
|
|
417
413
|
)
|
|
418
414
|
|
|
419
|
-
page_token =
|
|
415
|
+
page_token = search_response.get("nextPageToken")
|
|
420
416
|
if not page_token:
|
|
421
417
|
break
|
|
422
418
|
|
|
419
|
+
changes = changes[:limit]
|
|
420
|
+
|
|
423
421
|
if not changes:
|
|
424
422
|
console.print("[yellow]No matches found[/yellow]")
|
|
425
423
|
return
|
|
@@ -127,6 +127,12 @@ def create_mock_service():
|
|
|
127
127
|
}
|
|
128
128
|
service.commentThreads.return_value.list.return_value = comments_list
|
|
129
129
|
|
|
130
|
+
search_list = MagicMock()
|
|
131
|
+
search_list.execute.return_value = {
|
|
132
|
+
"items": [{"id": {"videoId": MOCK_VIDEO["id"]}}],
|
|
133
|
+
}
|
|
134
|
+
service.search.return_value.list.return_value = search_list
|
|
135
|
+
|
|
130
136
|
return service
|
|
131
137
|
|
|
132
138
|
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
from unittest.mock import MagicMock, patch
|
|
2
|
+
|
|
3
|
+
import typer
|
|
4
|
+
from typer.testing import CliRunner
|
|
5
|
+
|
|
6
|
+
from ytstudio.main import app
|
|
7
|
+
|
|
8
|
+
runner = CliRunner()
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def make_search_video(video_id, title, description=""):
|
|
12
|
+
return {
|
|
13
|
+
"id": video_id,
|
|
14
|
+
"snippet": {
|
|
15
|
+
"title": title,
|
|
16
|
+
"description": description,
|
|
17
|
+
"publishedAt": "2020-01-01T00:00:00Z",
|
|
18
|
+
"tags": [],
|
|
19
|
+
"categoryId": "22",
|
|
20
|
+
},
|
|
21
|
+
"statistics": {"viewCount": "0", "likeCount": "0", "commentCount": "0"},
|
|
22
|
+
"contentDetails": {"duration": "PT1M"},
|
|
23
|
+
"status": {"privacyStatus": "public"},
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def setup_search_mock(mock_service, videos):
|
|
28
|
+
"""Configure the search and videos.list mocks for search-replace tests"""
|
|
29
|
+
search_list = MagicMock()
|
|
30
|
+
search_list.execute.return_value = {
|
|
31
|
+
"items": [{"id": {"videoId": v["id"]}} for v in videos],
|
|
32
|
+
}
|
|
33
|
+
mock_service.search.return_value.list.return_value = search_list
|
|
34
|
+
|
|
35
|
+
videos_list = MagicMock()
|
|
36
|
+
videos_list.execute.return_value = {"items": videos}
|
|
37
|
+
mock_service.videos.return_value.list.return_value = videos_list
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class TestVideosCommands:
|
|
41
|
+
def test_list(self, mock_auth):
|
|
42
|
+
result = runner.invoke(app, ["videos", "list"])
|
|
43
|
+
assert result.exit_code == 0
|
|
44
|
+
assert "Test Video Title" in result.stdout
|
|
45
|
+
|
|
46
|
+
def test_get(self, mock_auth):
|
|
47
|
+
result = runner.invoke(app, ["videos", "show", "test_video_123"])
|
|
48
|
+
assert result.exit_code == 0
|
|
49
|
+
assert "Test Video Title" in result.stdout
|
|
50
|
+
|
|
51
|
+
def test_get_not_found(self, mock_auth):
|
|
52
|
+
mock_auth.videos.return_value.list.return_value.execute.return_value = {"items": []}
|
|
53
|
+
result = runner.invoke(app, ["videos", "show", "nonexistent"])
|
|
54
|
+
assert result.exit_code == 1
|
|
55
|
+
|
|
56
|
+
def test_update_preview(self, mock_auth):
|
|
57
|
+
result = runner.invoke(app, ["videos", "update", "test_video_123", "--title", "New Title"])
|
|
58
|
+
assert result.exit_code == 0
|
|
59
|
+
assert "Preview" in result.stdout
|
|
60
|
+
mock_auth.videos.return_value.update.assert_not_called()
|
|
61
|
+
|
|
62
|
+
def test_update_no_changes(self, mock_auth):
|
|
63
|
+
result = runner.invoke(app, ["videos", "update", "test_video_123"])
|
|
64
|
+
assert result.exit_code == 1
|
|
65
|
+
|
|
66
|
+
def test_not_authenticated(self):
|
|
67
|
+
with patch(
|
|
68
|
+
"ytstudio.commands.videos.get_data_service",
|
|
69
|
+
side_effect=typer.Exit(1),
|
|
70
|
+
):
|
|
71
|
+
result = runner.invoke(app, ["videos", "list"])
|
|
72
|
+
assert result.exit_code == 1
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
class TestSearchReplace:
|
|
76
|
+
def test_dry_run_shows_preview(self, mock_auth):
|
|
77
|
+
videos = [make_search_video("vid1", "OLDNAME Episode 1")]
|
|
78
|
+
setup_search_mock(mock_auth, videos)
|
|
79
|
+
|
|
80
|
+
result = runner.invoke(
|
|
81
|
+
app,
|
|
82
|
+
[
|
|
83
|
+
"videos",
|
|
84
|
+
"search-replace",
|
|
85
|
+
"-s",
|
|
86
|
+
"OLDNAME",
|
|
87
|
+
"-r",
|
|
88
|
+
"NewName",
|
|
89
|
+
"-f",
|
|
90
|
+
"title",
|
|
91
|
+
],
|
|
92
|
+
)
|
|
93
|
+
assert result.exit_code == 0
|
|
94
|
+
assert "NewName Episode 1" in result.stdout
|
|
95
|
+
assert "Pending" in result.stdout
|
|
96
|
+
assert "--execute" in result.stdout
|
|
97
|
+
mock_auth.videos.return_value.update.assert_not_called()
|
|
98
|
+
|
|
99
|
+
def test_execute_applies_changes(self, mock_auth):
|
|
100
|
+
videos = [make_search_video("vid1", "OLDNAME Episode 1")]
|
|
101
|
+
setup_search_mock(mock_auth, videos)
|
|
102
|
+
|
|
103
|
+
result = runner.invoke(
|
|
104
|
+
app,
|
|
105
|
+
[
|
|
106
|
+
"videos",
|
|
107
|
+
"search-replace",
|
|
108
|
+
"-s",
|
|
109
|
+
"OLDNAME",
|
|
110
|
+
"-r",
|
|
111
|
+
"NewName",
|
|
112
|
+
"-f",
|
|
113
|
+
"title",
|
|
114
|
+
"--execute",
|
|
115
|
+
],
|
|
116
|
+
)
|
|
117
|
+
assert result.exit_code == 0
|
|
118
|
+
assert "1 updated" in result.stdout
|
|
119
|
+
mock_auth.videos.return_value.update.assert_called_once()
|
|
120
|
+
|
|
121
|
+
def test_no_matches(self, mock_auth):
|
|
122
|
+
videos = [make_search_video("vid1", "Some Other Title")]
|
|
123
|
+
setup_search_mock(mock_auth, videos)
|
|
124
|
+
|
|
125
|
+
result = runner.invoke(
|
|
126
|
+
app,
|
|
127
|
+
[
|
|
128
|
+
"videos",
|
|
129
|
+
"search-replace",
|
|
130
|
+
"-s",
|
|
131
|
+
"OLDNAME",
|
|
132
|
+
"-r",
|
|
133
|
+
"NewName",
|
|
134
|
+
"-f",
|
|
135
|
+
"title",
|
|
136
|
+
],
|
|
137
|
+
)
|
|
138
|
+
assert result.exit_code == 0
|
|
139
|
+
assert "No matches found" in result.stdout
|
|
140
|
+
|
|
141
|
+
def test_regex_replace(self, mock_auth):
|
|
142
|
+
videos = [make_search_video("vid1", "Episode 01 - Test")]
|
|
143
|
+
setup_search_mock(mock_auth, videos)
|
|
144
|
+
|
|
145
|
+
result = runner.invoke(
|
|
146
|
+
app,
|
|
147
|
+
[
|
|
148
|
+
"videos",
|
|
149
|
+
"search-replace",
|
|
150
|
+
"-s",
|
|
151
|
+
r"Episode (\d+)",
|
|
152
|
+
"-r",
|
|
153
|
+
r"Ep.\1",
|
|
154
|
+
"-f",
|
|
155
|
+
"title",
|
|
156
|
+
"--regex",
|
|
157
|
+
],
|
|
158
|
+
)
|
|
159
|
+
assert result.exit_code == 0
|
|
160
|
+
assert "Ep.01" in result.stdout
|
|
161
|
+
|
|
162
|
+
def test_limit_caps_matches(self, mock_auth):
|
|
163
|
+
videos = [make_search_video(f"vid{i}", f"OLDNAME Episode {i}") for i in range(5)]
|
|
164
|
+
setup_search_mock(mock_auth, videos)
|
|
165
|
+
|
|
166
|
+
result = runner.invoke(
|
|
167
|
+
app,
|
|
168
|
+
[
|
|
169
|
+
"videos",
|
|
170
|
+
"search-replace",
|
|
171
|
+
"-s",
|
|
172
|
+
"OLDNAME",
|
|
173
|
+
"-r",
|
|
174
|
+
"NewName",
|
|
175
|
+
"-f",
|
|
176
|
+
"title",
|
|
177
|
+
"-n",
|
|
178
|
+
"2",
|
|
179
|
+
],
|
|
180
|
+
)
|
|
181
|
+
assert result.exit_code == 0
|
|
182
|
+
assert "2 changes" in result.stdout
|
|
183
|
+
|
|
184
|
+
def test_description_field(self, mock_auth):
|
|
185
|
+
videos = [make_search_video("vid1", "Title", description="Visit OLDSITE.com")]
|
|
186
|
+
setup_search_mock(mock_auth, videos)
|
|
187
|
+
|
|
188
|
+
result = runner.invoke(
|
|
189
|
+
app,
|
|
190
|
+
[
|
|
191
|
+
"videos",
|
|
192
|
+
"search-replace",
|
|
193
|
+
"-s",
|
|
194
|
+
"OLDSITE.com",
|
|
195
|
+
"-r",
|
|
196
|
+
"newsite.com",
|
|
197
|
+
"-f",
|
|
198
|
+
"description",
|
|
199
|
+
],
|
|
200
|
+
)
|
|
201
|
+
assert result.exit_code == 0
|
|
202
|
+
assert "newsite.com" in result.stdout
|
|
203
|
+
|
|
204
|
+
def test_pagination_reaches_all_videos(self, mock_auth):
|
|
205
|
+
page1_videos = [make_search_video("vid1", "No Match Here")]
|
|
206
|
+
page2_videos = [make_search_video("vid2", "OLDNAME Old Video")]
|
|
207
|
+
|
|
208
|
+
call_count = 0
|
|
209
|
+
|
|
210
|
+
def search_side_effect():
|
|
211
|
+
nonlocal call_count
|
|
212
|
+
call_count += 1
|
|
213
|
+
if call_count == 1:
|
|
214
|
+
return {
|
|
215
|
+
"items": [{"id": {"videoId": "vid1"}}],
|
|
216
|
+
"nextPageToken": "page2token",
|
|
217
|
+
}
|
|
218
|
+
return {
|
|
219
|
+
"items": [{"id": {"videoId": "vid2"}}],
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
mock_auth.search.return_value.list.return_value.execute.side_effect = search_side_effect
|
|
223
|
+
|
|
224
|
+
videos_call_count = 0
|
|
225
|
+
|
|
226
|
+
def videos_side_effect():
|
|
227
|
+
nonlocal videos_call_count
|
|
228
|
+
videos_call_count += 1
|
|
229
|
+
if videos_call_count == 1:
|
|
230
|
+
return {"items": page1_videos}
|
|
231
|
+
return {"items": page2_videos}
|
|
232
|
+
|
|
233
|
+
mock_auth.videos.return_value.list.return_value.execute.side_effect = videos_side_effect
|
|
234
|
+
|
|
235
|
+
result = runner.invoke(
|
|
236
|
+
app,
|
|
237
|
+
[
|
|
238
|
+
"videos",
|
|
239
|
+
"search-replace",
|
|
240
|
+
"-s",
|
|
241
|
+
"OLDNAME",
|
|
242
|
+
"-r",
|
|
243
|
+
"NewName",
|
|
244
|
+
"-f",
|
|
245
|
+
"title",
|
|
246
|
+
],
|
|
247
|
+
)
|
|
248
|
+
assert result.exit_code == 0
|
|
249
|
+
assert "NewName Old Video" in result.stdout
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
from unittest.mock import patch
|
|
2
|
-
|
|
3
|
-
import typer
|
|
4
|
-
from typer.testing import CliRunner
|
|
5
|
-
|
|
6
|
-
from ytstudio.main import app
|
|
7
|
-
|
|
8
|
-
runner = CliRunner()
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
class TestVideosCommands:
|
|
12
|
-
def test_list(self, mock_auth):
|
|
13
|
-
result = runner.invoke(app, ["videos", "list"])
|
|
14
|
-
assert result.exit_code == 0
|
|
15
|
-
assert "Test Video Title" in result.stdout
|
|
16
|
-
|
|
17
|
-
def test_get(self, mock_auth):
|
|
18
|
-
result = runner.invoke(app, ["videos", "show", "test_video_123"])
|
|
19
|
-
assert result.exit_code == 0
|
|
20
|
-
assert "Test Video Title" in result.stdout
|
|
21
|
-
|
|
22
|
-
def test_get_not_found(self, mock_auth):
|
|
23
|
-
mock_auth.videos.return_value.list.return_value.execute.return_value = {"items": []}
|
|
24
|
-
result = runner.invoke(app, ["videos", "show", "nonexistent"])
|
|
25
|
-
assert result.exit_code == 1
|
|
26
|
-
|
|
27
|
-
def test_update_preview(self, mock_auth):
|
|
28
|
-
result = runner.invoke(app, ["videos", "update", "test_video_123", "--title", "New Title"])
|
|
29
|
-
assert result.exit_code == 0
|
|
30
|
-
assert "Preview" in result.stdout
|
|
31
|
-
mock_auth.videos.return_value.update.assert_not_called()
|
|
32
|
-
|
|
33
|
-
def test_update_no_changes(self, mock_auth):
|
|
34
|
-
result = runner.invoke(app, ["videos", "update", "test_video_123"])
|
|
35
|
-
assert result.exit_code == 1
|
|
36
|
-
|
|
37
|
-
def test_not_authenticated(self):
|
|
38
|
-
with patch(
|
|
39
|
-
"ytstudio.commands.videos.get_data_service",
|
|
40
|
-
side_effect=typer.Exit(1),
|
|
41
|
-
):
|
|
42
|
-
result = runner.invoke(app, ["videos", "list"])
|
|
43
|
-
assert result.exit_code == 1
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|