Skip to content

Commit 87af463

Browse files
committed
feat: Added json output to subtitles
1 parent ebac9ac commit 87af463

File tree

4 files changed

+44
-51
lines changed

4 files changed

+44
-51
lines changed

README.md

+2-34
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,6 @@
44
Popcorn env
55
</h1>
66

7-
<div align="center">
8-
<a target="_blank" href="https://gitter.im/pct-org/Lobby">
9-
<img src="https://badges.gitter.im/popcorn-time-desktop.svg" alt="Gitter" />
10-
</a>
11-
</div>
12-
13-
---
14-
157
This repo holds everything you need (except the [app]) to run the PCT environment.
168

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

60-
## Installation
61-
62-
### Platforms
63-
64-
There is a installation scripts available to help install everything you need to run on a certain platform, scripts that are available:
65-
- [raspberry-pi](./docs/run-on.raspberry-pi.md)
66-
67-
Click on the links to ge more info on how to run on those platforms.
68-
69-
### Manual installation
52+
## How to run this
7053

71-
> TODO
72-
73-
Last step is to copy the `ecosystem.config.example.js` to `ecosystem.config.js` file and fill it in.
74-
75-
## Starting the project (PM2)
76-
77-
```shell script
78-
# To start the APIs (Scraper will immediately start scraping)
79-
$ yarn start:prod
80-
81-
# To stop the APIs
82-
$ yarn stop:prod
83-
84-
# To delete the PM2 apps
85-
$ yarn delete:prod
86-
```
54+
See the [docs](#) for more information on how to run this project.
8755

8856
## Contributing:
8957

apps/api/src/subtitle/subtitle.controller.ts

+36-17
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import * as path from 'path'
22
import * as fs from 'fs'
3-
import { Controller, Get, Res, Req, Param, Logger, Inject } from '@nestjs/common'
3+
import { Controller, Get, Res, Req, Param, Logger, Inject, Query } from '@nestjs/common'
44
import * as srtToVtt from 'srt-to-vtt'
5+
import * as subsrt from 'subsrt'
56

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

@@ -17,7 +18,8 @@ export class SubtitleController {
1718
public subtitle(
1819
@Param() params,
1920
@Res() res,
20-
@Req() req
21+
@Req() req,
22+
@Query('output') output = 'vtt'
2123
) {
2224
this.logger.debug(`[${params._id}]: Get subtitle with code "${params.code}"`)
2325

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

32+
if (!fs.existsSync(subtitleFile)) {
33+
res.status(404)
34+
35+
return res.send('File not found!')
36+
}
37+
38+
if (output === 'json') {
39+
res.status(200)
40+
res.headers({
41+
'access-control-allow-origin': '*',
42+
'Content-Type': 'application/json; charset=utf-8'
43+
})
44+
45+
return res.send(
46+
subsrt.convert(
47+
fs.readFileSync(subtitleFile, 'utf8'),
48+
{ format: 'json' }
49+
)
50+
)
51+
}
52+
3053
const { size } = fs.statSync(subtitleFile)
3154

3255
let streamOptions = null
3356

3457
res.status(200)
3558
res.headers({
3659
'access-control-allow-origin': '*',
37-
'Content-Type': 'text/vtt; charset=utf-8',
60+
'Content-Type': 'text/vtt; charset=utf-8'
3861
})
3962

4063
// If we have range then we need to start somewhere else
@@ -66,22 +89,18 @@ export class SubtitleController {
6689
}
6790
}
6891

69-
res.send(
70-
fs.createReadStream(
71-
subtitleFile,
72-
streamOptions
73-
).pipe(srtToVtt())
92+
const readStream = fs.createReadStream(
93+
subtitleFile,
94+
streamOptions
7495
)
7596

76-
// res.send(
77-
// createReadStream(
78-
// path.resolve(
79-
// this.configService.get(ConfigService.DOWNLOAD_LOCATION),
80-
// params._id,
81-
// `${params.code}.vtt`
82-
// )
83-
// )
84-
// )
97+
if (output === 'vtt') {
98+
return res.send(
99+
readStream.pipe(srtToVtt())
100+
)
101+
}
102+
103+
res.send(readStream)
85104
}
86105

87106
}

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
"rimraf": "3.0.2",
8484
"rxjs": "6.6.3",
8585
"srt-to-vtt": "^1.1.3",
86+
"subsrt": "^1.1.1",
8687
"tmdb": "^2.6.0",
8788
"trakt.tv": "^8.0.0",
8889
"url": "^0.11.0",

yarn.lock

+5
Original file line numberDiff line numberDiff line change
@@ -11858,6 +11858,11 @@ subscriptions-transport-ws@^0.9.11:
1185811858
symbol-observable "^1.0.4"
1185911859
ws "^5.2.0"
1186011860

11861+
subsrt@^1.1.1:
11862+
version "1.1.1"
11863+
resolved "https://registry.yarnpkg.com/subsrt/-/subsrt-1.1.1.tgz#079bc83921feb46e05319a3ff9a13bef08a8d388"
11864+
integrity sha512-F15pSRRrPYnLjDKohcwkUUGhgHH+0IqpCoznMHMibZI9a2qN3ya/p3Xp/7zFOPvwez9b/qFjwtOnyS7f7d/MNw==
11865+
1186111866
supports-color@^2.0.0:
1186211867
version "2.0.0"
1186311868
resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-2.0.0.tgz#535d045ce6b6363fa40117084629995e9df324c7"

0 commit comments

Comments
 (0)