Ver código fonte

Initial commit

Add files from pridepack.
master
TheoryOfNekomata 1 ano atrás
commit
aacec086af
11 arquivos alterados com 3904 adições e 0 exclusões
  1. +10
    -0
      .eslintrc
  2. +110
    -0
      .gitignore
  3. +7
    -0
      LICENSE
  4. +66
    -0
      package.json
  5. +3
    -0
      pridepack.json
  6. +57
    -0
      src/index.ts
  7. +22
    -0
      test/index.test.ts
  8. +11
    -0
      test/try-service.js
  9. +21
    -0
      tsconfig.eslint.json
  10. +21
    -0
      tsconfig.json
  11. +3576
    -0
      yarn.lock

+ 10
- 0
.eslintrc Ver arquivo

@@ -0,0 +1,10 @@
{
"root": true,
"ignorePatterns": ["**/*.js"],
"extends": [
"lxsmnsyc/typescript"
],
"parserOptions": {
"project": "./tsconfig.eslint.json"
}
}

+ 110
- 0
.gitignore Ver arquivo

@@ -0,0 +1,110 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# TypeScript v1 declaration files
typings/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env
.env.production
.env.development

# parcel-bundler cache (https://parceljs.org/)
.cache

# Next.js build output
.next

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and *not* Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port

.npmrc
vendor
test/*.webm
.idea/

+ 7
- 0
LICENSE Ver arquivo

@@ -0,0 +1,7 @@
MIT License Copyright (c) 2023 TheoryOfNekomata <allan.crisostomo@outlook.com>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice (including the next paragraph) shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

+ 66
- 0
package.json Ver arquivo

@@ -0,0 +1,66 @@
{
"name": "youtube-clip-core",
"version": "0.0.0",
"files": [
"dist",
"src"
],
"engines": {
"node": ">=10"
},
"license": "MIT",
"keywords": [
"pridepack"
],
"devDependencies": {
"@types/node": "^18.14.1",
"eslint": "^8.35.0",
"eslint-config-lxsmnsyc": "^0.5.0",
"pridepack": "2.4.2",
"tslib": "^2.5.0",
"typescript": "^4.9.5",
"vitest": "^0.28.1"
},
"scripts": {
"prepublishOnly": "pridepack clean && pridepack build",
"build": "pridepack build",
"type-check": "pridepack check",
"lint": "pridepack lint",
"clean": "pridepack clean",
"watch": "pridepack watch",
"start": "pridepack start",
"dev": "pridepack dev",
"test": "vitest"
},
"private": false,
"description": "Clip YouTube videos.",
"repository": {
"url": "https://code.modal.sh/TheoryOfNekomata/youtube-clip-core",
"type": "git"
},
"homepage": "https://code.modal.sh/TheoryOfNekomata/youtube-clip-core",
"bugs": {
"url": "https://code.modal.sh/TheoryOfNekomata/youtube-clip-core/issues"
},
"author": "TheoryOfNekomata <allan.crisostomo@outlook.com>",
"publishConfig": {
"access": "public"
},
"types": "./dist/types/index.d.ts",
"main": "./dist/cjs/production/index.js",
"module": "./dist/esm/production/index.js",
"exports": {
".": {
"development": {
"require": "./dist/cjs/development/index.js",
"import": "./dist/esm/development/index.js"
},
"require": "./dist/cjs/production/index.js",
"import": "./dist/esm/production/index.js",
"types": "./dist/types/index.d.ts"
}
},
"typesVersions": {
"*": {}
}
}

+ 3
- 0
pridepack.json Ver arquivo

@@ -0,0 +1,3 @@
{
"target": "es2018"
}

+ 57
- 0
src/index.ts Ver arquivo

@@ -0,0 +1,57 @@
import * as childProcess from 'child_process';
import { unlinkSync, readFileSync } from 'fs';

export enum VideoType {
YOUTUBE = 'youtube',
}

interface ClipVideoBaseParams {
url: string,
start: number | string,
end: number | string,
ffmpegExecutablePath?: string;
}

interface ClipYouTubeVideoParams extends ClipVideoBaseParams {
downloaderExecutablePath?: string;
}

interface ClipVideoParams extends ClipYouTubeVideoParams {
type: VideoType,
}

const clipYouTubeVideo = (params: ClipYouTubeVideoParams) => {
if (!params.downloaderExecutablePath) {
throw new Error('Downloader not found.');
}
if (!params.ffmpegExecutablePath) {
throw new Error('ffmpeg not found.');
}
childProcess.spawnSync(params.downloaderExecutablePath, [params.url, '-o', 'input.webm']);
childProcess.spawnSync(params.ffmpegExecutablePath, ['-ss', params.start.toString(), '-t', params.end.toString(), '-i', 'input.webm', 'output.webm']);
unlinkSync('input.webm');
const output = readFileSync('output.webm');
unlinkSync('output.webm');
return output;
};

export const clipVideo = (params: ClipVideoParams) => {
const {
type: videoType, url, start, end,
} = params;

switch (videoType as string) {
case VideoType.YOUTUBE:
return clipYouTubeVideo({
ffmpegExecutablePath: process.env.FFMPEG_EXECUTABLE_PATH,
downloaderExecutablePath: process.env.YOUTUBE_DOWNLOADER_EXECUTABLE_PATH,
url,
start,
end,
});
default:
break;
}

throw new TypeError(`Invalid video type: "${videoType}". Valid values are: ${JSON.stringify(Object.values(VideoType))}`);
};

+ 22
- 0
test/index.test.ts Ver arquivo

@@ -0,0 +1,22 @@
import {
describe, it, expect, vi,
} from 'vitest';
import * as childProcess from 'child_process';
import * as youtubeClipCore from '../src';

vi.mock('child_process', () => ({
spawnSync: vi.fn(),
}));

describe('clipVideo', () => {
it('works', () => {
youtubeClipCore.clipVideo({
type: youtubeClipCore.VideoType.YOUTUBE,
url: 'https://www.youtube.com/watch?v=BaW_jenozKc',
start: 0,
end: 0,
});

expect(childProcess.spawnSync).toBeCalledTimes(2);
});
});

+ 11
- 0
test/try-service.js Ver arquivo

@@ -0,0 +1,11 @@
const { clipVideo, VideoType } = require('../dist/cjs/development');
const fs = require('fs');

const clippedVideoBuffer = clipVideo({
type: VideoType.YOUTUBE,
url: 'https://www.youtube.com/watch?v=BaW_jenozKc',
start: 0,
end: 1,
});

fs.writeFileSync('output.webm', clippedVideoBuffer);

+ 21
- 0
tsconfig.eslint.json Ver arquivo

@@ -0,0 +1,21 @@
{
"exclude": ["node_modules"],
"include": ["src", "types", "test"],
"compilerOptions": {
"module": "ESNext",
"lib": ["ESNext"],
"importHelpers": true,
"declaration": true,
"sourceMap": true,
"rootDir": "./",
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"moduleResolution": "node",
"jsx": "react",
"esModuleInterop": true,
"target": "es2018"
}
}

+ 21
- 0
tsconfig.json Ver arquivo

@@ -0,0 +1,21 @@
{
"exclude": ["node_modules"],
"include": ["src", "types"],
"compilerOptions": {
"module": "ESNext",
"lib": ["ESNext"],
"importHelpers": true,
"declaration": true,
"sourceMap": true,
"rootDir": "./src",
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"moduleResolution": "node",
"jsx": "react",
"esModuleInterop": true,
"target": "es2018"
}
}

+ 3576
- 0
yarn.lock
Diferenças do arquivo suprimidas por serem muito extensas
Ver arquivo


Carregando…
Cancelar
Salvar