Best JavaScript code snippet using argos
index.js
Source:index.js
1import React, { useEffect, useRef, useState } from 'react';2import { useTranslation } from 'react-i18next';3import {4 Text,5 TouchableOpacity,6 View,7 TouchableWithoutFeedback,8 Keyboard,9 Dimensions,10 Image,11 Platform,12} from 'react-native';13import Ionicons from 'react-native-vector-icons/Ionicons';14import { Navigation } from 'react-native-navigation';15import { VideoPlayer, Trimmer } from 'react-native-video-processing';16import { Layout, NavBar } from '../../../components';17import style from './styles';18import colors from '../../../theme/colors';19import { wp } from '../../../commons/responsive';20import images from '../../../assets/images';21import AppSlider from '../../../components/slider';22import { createThumbnail } from 'react-native-create-thumbnail';23import _ from 'lodash';24import { useNavigation } from '../../../hooks';25import Screens from '../../screens';26import Video from 'react-native-video';27const TrimmerView = ({28 componentId,29 videoFile,30 maxDuration,31 onCreateSuccess,32 onFinish,33}) => {34 const { t } = useTranslation();35 const navigation = useNavigation(componentId);36 const [trimTime, setTrimTime] = useState({ start: 0, end: 10 });37 const [play, setPlay] = useState(true);38 const [videoThumbs, setVideoThumbs] = useState([]);39 const [videoOrientation, setVideoOrientation] = useState(40 Platform.OS === 'android'41 ? videoFile.width < videoFile.height42 ? 'portrait'43 : 'landscape'44 : '',45 );46 const videoPlayerRef = useRef(null);47 useEffect(() => {48 setTrimTime({49 start: 0,50 end: Platform.OS === 'android' ? maxDuration : videoFile.duration,51 });52 var thumbRequests = [];53 for (var i = 0; i < 10; i++) {54 thumbRequests.push(55 createThumbnail({56 url: videoFile.path,57 timeStamp: i * (videoFile.duration / 10),58 }),59 );60 }61 Promise.all(thumbRequests)62 .then(results => {63 setVideoThumbs(results);64 })65 .catch(e => {66 console.log('###createThumbnail - eror: ', e);67 });68 // eslint-disable-next-line react-hooks/exhaustive-deps69 }, []);70 const onPressDone = () => {71 const options = {72 startTime: trimTime.start,73 endTime: trimTime.end,74 quality:75 Platform.OS === 'ios'76 ? VideoPlayer.Constants.quality.QUALITY_1280x72077 : null, // iOS only78 saveToCameraRoll: true, // default is false // iOS only79 saveWithCurrentDate: true, // default is false // iOS only80 };81 videoPlayerRef.current82 .trim(options)83 .then(newSource => {84 console.log(newSource);85 if (_.isFunction(onFinish)) {86 Navigation.dismissModal(componentId);87 onFinish({88 ...videoFile,89 path: `${90 !newSource.includes('file://') ? 'file://' : ''91 }${newSource}`,92 duration: maxDuration,93 });94 } else {95 navigation.push(Screens.CreateVideoStory, {96 videoFile: {97 path: `${98 !newSource.includes('file://') ? 'file://' : ''99 }${newSource}`,100 width: videoFile.width,101 height: videoFile.height,102 },103 onCreateSuccess,104 });105 }106 })107 .catch(error => {108 console.log('###trim - error: ', error);109 });110 };111 const renderPostButton = () => {112 return (113 <TouchableOpacity114 onPress={() => onPressDone()}115 disabled={trimTime.end - trimTime.start > maxDuration}>116 <Text117 style={[118 style.doneButtonText,119 {120 color:121 trimTime.end - trimTime.start > maxDuration122 ? colors.flatGrey11123 : colors.black,124 },125 ]}>126 {t('done')}127 </Text>128 </TouchableOpacity>129 );130 };131 return (132 <Layout style={style.container}>133 <TouchableWithoutFeedback134 style={style.container}135 onPress={Keyboard.dismiss}>136 <View style={style.container}>137 <NavBar138 parentComponentId={componentId}139 showCloseButton140 accessoryRight={renderPostButton}141 title={t('trimmerViewTitle')}142 onLeftPress={() => Navigation.dismissModal(componentId)}143 />144 <View style={style.separator} />145 <View style={{ flex: 1, justifyContent: 'center' }}>146 <View style={style.videoContainer}>147 {videoOrientation === '' && (148 <Video149 style={{ width: 0, height: 0 }}150 source={{ uri: videoFile.path }}151 onLoad={response => {152 const { width, height, orientation } = response.naturalSize;153 setVideoOrientation(orientation);154 console.log(orientation);155 }}156 />157 )}158 {(videoOrientation !== '' || Platform.OS === 'android') && (159 <VideoPlayer160 ref={videoPlayerRef}161 rotate={videoOrientation === 'portrait' ? true : false}162 startTime={trimTime.start} // seconds163 endTime={trimTime.end} // seconds164 currentTime={trimTime.start}165 play={play} // default false166 replay={true} // should player play video again if it's ended167 source={videoFile.path}168 playerWidth={Dimensions.get('screen').width} // iOS only169 playerHeight={wp(250)} // iOS only170 style={{ flex: 1 }}171 resizeMode={VideoPlayer.Constants.resizeMode.CONTAIN}172 // onChange={({ nativeEvent }) => console.log({ nativeEvent })} // get Current time on every second173 />174 )}175 <TouchableOpacity176 style={{177 position: 'absolute',178 bottom: 0,179 left: 0,180 height: 50,181 width: 50,182 justifyContent: 'center',183 alignItems: 'center',184 }}185 onPress={() => setPlay(!play)}>186 <Ionicons187 name={play ? images.icon_pause : images.icon_play}188 size={24}189 color={colors.white}190 />191 </TouchableOpacity>192 </View>193 <View style={{ alignItems: 'center', marginBottom: wp(10) }}>194 <Text195 style={{196 color:197 trimTime.end - trimTime.start > maxDuration198 ? colors.red199 : colors.black,200 }}>{`${t('totalSelected')}: ${Math.ceil(201 trimTime.end - trimTime.start,202 )}s (${t('maxSelection')} ${maxDuration}s)`}</Text>203 </View>204 <View style={{ flexDirection: 'row' }}>205 <View>206 {/* {Platform.OS === 'ios' && (207 <Trimmer208 source={videoFile.path}209 height={50}210 width={Dimensions.get('screen').width - 16}211 // onTrackerMove={e => console.log(e.currentTime)} // iOS only212 currentTime={trimTime.start} // use this prop to set tracker position iOS only213 themeColor={colors.appYellow} // iOS only214 thumbWidth={20} // iOS only215 trackerColor={'white'} // iOS only216 onChange={e => {217 setTrimTime({ start: e.startTime, end: e.endTime });218 setPlay(false);219 }}220 />221 )}222 {Platform.OS === 'android' && ( */}223 <AppSlider224 style={style.sliderStyle}225 rangeSlider={true}226 min={0}227 max={videoFile.duration}228 selectedMin={trimTime.start}229 selectedMax={trimTime.end}230 step={1}231 onValueChanged={(low, high, _) => {232 if (233 trimTime.start !== parseInt(low) ||234 trimTime.end !== parseInt(high)235 ) {236 setTrimTime({ start: low, end: high });237 setPlay(false);238 }239 }}240 renderRail={() => (241 <View style={style.sliderRailContainer}>242 {videoThumbs.map(thumb => (243 <Image244 key={thumb.path}245 source={{ uri: thumb.path }}246 style={style.videoThumb}247 />248 ))}249 </View>250 )}251 renderRailSelected={() => (252 <View style={style.sliderRailSelectedContainer} />253 )}254 renderThumb={() => (255 <View style={style.sliderThumbContainer}>256 <View style={style.sliderThumbInside} />257 </View>258 )}259 />260 {/* )} */}261 </View>262 </View>263 </View>264 </View>265 </TouchableWithoutFeedback>266 </Layout>267 );268};...
encode.js
Source:encode.js
1const path = require("path");2const express = require("express");3const router = express.Router();4const upload = require("../config/multer");5const paths = require("../utils/utils");6const generateThumbnails = require("../services/generateThumbnails");7const { processVideo } = require("../services/ffmpeg");8const { killFFmpegProcess } = require("../services/ffmpeg");9router.post("/killffmpeg", (req, res) => {10 killFFmpegProcess()11 .then(() => res.json({ success: true }))12 .catch((e) => {13 res.status(500);14 res.json({ success: false, message: e.message });15 });16});17router.post("/upload", upload.single("file"), async (req, res) => {18 if (req.file) {19 const video = req.file;20 const uploadPath = video.path;21 const filename = video.filename;22 const thumbLocation = `${paths.basePath}/uploaded/${paths.thumb.folder}`;23 const thumbs = await generateThumbnails(24 uploadPath,25 path.parse(filename).name,26 thumbLocation,27 20,28 5029 );30 res.json({31 filename: filename,32 thumbs: thumbs,33 });34 } else {35 res.json({36 uploaded: false,37 });38 }39});40router.post("/encode", (req, res) => {41 if (req.body.filename) {42 const filename = path.parse(req.body.filename).name;43 const ext = path.parse(req.body.filename).ext;44 const vfOptions = req.body.vfOptions;45 const adjustOptions = req.body.adjustOptions;46 const trimTime = req.body.trimTime;47 const afOptions = req.body.afOptions;48 const zoomPanOptions = req.body.zoomPanOptions;49 const panOptions = req.body.panOptions;50 const outputFormat = req.body.outputFormat;51 const duration = {52 s: trimTime[1] - trimTime[0],53 ms: (trimTime[1] - trimTime[0]) * 1000,54 };55 const resultVideoPath = `server/public/converted/videos/${filename}.${outputFormat}`;56 const resultThumbPath = `server/public/converted/thumbs/`;57 processVideo(req, res, filename, ext, {58 afOptions: afOptions,59 vfOptions: vfOptions,60 trimTime: trimTime,61 duration: duration,62 adjustOptions: adjustOptions,63 zoomPanOptions: zoomPanOptions,64 panOptions: panOptions,65 outputFormat: outputFormat,66 })67 .then(() =>68 generateThumbnails(resultVideoPath, filename, resultThumbPath, 1, 320)69 )70 .then(() => {71 res.json({72 newVideoUrl: `download/video/${filename}.${outputFormat}`,73 newThumbUrl: `api/${paths.baseFolder}/${paths.thumb.folder}/${filename}.jpg`,74 });75 })76 .catch((e) => {77 console.error(e);78 res.status(500);79 res.json({ success: false });80 });81 } else {82 res.json({83 success: false,84 });85 }86});...
date.js
Source:date.js
...9}10export function addDays(date, days) {11 return new Date(new Date(date).getTime() + (days * DAY))12}13export function trimTime(date) {14 date = new Date(date)15 date.setMilliseconds(0)16 date.setSeconds(0)17 date.setMinutes(0)18 date.setHours(0)19 return date20}21const sameDateFormatter = date => {22 const diff = Date.now() - date.getTime()23 if (diff < MINUTE) {24 return Math.floor((diff / SECOND)) + ' Ñек. ÑомÑ'25 } else if (diff < HOUR) {26 return Math.floor((diff / MINUTE)) + ' Ñ
в. ÑомÑ'27 } else {28 return Math.floor((diff / HOUR)) + ' год. ÑомÑ'29 }30}31const yesterdayDateFormatter = time => {32 const hours = time.getHours()33 const min = time.getMinutes()34 return `вÑоÑа о ${hours}:${min}`35}36const beforeYesterdayDateFormatter = date => {37 const day = date.getDate() < 10 ? `0${date.getDate()}` : date.getDate()38 const month = date.getMonth() + 1 < 10 ? `0${date.getMonth() + 1}` : date.getMonth() + 139 const year = date.getFullYear()40 return `${day}.${month}.${year}`41}42const isSameDate = date => trimTime(date).getTime() === trimTime(Date.now()).getTime()43const isYesterdayDate = date => trimTime(date).getTime() === trimTime(addDays(Date.now(), -1)).getTime()44const isBeforeYesterdayDate = date => !isSameDate(date) && !isYesterdayDate(date)45const TIME_MARKERS = [46 {47 criteria : isSameDate,48 formatter: sameDateFormatter49 },50 {51 criteria : isYesterdayDate,52 formatter: yesterdayDateFormatter53 },54 {55 criteria : isBeforeYesterdayDate,56 formatter: beforeYesterdayDateFormatter57 }...
Using AI Code Generation
1require('argos/Utility').trimTime(myDate);2var Utility = require('argos/Utility');3Utility.trimTime(myDate);4var Utility = require('argos/Utility');5var trimTime = Utility.trimTime;6trimTime(myDate);7var Utility = require('argos/Utility');8var trimTime = Utility.trimTime;9trimTime(myDate);10var Utility = require('argos/Utility');11var trimTime = Utility.trimTime;12trimTime(myDate);13var Utility = require('argos/Utility');14var trimTime = Utility.trimTime;15trimTime(myDate);16var Utility = require('argos/Utility');17var trimTime = Utility.trimTime;18trimTime(myDate);19var Utility = require('argos/Utility');20var trimTime = Utility.trimTime;21trimTime(myDate);22var Utility = require('argos/Utility');23var trimTime = Utility.trimTime;24trimTime(myDate);25var Utility = require('argos/Utility');26var trimTime = Utility.trimTime;27trimTime(myDate);28var Utility = require('argos/Utility');29var trimTime = Utility.trimTime;30trimTime(myDate);31var Utility = require('argos/Utility');32var trimTime = Utility.trimTime;33trimTime(myDate);34var Utility = require('argos/Utility');
Using AI Code Generation
1define('test', ['argos/Utility'], function(Utility) {2 var trimmedTime = Utility.trimTime(new Date());3 console.log(trimmedTime);4});5require(['test'], function() {6});
Using AI Code Generation
1require('argos/Utility').trimTime('2012-10-10T00:00:00.000Z');2require('argos/Utility').trimTime('2012-10-10T00:00:00.000Z');3require('argos/Utility').trimTime('2012-10-10T00:00:00.000Z');4require('argos/Utility').trimTime('2012-10-10T00:00:00.000Z');5require('argos/Utility').trimTime('2012-10-10T00:00:00.000Z');6require('argos/Utility').trimTime('2012-10-10T00:00:00.000Z');7require('argos/Utility').trimTime('2012-10-10T00:00:00.000Z');8require('argos/Utility').trimTime('2012-10-10T00:00:00.000Z');9require('argos/Utility').trimTime('2012-10-10T00:00:00.000Z');10require('argos/Utility').trimTime('2012-10-10T00:00:00.000Z');11require('argos/Utility').trimTime('2012-10-10T00:00:00.000Z');
Using AI Code Generation
1require([2], function(Format) {3 var time = Format.trimTime(new Date());4 console.log(time);5});6require([7], function(Format) {8 var time = Format.trimTime(new Date());9 console.log(time);10});11require([12], function(Format) {13 var time = Format.trimTime(new Date());14 console.log(time);15});16require([17], function(Format) {18 var time = Format.trimTime(new Date());19 console.log(time);20});
Using AI Code Generation
1var argos = require('argos-sdk');2var date = new Date();3var date1 = argos.Utilities.trimTime(date);4console.log(date1);5var date2 = argos.Utilities.trimTime(date, true);6console.log(date2);7var date3 = argos.Utilities.trimTime(date, false, true);8console.log(date3);9var date4 = argos.Utilities.trimTime(date, true, true);10console.log(date4);11var argos = require('argos-sdk');12var date = new Date();13var date1 = argos.Utilities.trimTime(date);14console.log(date1);15var date2 = argos.Utilities.trimTime(date, true);16console.log(date2);17var date3 = argos.Utilities.trimTime(date, false, true);18console.log(date3);19var date4 = argos.Utilities.trimTime(date, true, true);20console.log(date4);21var date5 = argos.Utilities.trimTime(date, false, false);22console.log(date5);23var date6 = argos.Utilities.trimTime(date, true, false);24console.log(date6);25var date7 = argos.Utilities.trimTime(date, false, undefined);26console.log(date7);27var date8 = argos.Utilities.trimTime(date, true, undefined);28console.log(date8
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!