vidnavigator 2.2.0__tar.gz → 2.3.0__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.
Files changed (32) hide show
  1. {vidnavigator-2.2.0/vidnavigator.egg-info → vidnavigator-2.3.0}/PKG-INFO +48 -2
  2. {vidnavigator-2.2.0 → vidnavigator-2.3.0}/README.md +47 -1
  3. {vidnavigator-2.2.0 → vidnavigator-2.3.0}/pyproject.toml +1 -1
  4. {vidnavigator-2.2.0 → vidnavigator-2.3.0}/tests/test_async_client.py +26 -0
  5. {vidnavigator-2.2.0 → vidnavigator-2.3.0}/tests/test_client_endpoints.py +101 -0
  6. {vidnavigator-2.2.0 → vidnavigator-2.3.0}/tests/test_integration.py +27 -0
  7. {vidnavigator-2.2.0 → vidnavigator-2.3.0}/vidnavigator/__init__.py +47 -47
  8. {vidnavigator-2.2.0 → vidnavigator-2.3.0}/vidnavigator/_core.py +38 -1
  9. {vidnavigator-2.2.0 → vidnavigator-2.3.0}/vidnavigator/async_client.py +28 -1
  10. {vidnavigator-2.2.0 → vidnavigator-2.3.0}/vidnavigator/client.py +54 -1
  11. {vidnavigator-2.2.0 → vidnavigator-2.3.0}/vidnavigator/models.py +89 -0
  12. {vidnavigator-2.2.0 → vidnavigator-2.3.0/vidnavigator.egg-info}/PKG-INFO +48 -2
  13. {vidnavigator-2.2.0 → vidnavigator-2.3.0}/LICENSE +0 -0
  14. {vidnavigator-2.2.0 → vidnavigator-2.3.0}/setup.cfg +0 -0
  15. {vidnavigator-2.2.0 → vidnavigator-2.3.0}/tests/test_async_integration.py +0 -0
  16. {vidnavigator-2.2.0 → vidnavigator-2.3.0}/tests/test_async_jobs.py +0 -0
  17. {vidnavigator-2.2.0 → vidnavigator-2.3.0}/tests/test_error_mapping.py +0 -0
  18. {vidnavigator-2.2.0 → vidnavigator-2.3.0}/tests/test_extract_endpoints.py +0 -0
  19. {vidnavigator-2.2.0 → vidnavigator-2.3.0}/tests/test_models_extract.py +0 -0
  20. {vidnavigator-2.2.0 → vidnavigator-2.3.0}/tests/test_platforms.py +0 -0
  21. {vidnavigator-2.2.0 → vidnavigator-2.3.0}/tests/test_tiktok_webhooks.py +0 -0
  22. {vidnavigator-2.2.0 → vidnavigator-2.3.0}/tests/test_version.py +0 -0
  23. {vidnavigator-2.2.0 → vidnavigator-2.3.0}/tests/test_webhook_delivery.py +0 -0
  24. {vidnavigator-2.2.0 → vidnavigator-2.3.0}/tests/test_webhooks.py +0 -0
  25. {vidnavigator-2.2.0 → vidnavigator-2.3.0}/vidnavigator/exceptions.py +0 -0
  26. {vidnavigator-2.2.0 → vidnavigator-2.3.0}/vidnavigator/jobs.py +0 -0
  27. {vidnavigator-2.2.0 → vidnavigator-2.3.0}/vidnavigator/operations.py +0 -0
  28. {vidnavigator-2.2.0 → vidnavigator-2.3.0}/vidnavigator/webhooks.py +0 -0
  29. {vidnavigator-2.2.0 → vidnavigator-2.3.0}/vidnavigator.egg-info/SOURCES.txt +0 -0
  30. {vidnavigator-2.2.0 → vidnavigator-2.3.0}/vidnavigator.egg-info/dependency_links.txt +0 -0
  31. {vidnavigator-2.2.0 → vidnavigator-2.3.0}/vidnavigator.egg-info/requires.txt +0 -0
  32. {vidnavigator-2.2.0 → vidnavigator-2.3.0}/vidnavigator.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: vidnavigator
3
- Version: 2.2.0
3
+ Version: 2.3.0
4
4
  Summary: Python SDK for the VidNavigator Developer API
5
5
  Author-email: Hatem <hatem.mezlini@vidnavigator.com>
6
6
  License: Apache License
@@ -247,7 +247,7 @@ The official Python client for the [VidNavigator Developer API](https://docs.vid
247
247
  - [Installation](#installation) · [Authentication](#authentication) · [Quick start](#quick-start) · [Which method should I use?](#which-method-should-i-use)
248
248
  - **Online videos:** [Transcripts](#transcripts) · [AI analysis](#ai-analysis) · [Structured extraction](#structured-extraction) · [Tweet claim analysis](#tweet-claim-analysis)
249
249
  - **Long-running work:** [Background jobs](#background-jobs) · [Recipes](#recipes) · [Async client](#async-client) · [Webhooks](#webhooks)
250
- - **TikTok:** [Profile scraping](#tiktok-profile-scraping) · [Keyword search](#tiktok-keyword-search) · [LIVE search](#tiktok-live-search)
250
+ - **TikTok:** [Profile scraping](#tiktok-profile-scraping) · [Keyword search](#tiktok-keyword-search) · [LIVE search](#tiktok-live-search) · [LIVE room](#tiktok-live-room)
251
251
  - **Your own files:** [Semantic search](#semantic-search) · [File uploads](#file-uploads) · [Namespaces](#namespaces)
252
252
  - **Reference:** [Per-call usage](#per-call-usage) · [Usage & billing](#usage--billing) · [Error handling](#error-handling) · [Configuration](#configuration) · [Upgrading from 1.x](#upgrading-from-1x)
253
253
 
@@ -361,6 +361,7 @@ print(resp.data) # {"mood": "upbeat"}
361
361
  | List a TikTok profile's videos | `scrape_tiktok_profile` | when the job finishes |
362
362
  | Search TikTok by keyword | `search_tiktok` | when the job finishes |
363
363
  | Find TikTok LIVE rooms broadcasting now, with their stream URLs | `search_tiktok_live` | when the job finishes |
364
+ | Check one TikTok LIVE room or streamer, with its latest comments | `get_tiktok_live_room` | immediately |
364
365
  | Find YouTube videos about a topic | `search_youtube` | immediately |
365
366
  | Work with your own audio/video files | `upload_file`, then `get_file`, `analyze_file`, `extract_file_data`, `search_files` | immediately |
366
367
  | Process **many** videos at once | the `submit_*` version of a job method | a job handle, right away |
@@ -1231,6 +1232,47 @@ Results keep TikTok's ranking. A keyword with no LIVE room in that country at th
1231
1232
 
1232
1233
  ---
1233
1234
 
1235
+ ## TikTok LIVE Room
1236
+
1237
+ `get_tiktok_live_room` returns one LIVE room right away (no job): by room id, by streamer, or by LIVE URL. Use it to check whether someone is live, to follow a room found by [LIVE search](#tiktok-live-search), or to read its latest comments.
1238
+
1239
+ ```python
1240
+ resp = client.get_tiktok_live_room(username="tiktok", include_comments=True)
1241
+ room = resp.data.room
1242
+
1243
+ print(room.status, room.title, room.stats.viewers, room.stats.new_followers)
1244
+ if room.is_live:
1245
+ for comment in resp.data.comments:
1246
+ print(comment.created_at, comment.author.unique_id, comment.text)
1247
+ else:
1248
+ print("ended at", room.ended_at)
1249
+ ```
1250
+
1251
+ | Parameter | Type | Description |
1252
+ |---|---|---|
1253
+ | `room_id` | `str` | A LIVE room id, e.g. the `id` of a LIVE search room |
1254
+ | `username` | `str` | The streamer, with or without `@`: their current LIVE, or their last one when they are offline |
1255
+ | `url` | `str` | `https://www.tiktok.com/@username/live`, the profile URL, or a room's `share_url` |
1256
+ | `include_comments` | `bool` | Also return the latest comments, the pinned comment, the intro and the top viewers. Default `False`. |
1257
+ | `comments_limit` | `int` | At most this many comments, 1-50 (default 50) |
1258
+ | `include_stream_urls` | `bool` | Stream URLs are returned by default; pass `False` to leave them out |
1259
+ | `include_usage` | `bool` | Add the `usage` block |
1260
+
1261
+ Pass exactly one of `room_id`, `username` or `url`. The room (`TikTokLiveRoomDetail`) has the fields of a LIVE search room, plus:
1262
+
1263
+ - `status` (`"live"` or `"ended"`, also `room.is_live`) and `ended_at`
1264
+ - `stats.viewers` (watching now), `stats.total_viewers` (since the start), `stats.new_followers` (gained during the LIVE)
1265
+ - `author.bio`, `author.following`
1266
+ - `share_url`, `chat_enabled`, `subscribers_only`, `age_restricted`, `products` (items on sale)
1267
+
1268
+ With `include_comments=True`, `resp.data` also has `comments` (newest first; TikTok keeps only about the last 50 of a LIVE), `pinned_comment`, `intro` and `top_viewers`. A room that has ended has no comments.
1269
+
1270
+ A room's likes, comment count and share count are not available here: [LIVE search](#tiktok-live-search) returns them. A room or account that does not exist raises `NotFoundError` (`error_code == "live_not_found"`). The call usually takes a few seconds; it may wait up to two minutes, whatever the client's `timeout`.
1271
+
1272
+ Billing: 1 `residential_request` per room, 2 with `include_comments` (1 when the room has ended). Not billed when the room is not found.
1273
+
1274
+ ---
1275
+
1234
1276
  ## Semantic Search
1235
1277
 
1236
1278
  ### Search YouTube
@@ -1493,6 +1535,10 @@ One client can be reused for any number of calls. If you use threads, create one
1493
1535
 
1494
1536
  ---
1495
1537
 
1538
+ ## What's new in 2.3.0
1539
+
1540
+ - **TikTok LIVE room:** [`get_tiktok_live_room`](#tiktok-live-room) returns one room right away, by room id, streamer or LIVE URL: live or ended, viewers, new followers, the streamer's bio, and with `include_comments=True` its latest comments, pinned comment, intro and top viewers.
1541
+
1496
1542
  ## What's new in 2.2.0
1497
1543
 
1498
1544
  - **TikTok LIVE search:** `search_tiktok_live` / `client.tiktok_live_search`, with typed rooms and their stream URLs.
@@ -13,7 +13,7 @@ The official Python client for the [VidNavigator Developer API](https://docs.vid
13
13
  - [Installation](#installation) · [Authentication](#authentication) · [Quick start](#quick-start) · [Which method should I use?](#which-method-should-i-use)
14
14
  - **Online videos:** [Transcripts](#transcripts) · [AI analysis](#ai-analysis) · [Structured extraction](#structured-extraction) · [Tweet claim analysis](#tweet-claim-analysis)
15
15
  - **Long-running work:** [Background jobs](#background-jobs) · [Recipes](#recipes) · [Async client](#async-client) · [Webhooks](#webhooks)
16
- - **TikTok:** [Profile scraping](#tiktok-profile-scraping) · [Keyword search](#tiktok-keyword-search) · [LIVE search](#tiktok-live-search)
16
+ - **TikTok:** [Profile scraping](#tiktok-profile-scraping) · [Keyword search](#tiktok-keyword-search) · [LIVE search](#tiktok-live-search) · [LIVE room](#tiktok-live-room)
17
17
  - **Your own files:** [Semantic search](#semantic-search) · [File uploads](#file-uploads) · [Namespaces](#namespaces)
18
18
  - **Reference:** [Per-call usage](#per-call-usage) · [Usage & billing](#usage--billing) · [Error handling](#error-handling) · [Configuration](#configuration) · [Upgrading from 1.x](#upgrading-from-1x)
19
19
 
@@ -127,6 +127,7 @@ print(resp.data) # {"mood": "upbeat"}
127
127
  | List a TikTok profile's videos | `scrape_tiktok_profile` | when the job finishes |
128
128
  | Search TikTok by keyword | `search_tiktok` | when the job finishes |
129
129
  | Find TikTok LIVE rooms broadcasting now, with their stream URLs | `search_tiktok_live` | when the job finishes |
130
+ | Check one TikTok LIVE room or streamer, with its latest comments | `get_tiktok_live_room` | immediately |
130
131
  | Find YouTube videos about a topic | `search_youtube` | immediately |
131
132
  | Work with your own audio/video files | `upload_file`, then `get_file`, `analyze_file`, `extract_file_data`, `search_files` | immediately |
132
133
  | Process **many** videos at once | the `submit_*` version of a job method | a job handle, right away |
@@ -997,6 +998,47 @@ Results keep TikTok's ranking. A keyword with no LIVE room in that country at th
997
998
 
998
999
  ---
999
1000
 
1001
+ ## TikTok LIVE Room
1002
+
1003
+ `get_tiktok_live_room` returns one LIVE room right away (no job): by room id, by streamer, or by LIVE URL. Use it to check whether someone is live, to follow a room found by [LIVE search](#tiktok-live-search), or to read its latest comments.
1004
+
1005
+ ```python
1006
+ resp = client.get_tiktok_live_room(username="tiktok", include_comments=True)
1007
+ room = resp.data.room
1008
+
1009
+ print(room.status, room.title, room.stats.viewers, room.stats.new_followers)
1010
+ if room.is_live:
1011
+ for comment in resp.data.comments:
1012
+ print(comment.created_at, comment.author.unique_id, comment.text)
1013
+ else:
1014
+ print("ended at", room.ended_at)
1015
+ ```
1016
+
1017
+ | Parameter | Type | Description |
1018
+ |---|---|---|
1019
+ | `room_id` | `str` | A LIVE room id, e.g. the `id` of a LIVE search room |
1020
+ | `username` | `str` | The streamer, with or without `@`: their current LIVE, or their last one when they are offline |
1021
+ | `url` | `str` | `https://www.tiktok.com/@username/live`, the profile URL, or a room's `share_url` |
1022
+ | `include_comments` | `bool` | Also return the latest comments, the pinned comment, the intro and the top viewers. Default `False`. |
1023
+ | `comments_limit` | `int` | At most this many comments, 1-50 (default 50) |
1024
+ | `include_stream_urls` | `bool` | Stream URLs are returned by default; pass `False` to leave them out |
1025
+ | `include_usage` | `bool` | Add the `usage` block |
1026
+
1027
+ Pass exactly one of `room_id`, `username` or `url`. The room (`TikTokLiveRoomDetail`) has the fields of a LIVE search room, plus:
1028
+
1029
+ - `status` (`"live"` or `"ended"`, also `room.is_live`) and `ended_at`
1030
+ - `stats.viewers` (watching now), `stats.total_viewers` (since the start), `stats.new_followers` (gained during the LIVE)
1031
+ - `author.bio`, `author.following`
1032
+ - `share_url`, `chat_enabled`, `subscribers_only`, `age_restricted`, `products` (items on sale)
1033
+
1034
+ With `include_comments=True`, `resp.data` also has `comments` (newest first; TikTok keeps only about the last 50 of a LIVE), `pinned_comment`, `intro` and `top_viewers`. A room that has ended has no comments.
1035
+
1036
+ A room's likes, comment count and share count are not available here: [LIVE search](#tiktok-live-search) returns them. A room or account that does not exist raises `NotFoundError` (`error_code == "live_not_found"`). The call usually takes a few seconds; it may wait up to two minutes, whatever the client's `timeout`.
1037
+
1038
+ Billing: 1 `residential_request` per room, 2 with `include_comments` (1 when the room has ended). Not billed when the room is not found.
1039
+
1040
+ ---
1041
+
1000
1042
  ## Semantic Search
1001
1043
 
1002
1044
  ### Search YouTube
@@ -1259,6 +1301,10 @@ One client can be reused for any number of calls. If you use threads, create one
1259
1301
 
1260
1302
  ---
1261
1303
 
1304
+ ## What's new in 2.3.0
1305
+
1306
+ - **TikTok LIVE room:** [`get_tiktok_live_room`](#tiktok-live-room) returns one room right away, by room id, streamer or LIVE URL: live or ended, viewers, new followers, the streamer's bio, and with `include_comments=True` its latest comments, pinned comment, intro and top viewers.
1307
+
1262
1308
  ## What's new in 2.2.0
1263
1309
 
1264
1310
  - **TikTok LIVE search:** `search_tiktok_live` / `client.tiktok_live_search`, with typed rooms and their stream URLs.
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "vidnavigator"
7
- version = "2.2.0"
7
+ version = "2.3.0"
8
8
  authors = [
9
9
  { name="Hatem", email="hatem.mezlini@vidnavigator.com" },
10
10
  ]
@@ -625,3 +625,29 @@ def test_polling_does_not_block_the_event_loop():
625
625
  # The ticker kept running after the first poll, while the job slept 50 ms before the second.
626
626
  assert polls_seen_by_ticker == [1, 1, 1]
627
627
  assert len(api.calls("GET")) == 2
628
+
629
+
630
+ def test_get_tiktok_live_room_async():
631
+ from vidnavigator.models import TikTokLiveRoomResponse
632
+
633
+ room = {"id": "7705498471838665494", "status": "live", "stats": {"viewers": "12", "new_followers": 1},
634
+ "author": {"unique_id": "streamer", "following": 3}}
635
+ api = (Api().on("POST", "/v1/tiktok/live/room", {"status": "success", "data": {"room": room}})
636
+ .on("POST", "/v1/tiktok/live/room", (404, {"status": "error", "error": "live_not_found",
637
+ "message": "No TikTok LIVE room found."})))
638
+
639
+ async def go():
640
+ async with make_client(api) as client:
641
+ found = await client.get_tiktok_live_room(url="https://www.tiktok.com/@streamer/live")
642
+ with pytest.raises(NotFoundError) as exc_info:
643
+ await client.get_tiktok_live_room(room_id="123", include_comments=True)
644
+ return found, exc_info.value
645
+
646
+ found, error = run(go())
647
+ assert isinstance(found, TikTokLiveRoomResponse) and found.data.room.is_live
648
+ assert found.data.room.stats.viewers == 12 and found.data.room.author.following == 3
649
+ assert error.error_code == "live_not_found"
650
+ assert [body(r) for r in api.calls("POST")] == [
651
+ {"url": "https://www.tiktok.com/@streamer/live"},
652
+ {"room_id": "123", "include_comments": True},
653
+ ]
@@ -697,3 +697,104 @@ def test_health_check(client):
697
697
  assert isinstance(resp, HealthResponse)
698
698
  assert resp.status == "success"
699
699
  assert resp.endpoints[0].path == "/health"
700
+
701
+
702
+ # ---------------------------------------------------------------------------
703
+ # TikTok LIVE room (synchronous)
704
+ # ---------------------------------------------------------------------------
705
+
706
+ LIVE_ROOM_RAW = {
707
+ "status": "success",
708
+ "data": {
709
+ "room": {
710
+ "id": "7705498471838665494",
711
+ "title": "Night stream #fr",
712
+ "url": "https://www.tiktok.com/@streamer/live",
713
+ "status": "live",
714
+ "ended_at": None,
715
+ "share_url": "https://m.tiktok.com/share/live/7705498471838665494",
716
+ "started_at": "2026-11-07T16:00:00Z",
717
+ "author": {"unique_id": "streamer", "followers": "18867", "bio": "Live every night", "following": "9011"},
718
+ "stats": {"viewers": 936, "total_viewers": "4005", "new_followers": 12},
719
+ "hashtags": ["fr"],
720
+ "age_restricted": False,
721
+ "subscribers_only": False,
722
+ "chat_enabled": True,
723
+ "products": 2,
724
+ },
725
+ "comments": [{
726
+ "id": "3", "text": "hello", "language": "fr", "created_at": "2026-11-07T16:46:42.500Z",
727
+ "author": {"unique_id": "bob", "followers": 5},
728
+ "author_is_follower": True, "author_is_moderator": False, "author_is_subscriber": False,
729
+ }],
730
+ "pinned_comment": None,
731
+ "intro": "Welcome",
732
+ "top_viewers": [{"rank": 1, "score": 300, "user": {"unique_id": "bob"}}],
733
+ },
734
+ "usage": {"charges": [{"service_type": "residential_request", "quantity": 2.0, "credits": 0.01}],
735
+ "total_credits": 0.01},
736
+ }
737
+
738
+
739
+ def test_get_tiktok_live_room_with_comments(client):
740
+ from vidnavigator.models import TikTokLiveRoomResponse
741
+
742
+ with patch.object(client, "_request", return_value=LIVE_ROOM_RAW) as req:
743
+ resp = client.get_tiktok_live_room(room_id=7705498471838665494, include_comments=True,
744
+ comments_limit=10, include_usage=True)
745
+ assert isinstance(resp, TikTokLiveRoomResponse)
746
+ room = resp.data.room
747
+ assert room.is_live and room.ended_at is None
748
+ assert (room.stats.viewers, room.stats.total_viewers, room.stats.new_followers) == (936, 4005, 12)
749
+ assert (room.author.bio, room.author.following, room.author.followers) == ("Live every night", 9011, 18867)
750
+ assert (room.chat_enabled, room.subscribers_only, room.products) == (True, False, 2)
751
+ comment = resp.data.comments[0]
752
+ assert comment.created_at == datetime(2026, 11, 7, 16, 46, 42, 500000, tzinfo=timezone.utc)
753
+ assert comment.author.unique_id == "bob" and comment.author_is_follower is True
754
+ assert resp.data.top_viewers[0].user.unique_id == "bob"
755
+ assert resp.usage.charge_for("residential_request").quantity == 2.0
756
+ args, kw = req.call_args
757
+ assert args == ("POST", "/tiktok/live/room")
758
+ # The room id goes as a string: it has more digits than a JavaScript number holds.
759
+ assert kw["json_body"] == {"room_id": "7705498471838665494", "include_comments": True,
760
+ "comments_limit": 10, "include_usage": True}
761
+ assert kw["min_timeout"] == 120.0
762
+
763
+
764
+ def test_get_tiktok_live_room_by_username_without_comments(client):
765
+ raw = {"status": "success", "data": {"room": {**LIVE_ROOM_RAW["data"]["room"], "status": "ended",
766
+ "ended_at": "2026-11-07T18:51:31Z"}}}
767
+ with patch.object(client, "_request", return_value=raw) as req:
768
+ resp = client.get_tiktok_live_room(username="@streamer", include_stream_urls=False)
769
+ assert not resp.data.room.is_live
770
+ assert resp.data.room.ended_at == datetime(2026, 11, 7, 18, 51, 31, tzinfo=timezone.utc)
771
+ assert resp.data.comments is None and resp.data.top_viewers is None
772
+ assert req.call_args[1]["json_body"] == {"username": "@streamer", "include_stream_urls": False}
773
+
774
+
775
+ def test_get_tiktok_live_room_needs_exactly_one_target(client):
776
+ with patch.object(client, "_request") as req:
777
+ for kwargs in ({}, {"room_id": "1", "username": "a"}, {"username": "a", "url": "https://www.tiktok.com/@a/live"}):
778
+ with pytest.raises(ValueError):
779
+ client.get_tiktok_live_room(**kwargs)
780
+ req.assert_not_called()
781
+
782
+
783
+ @pytest.mark.parametrize("configured, expected", [(30, 120.0), (300, 300)])
784
+ def test_live_room_raises_the_timeout_never_lowers_it(configured, expected):
785
+ client = VidNavigatorClient(api_key="test_key", timeout=configured)
786
+
787
+ class Ok:
788
+ ok, status_code, reason = True, 200, "OK"
789
+
790
+ def __init__(self, payload):
791
+ self.payload = payload
792
+
793
+ def json(self):
794
+ return self.payload
795
+
796
+ with patch.object(client.session, "request", side_effect=[Ok(LIVE_ROOM_RAW), Ok(TRANSCRIPT_RAW)]) as send:
797
+ client.get_tiktok_live_room(url="https://www.tiktok.com/@streamer/live")
798
+ client.get_transcript(video_url="https://example.com/v")
799
+ assert send.call_args_list[0][1]["timeout"] == expected
800
+ assert send.call_args_list[1][1]["timeout"] == configured
@@ -386,6 +386,33 @@ def test_tiktok_live_search_rejects_unsupported_country(client):
386
386
  assert exc_info.value.error_code == "invalid_country"
387
387
 
388
388
 
389
+ def test_tiktok_live_room_by_id_with_comments(client):
390
+ rooms = client.search_tiktok_live(query="gaming", max_results=5, webhook_url="",
391
+ timeout=TIKTOK_TIMEOUT_SECONDS).data.results or []
392
+ assert rooms, "no LIVE room for 'gaming' in the US"
393
+ busiest = max(rooms, key=lambda r: (r.stats.viewers or 0))
394
+
395
+ plain = client.get_tiktok_live_room(room_id=busiest.id, include_usage=True)
396
+ room = plain.data.room
397
+ assert room.id == busiest.id and room.status in ("live", "ended")
398
+ assert plain.data.comments is None
399
+ assert plain.usage.charge_for("residential_request").quantity == 1.0
400
+
401
+ chat = client.get_tiktok_live_room(room_id=busiest.id, include_comments=True, comments_limit=10,
402
+ include_usage=True)
403
+ assert isinstance(chat.data.comments, list) and len(chat.data.comments) <= 10
404
+ for comment in chat.data.comments:
405
+ assert comment.text and comment.author and comment.author.unique_id
406
+ expected = 2.0 if chat.data.room.is_live else 1.0
407
+ assert chat.usage.charge_for("residential_request").quantity == expected
408
+
409
+
410
+ def test_tiktok_live_room_unknown_is_not_found(client):
411
+ with pytest.raises(NotFoundError) as exc_info:
412
+ client.get_tiktok_live_room(room_id="123")
413
+ assert exc_info.value.error_code == "live_not_found"
414
+
415
+
389
416
  # -- Background jobs -------------------------------------------------------
390
417
 
391
418
  def test_extract_video_data_blocking_runs_as_job(client):
@@ -1,47 +1,47 @@
1
- """VidNavigator Developer API Python client."""
2
-
3
- __version__ = "2.2.0"
4
-
5
- from .client import VidNavigatorClient
6
- from .async_client import AsyncVidNavigatorClient
7
- from .jobs import AsyncJob, Job
8
- from .exceptions import (
9
- VidNavigatorError,
10
- AuthenticationError,
11
- AccessDeniedError,
12
- PaymentRequiredError,
13
- NotFoundError,
14
- RateLimitExceeded,
15
- TooManyActiveJobsError,
16
- BadRequestError,
17
- GeoRestrictedError,
18
- StorageQuotaExceededError,
19
- SystemOverloadError,
20
- ServerError,
21
- JobTimeoutError,
22
- WebhookSignatureError,
23
- )
24
- from .webhooks import construct_webhook_event, verify_webhook_signature
25
-
26
- __all__ = [
27
- "VidNavigatorClient",
28
- "AsyncVidNavigatorClient",
29
- "Job",
30
- "AsyncJob",
31
- "VidNavigatorError",
32
- "AuthenticationError",
33
- "AccessDeniedError",
34
- "PaymentRequiredError",
35
- "NotFoundError",
36
- "RateLimitExceeded",
37
- "TooManyActiveJobsError",
38
- "BadRequestError",
39
- "GeoRestrictedError",
40
- "StorageQuotaExceededError",
41
- "SystemOverloadError",
42
- "ServerError",
43
- "JobTimeoutError",
44
- "WebhookSignatureError",
45
- "construct_webhook_event",
46
- "verify_webhook_signature",
47
- ]
1
+ """VidNavigator Developer API Python client."""
2
+
3
+ __version__ = "2.3.0"
4
+
5
+ from .client import VidNavigatorClient
6
+ from .async_client import AsyncVidNavigatorClient
7
+ from .jobs import AsyncJob, Job
8
+ from .exceptions import (
9
+ VidNavigatorError,
10
+ AuthenticationError,
11
+ AccessDeniedError,
12
+ PaymentRequiredError,
13
+ NotFoundError,
14
+ RateLimitExceeded,
15
+ TooManyActiveJobsError,
16
+ BadRequestError,
17
+ GeoRestrictedError,
18
+ StorageQuotaExceededError,
19
+ SystemOverloadError,
20
+ ServerError,
21
+ JobTimeoutError,
22
+ WebhookSignatureError,
23
+ )
24
+ from .webhooks import construct_webhook_event, verify_webhook_signature
25
+
26
+ __all__ = [
27
+ "VidNavigatorClient",
28
+ "AsyncVidNavigatorClient",
29
+ "Job",
30
+ "AsyncJob",
31
+ "VidNavigatorError",
32
+ "AuthenticationError",
33
+ "AccessDeniedError",
34
+ "PaymentRequiredError",
35
+ "NotFoundError",
36
+ "RateLimitExceeded",
37
+ "TooManyActiveJobsError",
38
+ "BadRequestError",
39
+ "GeoRestrictedError",
40
+ "StorageQuotaExceededError",
41
+ "SystemOverloadError",
42
+ "ServerError",
43
+ "JobTimeoutError",
44
+ "WebhookSignatureError",
45
+ "construct_webhook_event",
46
+ "verify_webhook_signature",
47
+ ]
@@ -18,7 +18,7 @@ from .exceptions import VidNavigatorError
18
18
  from . import models
19
19
 
20
20
  DEFAULT_BASE_URL = "https://api.vidnavigator.com/v1"
21
- USER_AGENT = "vidnavigator-python/2.2.0"
21
+ USER_AGENT = "vidnavigator-python/2.3.0"
22
22
  API_KEY_ENV_VAR = "VIDNAVIGATOR_API_KEY"
23
23
 
24
24
  DateLike = Union[str, date, datetime]
@@ -366,6 +366,43 @@ def submit_tiktok_live_search(
366
366
  ))
367
367
 
368
368
 
369
+ # A room usually answers in 1-5 s, but up to ~30 s when the API has to open a
370
+ # TikTok page, and two minutes at worst: the client's timeout is raised to this
371
+ # for that call only.
372
+ LIVE_ROOM_TIMEOUT = 120.0
373
+
374
+
375
+ def get_tiktok_live_room(
376
+ *,
377
+ room_id: Optional[str] = None,
378
+ username: Optional[str] = None,
379
+ url: Optional[str] = None,
380
+ include_comments: Optional[bool] = None,
381
+ comments_limit: Optional[int] = None,
382
+ include_stream_urls: Optional[bool] = None,
383
+ include_usage: bool = False,
384
+ ) -> Request:
385
+ given = [name for name, value in (("room_id", room_id), ("username", username), ("url", url)) if value]
386
+ if len(given) != 1:
387
+ raise ValueError("Pass exactly one of room_id, username or url")
388
+ payload = _with_optional(
389
+ {},
390
+ # A string: room ids have 19 digits, more than a JavaScript number holds.
391
+ room_id=None if room_id is None else str(room_id),
392
+ username=username,
393
+ url=url,
394
+ include_comments=include_comments,
395
+ comments_limit=comments_limit,
396
+ include_stream_urls=include_stream_urls,
397
+ )
398
+ if include_usage:
399
+ payload["include_usage"] = True
400
+ return Request(
401
+ "POST", "/tiktok/live/room", {"json_body": payload, "min_timeout": LIVE_ROOM_TIMEOUT},
402
+ _model(models.TikTokLiveRoomResponse),
403
+ )
404
+
405
+
369
406
  def _tiktok_page(path: str, model_cls: Any, cursor: Optional[str], limit: int, include_usage: bool) -> Request:
370
407
  params: Dict[str, Any] = {"limit": limit}
371
408
  if cursor is not None:
@@ -84,7 +84,12 @@ class AsyncVidNavigatorClient:
84
84
  json_body: Optional[Dict[str, Any]] = None,
85
85
  data: Optional[Dict[str, Any]] = None,
86
86
  files: Any = None,
87
+ min_timeout: Optional[float] = None,
87
88
  ) -> Any:
89
+ timeout = self.timeout
90
+ if min_timeout is not None and isinstance(timeout, (int, float)):
91
+ # A call known to run long raises the timeout, never lowers it.
92
+ timeout = max(timeout, min_timeout)
88
93
  try:
89
94
  response = await self.http_client.request(
90
95
  method,
@@ -94,7 +99,7 @@ class AsyncVidNavigatorClient:
94
99
  data=data,
95
100
  files=files,
96
101
  headers=self._headers,
97
- timeout=self.timeout,
102
+ timeout=timeout,
98
103
  )
99
104
  except httpx.HTTPError as exc:
100
105
  raise VidNavigatorError(f"Request failed: {exc}") from exc
@@ -513,6 +518,28 @@ class AsyncVidNavigatorClient:
513
518
  task_id, cursor=cursor, limit=limit, include_usage=include_usage,
514
519
  ))
515
520
 
521
+ async def get_tiktok_live_room(
522
+ self,
523
+ *,
524
+ room_id: Optional[str] = None,
525
+ username: Optional[str] = None,
526
+ url: Optional[str] = None,
527
+ include_comments: Optional[bool] = None,
528
+ comments_limit: Optional[int] = None,
529
+ include_stream_urls: Optional[bool] = None,
530
+ include_usage: bool = False,
531
+ ) -> models.TikTokLiveRoomResponse:
532
+ """Get one TikTok LIVE room, synchronously. See :meth:`VidNavigatorClient.get_tiktok_live_room`."""
533
+ return await self._call(_core.get_tiktok_live_room(
534
+ room_id=room_id,
535
+ username=username,
536
+ url=url,
537
+ include_comments=include_comments,
538
+ comments_limit=comments_limit,
539
+ include_stream_urls=include_stream_urls,
540
+ include_usage=include_usage,
541
+ ))
542
+
516
543
  # Search -----------------------------------------------------------------------
517
544
  async def search_youtube(
518
545
  self,
@@ -78,8 +78,13 @@ class VidNavigatorClient:
78
78
  data: Optional[Dict[str, Any]] = None,
79
79
  files: Any = None,
80
80
  stream: bool = False,
81
+ min_timeout: Optional[float] = None,
81
82
  ) -> Any:
82
83
  url = f"{self.base_url}{path}"
84
+ timeout = self.timeout
85
+ if min_timeout is not None and isinstance(timeout, (int, float)):
86
+ # A call known to run long raises the timeout, never lowers it.
87
+ timeout = max(timeout, min_timeout)
83
88
  try:
84
89
  response = self.session.request(
85
90
  method,
@@ -88,7 +93,7 @@ class VidNavigatorClient:
88
93
  json=json_body,
89
94
  data=data,
90
95
  files=files,
91
- timeout=self.timeout,
96
+ timeout=timeout,
92
97
  stream=stream,
93
98
  )
94
99
  except requests.RequestException as exc:
@@ -653,6 +658,54 @@ class VidNavigatorClient:
653
658
  task_id, cursor=cursor, limit=limit, include_usage=include_usage,
654
659
  ))
655
660
 
661
+ def get_tiktok_live_room(
662
+ self,
663
+ *,
664
+ room_id: Optional[str] = None,
665
+ username: Optional[str] = None,
666
+ url: Optional[str] = None,
667
+ include_comments: Optional[bool] = None,
668
+ comments_limit: Optional[int] = None,
669
+ include_stream_urls: Optional[bool] = None,
670
+ include_usage: bool = False,
671
+ ) -> models.TikTokLiveRoomResponse:
672
+ """Get one TikTok LIVE room, synchronously. Pass exactly one of the first three.
673
+
674
+ Parameters
675
+ ----------
676
+ room_id:
677
+ A LIVE room ID, e.g. the ``id`` of a :meth:`search_tiktok_live` room.
678
+ username:
679
+ The streamer, with or without ``@``: their current LIVE, or their
680
+ last one when they are offline (``room.status == "ended"``).
681
+ url:
682
+ ``https://www.tiktok.com/@username/live``, the profile URL, or a
683
+ room's ``share_url``.
684
+ include_comments:
685
+ Also return the latest comments (up to 50, newest first), the
686
+ pinned comment, the intro and the top viewers. Bills 2
687
+ ``residential_request`` instead of 1. An ended room has none.
688
+ comments_limit:
689
+ At most this many comments (1-50, default 50).
690
+ include_stream_urls:
691
+ The room's playback URLs are returned by default; ``False`` leaves
692
+ them out.
693
+
694
+ The room has no likes, comment count or share count: TikTok gives those
695
+ to LIVE search only. A room or account that does not exist raises
696
+ :class:`~vidnavigator.exceptions.NotFoundError` and is not billed. The
697
+ call waits up to two minutes, whatever the client's ``timeout``.
698
+ """
699
+ return self._call(_core.get_tiktok_live_room(
700
+ room_id=room_id,
701
+ username=username,
702
+ url=url,
703
+ include_comments=include_comments,
704
+ comments_limit=comments_limit,
705
+ include_stream_urls=include_stream_urls,
706
+ include_usage=include_usage,
707
+ ))
708
+
656
709
  # Search -----------------------------------------------------------------------
657
710
  def search_youtube(
658
711
  self,
@@ -679,6 +679,89 @@ class TikTokLiveRoom(BaseModel):
679
679
  stream_urls: Optional[TikTokLiveStreamUrls] = Field(None, alias="stream_urls")
680
680
 
681
681
 
682
+ class TikTokLiveRoomAuthor(TikTokLiveAuthor):
683
+ """The streamer of a room fetched with ``get_tiktok_live_room``."""
684
+
685
+ bio: Optional[str] = None
686
+ # Accounts the streamer follows.
687
+ following: Optional[int] = None
688
+
689
+ @_pre_validator("followers", "following")
690
+ @classmethod
691
+ def _coerce_int_fields(cls, v):
692
+ return _coerce_optional_int(v)
693
+
694
+
695
+ class TikTokLiveRoomStats(BaseModel):
696
+ """A single room's counters. Likes, comments and shares come with LIVE search only."""
697
+
698
+ # Watching now (0 once the LIVE has ended).
699
+ viewers: Optional[int] = None
700
+ # Since the LIVE started.
701
+ total_viewers: Optional[int] = Field(None, alias="total_viewers")
702
+ # Followers the streamer gained during this LIVE.
703
+ new_followers: Optional[int] = Field(None, alias="new_followers")
704
+
705
+ @_pre_validator("viewers", "total_viewers", "new_followers")
706
+ @classmethod
707
+ def _coerce_int_fields(cls, v):
708
+ return _coerce_optional_int(v)
709
+
710
+
711
+ class TikTokLiveRoomDetail(TikTokLiveRoom):
712
+ """One LIVE room, as ``get_tiktok_live_room`` returns it."""
713
+
714
+ author: Optional[TikTokLiveRoomAuthor] = None
715
+ stats: Optional[TikTokLiveRoomStats] = None
716
+ # ``"live"`` while broadcasting, ``"ended"`` once finished.
717
+ status: Optional[str] = None
718
+ ended_at: Optional[datetime] = Field(None, alias="ended_at")
719
+ # The room's share link; it can be passed back as ``url``.
720
+ share_url: Optional[str] = Field(None, alias="share_url")
721
+ age_restricted: Optional[bool] = Field(None, alias="age_restricted")
722
+ subscribers_only: Optional[bool] = Field(None, alias="subscribers_only")
723
+ chat_enabled: Optional[bool] = Field(None, alias="chat_enabled")
724
+ # Products on sale in the LIVE.
725
+ products: Optional[int] = None
726
+
727
+ @property
728
+ def is_live(self) -> bool:
729
+ return self.status == "live"
730
+
731
+
732
+ class TikTokLiveComment(BaseModel):
733
+ """A comment posted in a LIVE's chat."""
734
+
735
+ id: Optional[str] = None
736
+ text: Optional[str] = None
737
+ # ISO 639-1 code TikTok detected, or None.
738
+ language: Optional[str] = None
739
+ created_at: Optional[datetime] = Field(None, alias="created_at")
740
+ author: Optional[TikTokLiveAuthor] = None
741
+ author_is_follower: Optional[bool] = Field(None, alias="author_is_follower")
742
+ author_is_moderator: Optional[bool] = Field(None, alias="author_is_moderator")
743
+ # A paying subscriber of the streamer.
744
+ author_is_subscriber: Optional[bool] = Field(None, alias="author_is_subscriber")
745
+
746
+
747
+ class TikTokLiveTopViewer(BaseModel):
748
+ """One of a LIVE's top viewers, ranked by the gifts they sent."""
749
+
750
+ rank: Optional[int] = None
751
+ score: Optional[int] = None
752
+ user: Optional[TikTokLiveAuthor] = None
753
+
754
+
755
+ class TikTokLiveRoomData(BaseModel):
756
+ room: TikTokLiveRoomDetail
757
+ # The four below are present only with ``include_comments=True``.
758
+ # Latest comments, newest first (TikTok keeps about the last 50).
759
+ comments: Optional[List[TikTokLiveComment]] = None
760
+ pinned_comment: Optional[TikTokLiveComment] = Field(None, alias="pinned_comment")
761
+ intro: Optional[str] = None
762
+ top_viewers: Optional[List[TikTokLiveTopViewer]] = Field(None, alias="top_viewers")
763
+
764
+
682
765
  class TikTokLiveSearchStats(BaseModel):
683
766
  pages_fetched: Optional[int] = Field(None, alias="pages_fetched")
684
767
  # Distinct rooms TikTok returned, those past ``max_results`` included.
@@ -923,6 +1006,12 @@ class TikTokLiveSearchResponse(BaseModel):
923
1006
  usage: Optional[UsageBlock] = None
924
1007
 
925
1008
 
1009
+ class TikTokLiveRoomResponse(BaseModel):
1010
+ status: str
1011
+ data: TikTokLiveRoomData
1012
+ usage: Optional[UsageBlock] = None
1013
+
1014
+
926
1015
  class TweetStatementResponse(BaseModel):
927
1016
  status: str
928
1017
  data: TweetStatementData
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: vidnavigator
3
- Version: 2.2.0
3
+ Version: 2.3.0
4
4
  Summary: Python SDK for the VidNavigator Developer API
5
5
  Author-email: Hatem <hatem.mezlini@vidnavigator.com>
6
6
  License: Apache License
@@ -247,7 +247,7 @@ The official Python client for the [VidNavigator Developer API](https://docs.vid
247
247
  - [Installation](#installation) · [Authentication](#authentication) · [Quick start](#quick-start) · [Which method should I use?](#which-method-should-i-use)
248
248
  - **Online videos:** [Transcripts](#transcripts) · [AI analysis](#ai-analysis) · [Structured extraction](#structured-extraction) · [Tweet claim analysis](#tweet-claim-analysis)
249
249
  - **Long-running work:** [Background jobs](#background-jobs) · [Recipes](#recipes) · [Async client](#async-client) · [Webhooks](#webhooks)
250
- - **TikTok:** [Profile scraping](#tiktok-profile-scraping) · [Keyword search](#tiktok-keyword-search) · [LIVE search](#tiktok-live-search)
250
+ - **TikTok:** [Profile scraping](#tiktok-profile-scraping) · [Keyword search](#tiktok-keyword-search) · [LIVE search](#tiktok-live-search) · [LIVE room](#tiktok-live-room)
251
251
  - **Your own files:** [Semantic search](#semantic-search) · [File uploads](#file-uploads) · [Namespaces](#namespaces)
252
252
  - **Reference:** [Per-call usage](#per-call-usage) · [Usage & billing](#usage--billing) · [Error handling](#error-handling) · [Configuration](#configuration) · [Upgrading from 1.x](#upgrading-from-1x)
253
253
 
@@ -361,6 +361,7 @@ print(resp.data) # {"mood": "upbeat"}
361
361
  | List a TikTok profile's videos | `scrape_tiktok_profile` | when the job finishes |
362
362
  | Search TikTok by keyword | `search_tiktok` | when the job finishes |
363
363
  | Find TikTok LIVE rooms broadcasting now, with their stream URLs | `search_tiktok_live` | when the job finishes |
364
+ | Check one TikTok LIVE room or streamer, with its latest comments | `get_tiktok_live_room` | immediately |
364
365
  | Find YouTube videos about a topic | `search_youtube` | immediately |
365
366
  | Work with your own audio/video files | `upload_file`, then `get_file`, `analyze_file`, `extract_file_data`, `search_files` | immediately |
366
367
  | Process **many** videos at once | the `submit_*` version of a job method | a job handle, right away |
@@ -1231,6 +1232,47 @@ Results keep TikTok's ranking. A keyword with no LIVE room in that country at th
1231
1232
 
1232
1233
  ---
1233
1234
 
1235
+ ## TikTok LIVE Room
1236
+
1237
+ `get_tiktok_live_room` returns one LIVE room right away (no job): by room id, by streamer, or by LIVE URL. Use it to check whether someone is live, to follow a room found by [LIVE search](#tiktok-live-search), or to read its latest comments.
1238
+
1239
+ ```python
1240
+ resp = client.get_tiktok_live_room(username="tiktok", include_comments=True)
1241
+ room = resp.data.room
1242
+
1243
+ print(room.status, room.title, room.stats.viewers, room.stats.new_followers)
1244
+ if room.is_live:
1245
+ for comment in resp.data.comments:
1246
+ print(comment.created_at, comment.author.unique_id, comment.text)
1247
+ else:
1248
+ print("ended at", room.ended_at)
1249
+ ```
1250
+
1251
+ | Parameter | Type | Description |
1252
+ |---|---|---|
1253
+ | `room_id` | `str` | A LIVE room id, e.g. the `id` of a LIVE search room |
1254
+ | `username` | `str` | The streamer, with or without `@`: their current LIVE, or their last one when they are offline |
1255
+ | `url` | `str` | `https://www.tiktok.com/@username/live`, the profile URL, or a room's `share_url` |
1256
+ | `include_comments` | `bool` | Also return the latest comments, the pinned comment, the intro and the top viewers. Default `False`. |
1257
+ | `comments_limit` | `int` | At most this many comments, 1-50 (default 50) |
1258
+ | `include_stream_urls` | `bool` | Stream URLs are returned by default; pass `False` to leave them out |
1259
+ | `include_usage` | `bool` | Add the `usage` block |
1260
+
1261
+ Pass exactly one of `room_id`, `username` or `url`. The room (`TikTokLiveRoomDetail`) has the fields of a LIVE search room, plus:
1262
+
1263
+ - `status` (`"live"` or `"ended"`, also `room.is_live`) and `ended_at`
1264
+ - `stats.viewers` (watching now), `stats.total_viewers` (since the start), `stats.new_followers` (gained during the LIVE)
1265
+ - `author.bio`, `author.following`
1266
+ - `share_url`, `chat_enabled`, `subscribers_only`, `age_restricted`, `products` (items on sale)
1267
+
1268
+ With `include_comments=True`, `resp.data` also has `comments` (newest first; TikTok keeps only about the last 50 of a LIVE), `pinned_comment`, `intro` and `top_viewers`. A room that has ended has no comments.
1269
+
1270
+ A room's likes, comment count and share count are not available here: [LIVE search](#tiktok-live-search) returns them. A room or account that does not exist raises `NotFoundError` (`error_code == "live_not_found"`). The call usually takes a few seconds; it may wait up to two minutes, whatever the client's `timeout`.
1271
+
1272
+ Billing: 1 `residential_request` per room, 2 with `include_comments` (1 when the room has ended). Not billed when the room is not found.
1273
+
1274
+ ---
1275
+
1234
1276
  ## Semantic Search
1235
1277
 
1236
1278
  ### Search YouTube
@@ -1493,6 +1535,10 @@ One client can be reused for any number of calls. If you use threads, create one
1493
1535
 
1494
1536
  ---
1495
1537
 
1538
+ ## What's new in 2.3.0
1539
+
1540
+ - **TikTok LIVE room:** [`get_tiktok_live_room`](#tiktok-live-room) returns one room right away, by room id, streamer or LIVE URL: live or ended, viewers, new followers, the streamer's bio, and with `include_comments=True` its latest comments, pinned comment, intro and top viewers.
1541
+
1496
1542
  ## What's new in 2.2.0
1497
1543
 
1498
1544
  - **TikTok LIVE search:** `search_tiktok_live` / `client.tiktok_live_search`, with typed rooms and their stream URLs.
File without changes
File without changes