From 2e300a9964bc1fe99bfbe8f8ae4c8b95cb1db037 Mon Sep 17 00:00:00 2001 From: Ted Kulp Date: Wed, 4 Aug 2021 15:10:32 -0400 Subject: [PATCH] Fix bookmarklet. Update docs and ports --- .dockerignore | 4 + Dockerfile | 12 +++ LICENSE | 19 +++++ README.md | 115 ++++++--------------------- apps/api/src/config/configuration.ts | 1 + apps/api/src/web/web.controller.ts | 6 +- docker-compose.yml | 19 +++++ 7 files changed, 82 insertions(+), 94 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 LICENSE create mode 100644 docker-compose.yml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..3ec3a0c --- /dev/null +++ b/.dockerignore @@ -0,0 +1,4 @@ +dist +node_modules +downloads +.next \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..4e662fe --- /dev/null +++ b/Dockerfile @@ -0,0 +1,12 @@ +FROM node + +COPY package.json package.json +COPY package-lock.json package-lock.json + +RUN npm install + +COPY . . + +RUN npm run build + +CMD [ "npm", "run", "prod" ] diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..8a3cb26 --- /dev/null +++ b/LICENSE @@ -0,0 +1,19 @@ +Copyright 2021 Ted Kulp + +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 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. \ No newline at end of file diff --git a/README.md b/README.md index be02a38..2306467 100644 --- a/README.md +++ b/README.md @@ -1,105 +1,36 @@ +[![Docker Stars Shield](https://img.shields.io/docker/stars/tedkulp/vidgrab.svg?style=flat-square)](https://hub.docker.com/r/tedkulp/vidgrab/) +[![Docker Pulls Shield](https://img.shields.io/docker/pulls/tedkulp/vidgrab.svg?style=flat-square)](https://hub.docker.com/r/tedkulp/vidgrab/) +[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)](https://raw.githubusercontent.com/tedkulp/vidgrab/master/LICENSE) +# Vidgrab -# Vidgrab2 +Simple web interface to download videos with [youtube-dl](https://github.com/ytdl-org/youtube-dl) and store them on your server. Written in Typescript using [nest.js](https://nestjs.com). -This project was generated using [Nx](https://nx.dev). +![screenshot](img/screenshot.png) -

+## Setup -🔎 **Smart, Extensible Build Framework** +Vidgrab was written assuming that Docker would be used to deploy it. It requires redis for it's queuing functionality. -## Quick Start & Documentation +### Docker CLI -[Nx Documentation](https://nx.dev/angular) +```shell +docker run -d --name vidgrab -E FILE_DIR=/vidgrab -v /vidgrab:/vidgrab -p 4200:4200 tedkulp/vidgrab +``` -[10-minute video showing all Nx features](https://nx.dev/getting-started/intro) +### Docker Compose -[Interactive Tutorial](https://nx.dev/tutorial/01-create-application) +There is an example docker-compose.yml file [included](https://raw.githubusercontent.com/tedkulp/vidgrab/master/docker-compose.yml) in the repo. Use that directly to get a site running on port 3000 or modify to taste. -## Adding capabilities to your workspace +### Environment Variables -Nx supports many plugins which add capabilities for developing different types of applications and different tools. +| Name | Default Value | Description | +| ---------- | --------------------- | -------------------------------------- | +| REDIS_HOST | localhost | Hostname of the redis server | +| REDIS_PORT | 6379 | Port to connect to for redis server | +| FILE_DIR | /tmp | Directory to store downloads | +| SITE_URL | http://localhost:4200 | URL to the site. Used for bookmarklet. | -These capabilities include generating applications, libraries, etc as well as the devtools to test, and build projects as well. +## License -Below are our core plugins: - -- [Angular](https://angular.io) - - `ng add @nrwl/angular` -- [React](https://reactjs.org) - - `ng add @nrwl/react` -- Web (no framework frontends) - - `ng add @nrwl/web` -- [Nest](https://nestjs.com) - - `ng add @nrwl/nest` -- [Express](https://expressjs.com) - - `ng add @nrwl/express` -- [Node](https://nodejs.org) - - `ng add @nrwl/node` - -There are also many [community plugins](https://nx.dev/community) you could add. - -## Generate an application - -Run `ng g @nrwl/angular:app my-app` to generate an application. - -> You can use any of the plugins above to generate applications as well. - -When using Nx, you can create multiple applications and libraries in the same workspace. - -## Generate a library - -Run `ng g @nrwl/angular:lib my-lib` to generate a library. - -> You can also use any of the plugins above to generate libraries as well. - -Libraries are shareable across libraries and applications. They can be imported from `@vidgrab2/mylib`. - -## Development server - -Run `ng serve my-app` for a dev server. Navigate to http://localhost:4200/. The app will automatically reload if you change any of the source files. - -## Code scaffolding - -Run `ng g component my-component --project=my-app` to generate a new component. - -## Build - -Run `ng build my-app` to build the project. The build artifacts will be stored in the `dist/` directory. Use the `--prod` flag for a production build. - -## Running unit tests - -Run `ng test my-app` to execute the unit tests via [Jest](https://jestjs.io). - -Run `nx affected:test` to execute the unit tests affected by a change. - -## Running end-to-end tests - -Run `ng e2e my-app` to execute the end-to-end tests via [Cypress](https://www.cypress.io). - -Run `nx affected:e2e` to execute the end-to-end tests affected by a change. - -## Understand your workspace - -Run `nx dep-graph` to see a diagram of the dependencies of your projects. - -## Further help - -Visit the [Nx Documentation](https://nx.dev/angular) to learn more. - - - - - - -## ☁ Nx Cloud - -### Distributed Computation Caching & Distributed Task Execution - -

- -Nx Cloud pairs with Nx in order to enable you to build and test code more rapidly, by up to 10 times. Even teams that are new to Nx can connect to Nx Cloud and start saving time instantly. - -Teams using Nx gain the advantage of building full-stack applications with their preferred framework alongside Nx’s advanced code generation and project dependency graph, plus a unified experience for both frontend and backend developers. - -Visit [Nx Cloud](https://nx.app/) to learn more. +This software is available under the [MIT License](https://opensource.org/licenses/MIT). diff --git a/apps/api/src/config/configuration.ts b/apps/api/src/config/configuration.ts index 9275765..4f78549 100644 --- a/apps/api/src/config/configuration.ts +++ b/apps/api/src/config/configuration.ts @@ -4,4 +4,5 @@ export default () => ({ ? parseInt(process.env.REDIS_PORT, 10) : 6379, fileDir: process.env.FILE_DIR || '/tmp', + siteUrl: process.env.SITE_URL || 'http://localhost:4200', }); diff --git a/apps/api/src/web/web.controller.ts b/apps/api/src/web/web.controller.ts index 0e964ef..93a6d63 100644 --- a/apps/api/src/web/web.controller.ts +++ b/apps/api/src/web/web.controller.ts @@ -14,6 +14,7 @@ import { ValidationPipe, } from '@nestjs/common'; import { EventEmitter2 } from '@nestjs/event-emitter'; +import { ConfigService } from '@nestjs/config'; import { Queue } from 'bull'; import { pick, trimEnd } from 'lodash'; @@ -28,18 +29,19 @@ export class WebController { @InjectQueue('vidgrab') private readonly vidgrabQueue: Queue, private readonly ytdlService: YtdlService, private readonly eventEmitter: EventEmitter2, + private readonly configService: ConfigService, ) {} @Get('/info') // @Render('Index') // eslint-disable-next-line @typescript-eslint/no-explicit-any async root(@Req() request: any) { - const fullUrl = + const fullUrl = this.configService.get('siteUrl') || request.protocol + '://' + request.get('host') + request.originalUrl; const bookmarklet = `javascript:(function(){var xhr=new XMLHttpRequest();xhr.open('POST',encodeURI('${trimEnd( fullUrl, '/', - )}/queue'));xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');xhr.send('url='+document.location.href.replace(/ /g,'+'));}());`; + )}'));xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');xhr.send('url='+document.location.href.replace(/ /g,'+'));}());`; const jobs = await this.vidgrabQueue.getJobs([ 'completed', diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..bd8fb6b --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,19 @@ +version: '3' +services: + redis: + image: redis + restart: unless-stopped + ports: + - 6379:6379 + vidgrab: + # image: tedkulp/vidgrab + build: . + restart: unless-stopped + environment: + - REDIS_HOST=redis + - FILE_DIR=/downloads + - SITE_URL=http://localhost:4200 + ports: + - 4200:4200 + volumes: + - ${PWD}/downloads:/downloads