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
feat: script to add and remove SRT track from Mux #1458
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
apps/testing-javascript/src/data/add-srt-to-specific-video.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Running this script: | ||
// | ||
// Be sure to set `MUX_ACCESS_TOKEN` and `MUX_SECRET_KEY` in your | ||
// `.env.local` environment variables file. And assign string values | ||
// to the `assetId` and `srtUrl` variables below. | ||
// | ||
// Execute the script with: | ||
// | ||
// ``` | ||
// npx ts-node --files --skipProject src/data/add-srt-to-specific-video.ts | ||
// ``` | ||
|
||
import Mux from '@mux/mux-node' | ||
|
||
require('dotenv-flow').config({ | ||
default_node_env: 'development', | ||
}) | ||
|
||
const assetId = undefined // Set me! | ||
const srtUrl = undefined // Set me! | ||
|
||
const addSrtToSpecificVideo = async ( | ||
assetId: string | undefined, | ||
srtUrl: string | undefined, | ||
) => { | ||
if (!assetId) { | ||
throw new Error('Must define assetId at the beginning of this script') | ||
} | ||
if (!srtUrl) { | ||
throw new Error('Must define srtUrl at the beginning of this script') | ||
} | ||
|
||
// Set up Mux API Client | ||
const MUX_ACCESS_TOKEN = process.env.MUX_ACCESS_TOKEN as string | ||
const MUX_SECRET_KEY = process.env.MUX_SECRET_KEY as string | ||
const muxClient = new Mux(MUX_ACCESS_TOKEN, MUX_SECRET_KEY) | ||
const {Video} = muxClient | ||
|
||
await Video.Assets.createTrack(assetId, { | ||
url: srtUrl, | ||
type: 'text', | ||
text_type: 'subtitles', | ||
closed_captions: false, | ||
language_code: 'en-US', | ||
name: 'English', | ||
passthrough: 'English', | ||
}) | ||
} | ||
|
||
addSrtToSpecificVideo(assetId, srtUrl) |
42 changes: 42 additions & 0 deletions
42
apps/testing-javascript/src/data/remove-track-from-video.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Running this script: | ||
// | ||
// Be sure to set `MUX_ACCESS_TOKEN` and `MUX_SECRET_KEY` in your | ||
// `.env.local` environment variables file. And assign string values | ||
// to the `assetId` and `trackId` variables below. | ||
// | ||
// Execute the script with: | ||
// | ||
// ``` | ||
// npx ts-node --files --skipProject src/data/remove-track-from-video.ts | ||
// ``` | ||
|
||
import Mux from '@mux/mux-node' | ||
|
||
require('dotenv-flow').config({ | ||
default_node_env: 'development', | ||
}) | ||
|
||
const assetId = undefined // Set me! | ||
const trackId = undefined // Set me! | ||
|
||
const removeTrackFromVideo = async ( | ||
assetId: string | undefined, | ||
trackId: string | undefined, | ||
) => { | ||
if (!assetId) { | ||
throw new Error('Must define assetId at the beginning of this script') | ||
} | ||
if (!trackId) { | ||
throw new Error('Must define trackId at the beginning of this script') | ||
} | ||
|
||
// Set up Mux API Client | ||
const MUX_ACCESS_TOKEN = process.env.MUX_ACCESS_TOKEN as string | ||
const MUX_SECRET_KEY = process.env.MUX_SECRET_KEY as string | ||
const muxClient = new Mux(MUX_ACCESS_TOKEN, MUX_SECRET_KEY) | ||
const {Video} = muxClient | ||
|
||
await Video.Assets.deleteTrack(assetId, trackId) | ||
} | ||
|
||
removeTrackFromVideo(assetId, trackId) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
personally I found it useful to check here if it already exists and remove it first