mirror of
https://github.com/Ernous/TorrServerJellyfin.git
synced 2025-12-19 13:36:09 +05:00
added function to trim redundant {,[,( symbols if there is no closing brackets
This commit is contained in:
@@ -8,7 +8,8 @@
|
||||
> `http://192.168.78.4:8090` - correct
|
||||
>
|
||||
> `http://192.168.78.4:8090/` - wrong
|
||||
3. `yarn start`
|
||||
3. in `.env` file add TMDB api key
|
||||
4. `yarn start`
|
||||
|
||||
### Eslint
|
||||
> Prettier will fix the code every time the code is saved
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
import { playlistAllHost } from 'utils/Hosts'
|
||||
import Divider from '@material-ui/core/Divider'
|
||||
import ListItem from '@material-ui/core/ListItem'
|
||||
import ListItemIcon from '@material-ui/core/ListItemIcon'
|
||||
import ListItemText from '@material-ui/core/ListItemText'
|
||||
import { CreditCard as CreditCardIcon, List as ListIcon, Language as LanguageIcon } from '@material-ui/icons'
|
||||
import { CreditCard as CreditCardIcon, Language as LanguageIcon } from '@material-ui/icons'
|
||||
import List from '@material-ui/core/List'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import useChangeLanguage from 'utils/useChangeLanguage'
|
||||
@@ -24,12 +23,6 @@ export default function Sidebar({ isDrawerOpen, setIsDonationDialogOpen }) {
|
||||
<List>
|
||||
<AddDialogButton />
|
||||
<RemoveAll />
|
||||
<ListItem button component='a' target='_blank' href={playlistAllHost()}>
|
||||
<ListItemIcon>
|
||||
<ListIcon />
|
||||
</ListItemIcon>
|
||||
<ListItemText primary={t('PlaylistAll')} />
|
||||
</ListItem>
|
||||
</List>
|
||||
|
||||
<Divider />
|
||||
@@ -37,20 +30,25 @@ export default function Sidebar({ isDrawerOpen, setIsDonationDialogOpen }) {
|
||||
<List>
|
||||
<SettingsDialog />
|
||||
|
||||
<ListItem button onClick={() => (currentLang === 'en' ? changeLang('ru') : changeLang('en'))}>
|
||||
<ListItemIcon>
|
||||
<LanguageIcon />
|
||||
</ListItemIcon>
|
||||
<ListItemText primary={t('ChooseLanguage')} />
|
||||
</ListItem>
|
||||
|
||||
<AboutDialog />
|
||||
<CloseServer />
|
||||
</List>
|
||||
|
||||
<Divider />
|
||||
|
||||
<List>
|
||||
<ListItem button onClick={() => (currentLang === 'en' ? changeLang('ru') : changeLang('en'))}>
|
||||
<ListItemIcon>
|
||||
<LanguageIcon />
|
||||
</ListItemIcon>
|
||||
<ListItemText primary={t('ChooseLanguage')} />
|
||||
</ListItem>
|
||||
</List>
|
||||
|
||||
<Divider />
|
||||
|
||||
<List>
|
||||
<AboutDialog />
|
||||
|
||||
<ListItem button onClick={() => setIsDonationDialogOpen(true)}>
|
||||
<ListItemIcon>
|
||||
<CreditCardIcon />
|
||||
|
||||
Binary file not shown.
@@ -1,5 +1,5 @@
|
||||
import { NoImageIcon } from 'icons'
|
||||
import { humanizeSize } from 'utils/Utils'
|
||||
import { humanizeSize, removeRedundantCharacters } from 'utils/Utils'
|
||||
import { useEffect, useState } from 'react'
|
||||
import { Button, ButtonGroup } from '@material-ui/core'
|
||||
import ptt from 'parse-torrent-title'
|
||||
@@ -102,21 +102,27 @@ export default function DialogTorrentDetailsContent({ closeDialog, torrent }) {
|
||||
const bufferSize = settings?.PreloadBuffer ? Capacity : 33554432 // Default is 32mb if PreloadBuffer is false
|
||||
|
||||
const getParsedTitle = () => {
|
||||
const newNameStrings = []
|
||||
const newNameStringArr = []
|
||||
|
||||
const torrentParsedName = name && ptt.parse(name)
|
||||
|
||||
if (title !== name) {
|
||||
newNameStrings.push(title)
|
||||
} else if (torrentParsedName?.title) newNameStrings.push(torrentParsedName?.title)
|
||||
newNameStringArr.push(removeRedundantCharacters(title))
|
||||
} else if (torrentParsedName?.title) newNameStringArr.push(torrentParsedName?.title)
|
||||
|
||||
// These 2 checks are needed to get year and resolution from torrent name if title does not have this info
|
||||
if (torrentParsedName?.year && !title.includes(torrentParsedName?.year))
|
||||
newNameStrings.push(torrentParsedName?.year)
|
||||
newNameStringArr.push(torrentParsedName?.year)
|
||||
if (torrentParsedName?.resolution && !title.includes(torrentParsedName?.resolution))
|
||||
newNameStrings.push(torrentParsedName?.resolution)
|
||||
newNameStringArr.push(torrentParsedName?.resolution)
|
||||
|
||||
return newNameStrings.join('. ')
|
||||
const newNameString = newNameStringArr.join('. ')
|
||||
|
||||
// removeRedundantCharacters is returning ".." if it was "..."
|
||||
const lastDotShouldBeAdded =
|
||||
newNameString[newNameString.length - 1] === '.' && newNameString[newNameString.length - 2] === '.'
|
||||
|
||||
return lastDotShouldBeAdded ? `${newNameString}.` : newNameString
|
||||
}
|
||||
|
||||
return (
|
||||
|
||||
@@ -6,7 +6,7 @@ import {
|
||||
Close as CloseIcon,
|
||||
Delete as DeleteIcon,
|
||||
} from '@material-ui/icons'
|
||||
import { getPeerString, humanizeSize } from 'utils/Utils'
|
||||
import { getPeerString, humanizeSize, removeRedundantCharacters } from 'utils/Utils'
|
||||
import { torrentsHost } from 'utils/Hosts'
|
||||
import { NoImageIcon } from 'icons'
|
||||
import DialogTorrentDetailsContent from 'components/DialogTorrentDetailsContent'
|
||||
@@ -45,7 +45,7 @@ const Torrent = ({ torrent }) => {
|
||||
|
||||
const titleStrings = []
|
||||
|
||||
let parsedTitle = parse('title')
|
||||
let parsedTitle = removeRedundantCharacters(parse('title'))
|
||||
const parsedYear = parse('year')
|
||||
const parsedResolution = parse('resolution')
|
||||
if (parsedTitle) titleStrings.push(parsedTitle)
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
"Cache": "Cache",
|
||||
"CacheSize": "Cache Size (Megabytes)",
|
||||
"Cancel": "Cancel",
|
||||
"ChooseLanguage": "Russian",
|
||||
"ChooseLanguage": "Ru",
|
||||
"Clear": "Clear",
|
||||
"Close": "Close",
|
||||
"CloseServer?": "Do you want to turn off server?",
|
||||
@@ -59,12 +59,11 @@
|
||||
"Offline": "Offline",
|
||||
"OK": "OK",
|
||||
"OpenLink": "Open link",
|
||||
"Peers": "[Connected] Peers",
|
||||
"Peers": "Peers",
|
||||
"PeersListenPort": "Peers Listen Port",
|
||||
"PEX": "PEX (Peer Exchange)",
|
||||
"PiecesCount": "Pieces count",
|
||||
"PiecesLength": "Pieces length",
|
||||
"PlaylistAll": "Playlist All",
|
||||
"Preload": "Preload",
|
||||
"PreloadBuffer": "Preload Buffer",
|
||||
"ReaderReadAHead": "Reader Read Ahead (5-100%)",
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
"Cache": "Кеш",
|
||||
"CacheSize": "Размер кеша (Мегабайты)",
|
||||
"Cancel": "Отмена",
|
||||
"ChooseLanguage": "Английский",
|
||||
"ChooseLanguage": "En",
|
||||
"Clear": "Очистить",
|
||||
"Close": "Закрыть",
|
||||
"CloseServer?": "Хотите выключить сервер?",
|
||||
@@ -59,12 +59,11 @@
|
||||
"Offline": "Сервер не доступен",
|
||||
"OK": "OK",
|
||||
"OpenLink": "Открыть",
|
||||
"Peers": "[Подкл.] Пиры",
|
||||
"Peers": "Пиры",
|
||||
"PeersListenPort": "Порт для входящих подключений",
|
||||
"PEX": "PEX (Peer Exchange)",
|
||||
"PiecesCount": "Кол-во блоков",
|
||||
"PiecesLength": "Размер блока",
|
||||
"PlaylistAll": "Плейлист всех",
|
||||
"Preload": "Предзагр.",
|
||||
"PreloadBuffer": "Наполнять кеш перед началом воспроизведения",
|
||||
"ReaderReadAHead": "Кеш предзагрузки (5-100%, рек. 95%)",
|
||||
|
||||
@@ -10,7 +10,6 @@ export const settingsHost = () => `${torrserverHost}/settings`
|
||||
export const streamHost = () => `${torrserverHost}/stream`
|
||||
export const shutdownHost = () => `${torrserverHost}/shutdown`
|
||||
export const echoHost = () => `${torrserverHost}/echo`
|
||||
export const playlistAllHost = () => `${torrserverHost}/playlistall/all.m3u`
|
||||
export const playlistTorrHost = () => `${torrserverHost}/stream`
|
||||
|
||||
export const getTorrServerHost = () => torrserverHost
|
||||
|
||||
@@ -11,3 +11,33 @@ export function getPeerString(torrent) {
|
||||
|
||||
export const shortenText = (text, sympolAmount) =>
|
||||
text ? text.slice(0, sympolAmount) + (text.length > sympolAmount ? '…' : '') : ''
|
||||
|
||||
export const removeRedundantCharacters = string => {
|
||||
let newString = string
|
||||
const brackets = [
|
||||
['(', ')'],
|
||||
['[', ']'],
|
||||
['{', '}'],
|
||||
]
|
||||
|
||||
brackets.forEach(el => {
|
||||
const leftBracketRegexFormula = `\\${el[0]}`
|
||||
const leftBracketRegex = new RegExp(leftBracketRegexFormula, 'g')
|
||||
const leftBracketAmount = [...newString.matchAll(leftBracketRegex)].length
|
||||
const rightBracketRegexFormula = `\\${el[1]}`
|
||||
const rightBracketRegex = new RegExp(rightBracketRegexFormula, 'g')
|
||||
const rightBracketAmount = [...newString.matchAll(rightBracketRegex)].length
|
||||
|
||||
if (leftBracketAmount !== rightBracketAmount) {
|
||||
const removeFormula = `(\\${el[0]})(?!.*\\1).*`
|
||||
const removeRegex = new RegExp(removeFormula, 'g')
|
||||
newString = newString.replace(removeRegex, '')
|
||||
}
|
||||
})
|
||||
|
||||
const hasThreeDotsAtTheEnd = !!newString.match(/\.{3}$/g)
|
||||
|
||||
const trimmedString = newString.replace(/[\\.| ]+$/g, '').trim()
|
||||
|
||||
return hasThreeDotsAtTheEnd ? `${trimmedString}..` : trimmedString
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user