@yourname168/tiktok 0.2.0 → 0.2.1

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.
package/README.md CHANGED
@@ -82,6 +82,29 @@ methods. Set `productRegistration: 'existing'` for products already registered
82
82
  in the account's Showcase. The default is `'add'`. Use the same option on
83
83
  `publishVideo()` or `uploadVideo()`.
84
84
 
85
+ ### Use a TikTok sound in a video
86
+
87
+ Pass `music` to `publishVideo()` or `uploadVideo()` to send a native TikTok
88
+ sound and its edit timeline. Provide the same selected-sound metadata as for
89
+ albums, plus `videoDurationSeconds` and, optionally, `framesPerSecond` (24 by
90
+ default). The timeline keeps the original audio, starts the selected sound at
91
+ the beginning of the video, and trims it to the video duration or end of the
92
+ requested track segment, whichever comes first. It does not re-encode the MP4.
93
+
94
+ ```ts
95
+ await client.uploadVideo({
96
+ videoPath: '/absolute/path/video.mp4',
97
+ caption: '',
98
+ visibility: 'private',
99
+ music: { ...selectedMusic, videoDurationSeconds: 10, framesPerSecond: 24 },
100
+ });
101
+ ```
102
+
103
+ Use metadata from a sound available to the posting account. A TikTok music page
104
+ link identifies a track and needs to be resolved to the TikTok playback URL and
105
+ metadata before this API call. The video request shape was checked against
106
+ TikTok Studio. Playback of the linked sound after API publication is unverified.
107
+
85
108
  The publish response is TikTok's raw acknowledgement. Check the published item
86
109
  for review status, visibility and whether the product anchor renders. Reuse a known
87
110
  `creationId` and inspect TikTok before retrying after a timeout.
@@ -137,7 +160,7 @@ For installation outside the monorepo, generate a compiled JS + declaration tarb
137
160
 
138
161
  ```sh
139
162
  pnpm --filter @gateway/tiktok pack:portable /absolute/output/directory
140
- npm install /absolute/output/directory/gateway-tiktok-0.2.0.tgz
163
+ npm install /absolute/output/directory/gateway-tiktok-0.2.1.tgz
141
164
  ```
142
165
 
143
166
  Use this portable tarball instead of packing the TypeScript workspace directly:
@@ -150,7 +173,7 @@ To prepare a public release under the npm account scope:
150
173
 
151
174
  ```sh
152
175
  pnpm --filter @gateway/tiktok pack:portable /absolute/output/directory --name @yourname168/tiktok
153
- npm publish /absolute/output/directory/yourname168-tiktok-0.2.0.tgz --access public
176
+ npm publish /absolute/output/directory/yourname168-tiktok-0.2.1.tgz --access public
154
177
  ```
155
178
 
156
179
  The public tarball excludes tests, session files, npm credentials and workspace
package/dist/index.d.ts CHANGED
@@ -3,5 +3,5 @@ export { createTikTokContentClient, refreshTikTokToken } from './content-client.
3
3
  export { parseTikTokSession } from './session.ts';
4
4
  export { createPhotoPostBody, createWebPostBody, productAnchors } from './post-body.ts';
5
5
  export type { TikTokSession } from './session.ts';
6
- export type { PhotoAlbumMusic, PhotoPostOptions, PrivatePhotoPostOptions, ProductAnchor, UploadedPhoto, UploadedVideo, WebPostOptions } from './post-body.ts';
6
+ export type { PhotoAlbumMusic, PhotoPostOptions, PrivatePhotoPostOptions, ProductAnchor, UploadedPhoto, UploadedVideo, VideoPostMusic, WebPostOptions } from './post-body.ts';
7
7
  export type { HttpTransport } from './http.ts';
@@ -22,6 +22,10 @@ export interface PhotoAlbumMusic {
22
22
  endSeconds: number;
23
23
  album?: string;
24
24
  }
25
+ export interface VideoPostMusic extends PhotoAlbumMusic {
26
+ videoDurationSeconds: number;
27
+ framesPerSecond?: number;
28
+ }
25
29
  export interface PrivatePhotoPostOptions {
26
30
  creationId: string;
27
31
  title: string;
@@ -46,6 +50,7 @@ export interface WebPostOptions {
46
50
  scheduleTimeSeconds?: number;
47
51
  products?: ProductAnchor[];
48
52
  productRegistration?: 'add' | 'existing';
53
+ music?: VideoPostMusic;
49
54
  }
50
55
  export declare function productAnchors(products: ProductAnchor[]): {
51
56
  type: number;
@@ -79,6 +84,8 @@ export declare function createWebPostBody(input: WebPostOptions): {
79
84
  };
80
85
  }[];
81
86
  vedit_common_info: {
87
+ application?: number;
88
+ tiktok_snap_shot_lite_params?: string;
82
89
  draft: string;
83
90
  video_id: string;
84
91
  };
@@ -96,7 +103,6 @@ export declare function createWebPostBody(input: WebPostOptions): {
96
103
  video_id: string;
97
104
  is_long_video: number;
98
105
  single_post_feature_info: {
99
- music_info: {};
100
106
  cover_info: {
101
107
  frame_duration: number;
102
108
  blob_url: string;
@@ -112,6 +118,17 @@ export declare function createWebPostBody(input: WebPostOptions): {
112
118
  cloud_edit_video_height: number;
113
119
  cloud_edit_video_width: number;
114
120
  cloud_edit_is_use_video_canvas: boolean;
121
+ music_info: {};
122
+ vedit_segment_info?: {
123
+ start_time: number;
124
+ end_time: number;
125
+ };
126
+ has_original_audio?: number;
127
+ is_upload_audio_track?: boolean;
128
+ video_track_time_range_list?: {
129
+ start_time_in_ms: number;
130
+ end_time_in_ms: number;
131
+ }[];
115
132
  text: string;
116
133
  text_extra: {
117
134
  tag_id: string;
package/dist/post-body.js CHANGED
@@ -29,21 +29,22 @@ export function createWebPostBody(input) {
29
29
  const visibility = input.visibility ?? 'private';
30
30
  if (!['public', 'friends', 'private'].includes(visibility))
31
31
  throw new Error('Invalid visibility');
32
+ const audio = input.music ? videoMusicFields(input.video, input.music) : undefined;
32
33
  return {
33
34
  post_common_info: { creation_id: input.creationId, enter_post_page_from: 2, post_type: 3 },
34
35
  feature_common_info_list: [{ schedule_time: schedule, geofencing_regions: [], playlist_name: '', playlist_id: '',
35
36
  tcm_params: '{"commerce_toggle_info":{}}', sound_exemption: 0, anchors: productAnchors(input.products ?? []),
36
- vedit_common_info: { draft: '', video_id: input.video.videoId },
37
+ vedit_common_info: { draft: '', video_id: input.video.videoId, ...audio?.editor },
37
38
  privacy_setting_info: { visibility_type: { public: 0, friends: 2, private: 1 }[visibility], allow_duet: null,
38
39
  allow_stitch: null, allow_comment: input.allowComments === false ? 0 : 1, allow_content_reuse: 1 }, content_check_id: '' }],
39
40
  single_post_req_list: [{ batch_index: 0, video_id: input.video.videoId, is_long_video: 0,
40
- single_post_feature_info: { ...captionFields(input.caption), music_info: {},
41
+ single_post_feature_info: { ...captionFields(input.caption), music_info: {}, ...audio?.post,
41
42
  cover_info: { frame_duration: 0, blob_url: '', cover_width: input.video.width, cover_height: input.video.height,
42
43
  cover_type: 2, crop_type: 2, isAutoCropFirstFrame: true, cover_uri: input.coverUri ?? '', isProcessingInitialCover: false },
43
44
  poster_delay: 0, cloud_edit_video_height: input.video.height, cloud_edit_video_width: input.video.width, cloud_edit_is_use_video_canvas: false } }],
44
45
  };
45
46
  }
46
- function photoMusicInfo(music) {
47
+ function musicInfo(music) {
47
48
  const start = music.startSeconds ?? 0;
48
49
  if (!Number.isFinite(start) || !Number.isFinite(music.endSeconds) || start < 0 || music.endSeconds <= start) {
49
50
  throw new Error('Invalid music time range');
@@ -64,6 +65,42 @@ function photoMusicInfo(music) {
64
65
  music_type: 1,
65
66
  };
66
67
  }
68
+ function videoMusicFields(video, music) {
69
+ const track = musicInfo(music);
70
+ const duration = Math.round(music.videoDurationSeconds * 1000);
71
+ const framesPerSecond = music.framesPerSecond ?? 24;
72
+ const start = Math.round(track.music_begin_time * 1000);
73
+ const end = Math.min(Math.round(track.music_end_time * 1000), start + duration);
74
+ if (![duration, start, end].every(Number.isSafeInteger) || duration < 1 || end <= start ||
75
+ !Number.isFinite(framesPerSecond) || framesPerSecond <= 0) {
76
+ throw new Error('Invalid video music timeline');
77
+ }
78
+ const snapshot = {
79
+ Elements: [
80
+ {
81
+ Type: 'video', Source: `vid://${video.videoId}`, StartIndex: 0, StartTime: 0, EndTime: duration,
82
+ Volume: 1, Background: { Type: 'color', Color: '#000000FF' }, OffsetX: 0, OffsetY: 0,
83
+ Rotate: 0, Scale: 1, Alpha: 1,
84
+ },
85
+ {
86
+ Type: 'audio', Source: track.music_url, StartTime: 0, EndTime: end - start, StartIndex: 0,
87
+ StartOffset: start, EndIndex: 0, EndOffset: end, Volume: 1, FadeIn: 0, FadeOut: 0,
88
+ },
89
+ ],
90
+ GlobalElements: [],
91
+ OutputInfo: { Format: 'mp4', Width: video.width, Height: video.height, Fps: framesPerSecond, Duration: duration, FallbackFonts: [] },
92
+ };
93
+ return {
94
+ editor: { application: 2, tiktok_snap_shot_lite_params: JSON.stringify(snapshot) },
95
+ post: {
96
+ music_info: { ...track, music_begin_time: start, music_end_time: end },
97
+ vedit_segment_info: { start_time: 0, end_time: duration },
98
+ has_original_audio: 1,
99
+ is_upload_audio_track: true,
100
+ video_track_time_range_list: [{ start_time_in_ms: 0, end_time_in_ms: duration }],
101
+ },
102
+ };
103
+ }
67
104
  export function createPhotoPostBody(input) {
68
105
  string(input.creationId, 'creationId');
69
106
  if (!input.products.length)
@@ -102,7 +139,7 @@ export function createPhotoPostBody(input) {
102
139
  image_post_content: { title: input.title, images: photos, cover },
103
140
  single_post_feature_info: {
104
141
  ...captionFields(input.caption),
105
- ...(input.music ? { music_info: photoMusicInfo(input.music) } : {}),
142
+ ...(input.music ? { music_info: musicInfo(input.music) } : {}),
106
143
  },
107
144
  }],
108
145
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yourname168/tiktok",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "Experimental direct TikTok web-session/Shop and official Content Posting API clients, with TypeScript types and no runtime dependencies.",
5
5
  "license": "MIT",
6
6
  "type": "module",