Skip to content

Instantly share code, notes, and snippets.

@MoeRayo
Last active August 4, 2022 09:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MoeRayo/954f4d17563c7779fea6bf5f28022088 to your computer and use it in GitHub Desktop.
Save MoeRayo/954f4d17563c7779fea6bf5f28022088 to your computer and use it in GitHub Desktop.
<script>
export default {
data(){
return {
jobId: '',
formData: null,
}
},
methods: {
async enhanceVideo(){
//Dolby authnentication code goes here
//media enhancement API
//enhancement checker API
//media download API
function wait(ms = 2000) {
return new Promise((resolve) => {
setTimeout(resolve, ms);
});
}
let state = null;
this.$axios(enhanceRequest)
.then(async (response) =>{
this.jobId = response.data.job_id
while(state !== "Success"){
await wait()
this.$axios(`https://api.dolby.com/media/enhance?job_id=${this.jobId}`,enhancementCheck)
.then((res)=> {
state = res.data.status
if(res.data.status === "Success"){
this.$axios(mediaDownload)
.then((response) => {
response
})
.catch((err) => {
if (err.request.responseURL.match(/mp4/)) {
let retry = err.request.responseURL
if (retry){
console.log("Now Downloading audio");
this.$axios.get(retry).then((response) => {
if (response.status === 200) {
//upload enhanced video to cloudinary
console.log("Now Uploading to cloudinary");
this.formData = new FormData();
this.formData.append("file", response.config.url);
this.formData.append("upload_preset", this.uploadPreset);
const cloudinaryUploadURL = `https://api.cloudinary.com/v1_1/${this.cloudName}/upload`;
const requestObj = {
url: cloudinaryUploadURL,
method: "POST",
data: this.formData,
};
//uploading to cloudinary
this.$axios(requestObj)
.then(response => {
response
})
.catch((err) => console.log(err));
}
}).catch((e) => {
e
})
}
} else {
console.log("error")
}
});
}
}).catch((err) => err)
}
}).catch((err) => err)
}
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment