Skip to content

Commit

Permalink
feat: Added json output to subtitles
Browse files Browse the repository at this point in the history
  • Loading branch information
TriPSs committed Dec 10, 2020
1 parent ebac9ac commit 87af463
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 51 deletions.
36 changes: 2 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,6 @@
Popcorn env
</h1>

<div align="center">
<a target="_blank" href="https://gitter.im/pct-org/Lobby">
<img src="https://badges.gitter.im/popcorn-time-desktop.svg" alt="Gitter" />
</a>
</div>

---

This repo holds everything you need (except the [app]) to run the PCT environment.

## In this repo
Expand Down Expand Up @@ -57,33 +49,9 @@ This repo holds everything you need (except the [app]) to run the PCT environmen
└── show #
```

## Installation

### Platforms

There is a installation scripts available to help install everything you need to run on a certain platform, scripts that are available:
- [raspberry-pi](./docs/run-on.raspberry-pi.md)

Click on the links to ge more info on how to run on those platforms.

### Manual installation
## How to run this

> TODO
Last step is to copy the `ecosystem.config.example.js` to `ecosystem.config.js` file and fill it in.

## Starting the project (PM2)

```shell script
# To start the APIs (Scraper will immediately start scraping)
$ yarn start:prod

# To stop the APIs
$ yarn stop:prod

# To delete the PM2 apps
$ yarn delete:prod
```
See the [docs](#) for more information on how to run this project.

## Contributing:

Expand Down
53 changes: 36 additions & 17 deletions apps/api/src/subtitle/subtitle.controller.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import * as path from 'path'
import * as fs from 'fs'
import { Controller, Get, Res, Req, Param, Logger, Inject } from '@nestjs/common'
import { Controller, Get, Res, Req, Param, Logger, Inject, Query } from '@nestjs/common'
import * as srtToVtt from 'srt-to-vtt'
import * as subsrt from 'subsrt'

import { ConfigService } from '../shared/config/config.service'

Expand All @@ -17,7 +18,8 @@ export class SubtitleController {
public subtitle(
@Param() params,
@Res() res,
@Req() req
@Req() req,
@Query('output') output = 'vtt'
) {
this.logger.debug(`[${params._id}]: Get subtitle with code "${params.code}"`)

Expand All @@ -27,14 +29,35 @@ export class SubtitleController {
`${params.code}.srt`
)

if (!fs.existsSync(subtitleFile)) {
res.status(404)

return res.send('File not found!')
}

if (output === 'json') {
res.status(200)
res.headers({
'access-control-allow-origin': '*',
'Content-Type': 'application/json; charset=utf-8'
})

return res.send(
subsrt.convert(
fs.readFileSync(subtitleFile, 'utf8'),
{ format: 'json' }
)
)
}

const { size } = fs.statSync(subtitleFile)

let streamOptions = null

res.status(200)
res.headers({
'access-control-allow-origin': '*',
'Content-Type': 'text/vtt; charset=utf-8',
'Content-Type': 'text/vtt; charset=utf-8'
})

// If we have range then we need to start somewhere else
Expand Down Expand Up @@ -66,22 +89,18 @@ export class SubtitleController {
}
}

res.send(
fs.createReadStream(
subtitleFile,
streamOptions
).pipe(srtToVtt())
const readStream = fs.createReadStream(
subtitleFile,
streamOptions
)

// res.send(
// createReadStream(
// path.resolve(
// this.configService.get(ConfigService.DOWNLOAD_LOCATION),
// params._id,
// `${params.code}.vtt`
// )
// )
// )
if (output === 'vtt') {
return res.send(
readStream.pipe(srtToVtt())
)
}

res.send(readStream)
}

}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
"rimraf": "3.0.2",
"rxjs": "6.6.3",
"srt-to-vtt": "^1.1.3",
"subsrt": "^1.1.1",
"tmdb": "^2.6.0",
"trakt.tv": "^8.0.0",
"url": "^0.11.0",
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11858,6 +11858,11 @@ subscriptions-transport-ws@^0.9.11:
symbol-observable "^1.0.4"
ws "^5.2.0"

subsrt@^1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/subsrt/-/subsrt-1.1.1.tgz#079bc83921feb46e05319a3ff9a13bef08a8d388"
integrity sha512-F15pSRRrPYnLjDKohcwkUUGhgHH+0IqpCoznMHMibZI9a2qN3ya/p3Xp/7zFOPvwez9b/qFjwtOnyS7f7d/MNw==

supports-color@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-2.0.0.tgz#535d045ce6b6363fa40117084629995e9df324c7"
Expand Down

0 comments on commit 87af463

Please sign in to comment.