Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: Add Clips Upload #1718

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 9 additions & 12 deletions src/repositories/media.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ export class MediaRepository extends Repository {
return body;
}

public async configureVideo(options: MediaConfigureTimelineVideoOptions) {
public async configureVideo(options: MediaConfigureTimelineVideoOptions, isClips: boolean) {
const now = DateTime.local().toFormat('yyyy:mm:dd HH:mm:ss');

const form = this.applyConfigureDefaults<MediaConfigureTimelineVideoOptions>(options, {
Expand All @@ -388,7 +388,7 @@ export class MediaRepository extends Repository {
}

const { body } = await this.client.request.send<MediaRepositoryConfigureResponseRootObject>({
url: '/api/v1/media/configure/',
url: '/api/v1/media/configure' + (isClips ? '_to_clips/' : '/'),
method: 'POST',
qs: {
video: '1',
Expand Down Expand Up @@ -682,10 +682,10 @@ export class MediaRepository extends Repository {
* save a media, or save it to collection if you pass the collection ids in array
* @param {string} mediaId - The mediaId of the post
* @param {string[]} [collection_ids] - Optional, The array of collection ids if you want to save the media to a specific collection
* Example:
* Example:
* save("2524149952724070925_1829855275") save media
* save("2524149952724070925_1829855275", ["17865977635619975"]) save media to 1 collection
* save("2524149952724070925_1829855275", ["17865977635619975", "17845997638619928"]) save media to 2 collection
* save("2524149952724070925_1829855275", ["17865977635619975", "17845997638619928"]) save media to 2 collection
*/
public async save(mediaId: string, collection_ids?: string[]) {
const { body } = await this.client.request.send({
Expand Down Expand Up @@ -795,27 +795,24 @@ export class MediaRepository extends Repository {
});
return body;
}

private async storyCountdownAction(
countdownId: string | number,
action: string,
): Promise<StatusResponse> {

private async storyCountdownAction(countdownId: string | number, action: string): Promise<StatusResponse> {
const { body } = await this.client.request.send({
url: `/api/v1/media/${countdownId}/${action}/`,
method: 'POST',
form: this.client.request.sign({
_csrftoken: this.client.state.cookieCsrfToken,
_uid: this.client.state.cookieUserId,
_uuid: this.client.state.uuid
_uuid: this.client.state.uuid,
}),
});
return body;
}

public async storyCountdownFollow(countdownId: string | number) {
return this.storyCountdownAction(countdownId, 'follow_story_countdown');
}

public async storyCountdownUnfollow(countdownId: string | number) {
return this.storyCountdownAction(countdownId, 'unfollow_story_countdown');
}
Expand Down
3 changes: 3 additions & 0 deletions src/repositories/upload.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,9 @@ export class UploadRepository extends Repository {
if (options.isDirectVoice) {
ruploadParams.is_direct_voice = '1';
}
if (options.isClipVideo) {
ruploadParams.is_clips_video = '1';
}
return ruploadParams;
}
}
7 changes: 6 additions & 1 deletion src/services/publish.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ export class PublishService extends Repository {
await Bluebird.try(() =>
this.regularVideo({
video: options.video,
isClipVideo: options.isClip,
uploadId,
...videoInfo,
}),
Expand Down Expand Up @@ -196,9 +197,13 @@ export class PublishService extends Repository {
configureOptions.usertags = options.usertags;
}

if (typeof options.clipsPreviewToFeed) {
configureOptions.clips_share_preview_to_feed = options.clipsPreviewToFeed ? '1' : '0';
}

for (let i = 0; i < 6; i++) {
try {
return await this.client.media.configureVideo(configureOptions);
return await this.client.media.configureVideo(configureOptions, options.isClip);
} catch (e) {
if (i >= 5 || e.response.statusCode >= 400) {
throw new IgConfigureVideoError(e.response, configureOptions);
Expand Down
3 changes: 3 additions & 0 deletions src/types/media.configure-video.options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ export interface MediaConfigureVideoOptions {
posting_longitude?: string;
media_latitude?: string;
media_longitude?: string;

isClipsVideo?: boolean;
clips_share_preview_to_feed?: string;
}

export interface MediaConfigureTimelineVideoOptions extends MediaConfigureVideoOptions {
Expand Down
2 changes: 2 additions & 0 deletions src/types/posting.video.options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ export interface PostingVideoOptions {
usertags?: PostingUsertags;
location?: PostingLocation;
transcodeDelay?: number;
isClip?: boolean;
clipsPreviewToFeed?: boolean;
}

export interface PostingStoryVideoOptions extends PostingStoryOptions {
Expand Down
1 change: 1 addition & 0 deletions src/types/upload.video.options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface UploadVideoOptions {
waterfallId?: string;
uploadName?: string;
offset?: number;
isClipVideo?: boolean;
}

export interface UploadVideoSegmentInitOptions {
Expand Down