mirror of
https://github.com/Ernous/TorrServerJellyfin.git
synced 2025-12-19 21:46:11 +05:00
refactor
This commit is contained in:
@@ -12,12 +12,10 @@ import useChangeLanguage from 'utils/useChangeLanguage'
|
|||||||
import { Cancel as CancelIcon } from '@material-ui/icons'
|
import { Cancel as CancelIcon } from '@material-ui/icons'
|
||||||
import { useDropzone } from 'react-dropzone'
|
import { useDropzone } from 'react-dropzone'
|
||||||
import { useMediaQuery } from '@material-ui/core'
|
import { useMediaQuery } from '@material-ui/core'
|
||||||
import parseTorrent from 'parse-torrent'
|
|
||||||
import ptt from 'parse-torrent-title'
|
|
||||||
import CircularProgress from '@material-ui/core/CircularProgress'
|
import CircularProgress from '@material-ui/core/CircularProgress'
|
||||||
import usePreviousState from 'utils/usePreviousState'
|
import usePreviousState from 'utils/usePreviousState'
|
||||||
|
|
||||||
import { checkImageURL, getMoviePosters, chechTorrentSource } from './helpers'
|
import { checkImageURL, getMoviePosters, chechTorrentSource, parseTorrentTitle } from './helpers'
|
||||||
import {
|
import {
|
||||||
ButtonWrapper,
|
ButtonWrapper,
|
||||||
CancelIconWrapper,
|
CancelIconWrapper,
|
||||||
@@ -39,23 +37,6 @@ import {
|
|||||||
RightSideContainer,
|
RightSideContainer,
|
||||||
} from './style'
|
} from './style'
|
||||||
|
|
||||||
const parseTorrentTitle = (parsingSource, callback) => {
|
|
||||||
parseTorrent.remote(parsingSource, (err, { name, files } = {}) => {
|
|
||||||
if (!name || err) return callback(null)
|
|
||||||
|
|
||||||
const torrentName = ptt.parse(name).title
|
|
||||||
const nameOfFileInsideTorrent = files ? ptt.parse(files[0].name).title : null
|
|
||||||
|
|
||||||
let newTitle = torrentName
|
|
||||||
if (nameOfFileInsideTorrent) {
|
|
||||||
// taking shorter title because in most cases it is more accurate
|
|
||||||
newTitle = torrentName.length < nameOfFileInsideTorrent.length ? torrentName : nameOfFileInsideTorrent
|
|
||||||
}
|
|
||||||
|
|
||||||
callback(newTitle)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
export default function AddDialog({ handleClose }) {
|
export default function AddDialog({ handleClose }) {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const [torrentSource, setTorrentSource] = useState('')
|
const [torrentSource, setTorrentSource] = useState('')
|
||||||
@@ -76,13 +57,12 @@ export default function AddDialog({ handleClose }) {
|
|||||||
|
|
||||||
const posterSearch = useMemo(
|
const posterSearch = useMemo(
|
||||||
() =>
|
() =>
|
||||||
(movieName, language, settings = {}) => {
|
(movieName, language, { shouldRefreshMainPoster = false } = {}) => {
|
||||||
if (!movieName) {
|
if (!movieName) {
|
||||||
setPosterList()
|
setPosterList()
|
||||||
removePoster()
|
removePoster()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
const { shouldRefreshMainPoster = false } = settings
|
|
||||||
|
|
||||||
getMoviePosters(movieName, language).then(urlList => {
|
getMoviePosters(movieName, language).then(urlList => {
|
||||||
if (urlList) {
|
if (urlList) {
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
import axios from 'axios'
|
import axios from 'axios'
|
||||||
|
import parseTorrent from 'parse-torrent'
|
||||||
|
import ptt from 'parse-torrent-title'
|
||||||
|
|
||||||
export const getMoviePosters = (movieName, language = 'en') => {
|
export const getMoviePosters = (movieName, language = 'en') => {
|
||||||
const url = 'http://api.themoviedb.org/3/search/multi'
|
const url = 'http://api.themoviedb.org/3/search/multi'
|
||||||
@@ -34,3 +36,20 @@ const hashRegex = /^\b[0-9a-f]{32}\b$|^\b[0-9a-f]{40}\b$|^\b[0-9a-f]{64}\b$/i
|
|||||||
const torrentRegex = /^.*\.(torrent)$/i
|
const torrentRegex = /^.*\.(torrent)$/i
|
||||||
export const chechTorrentSource = source =>
|
export const chechTorrentSource = source =>
|
||||||
source.match(hashRegex) !== null || source.match(magnetRegex) !== null || source.match(torrentRegex) !== null
|
source.match(hashRegex) !== null || source.match(magnetRegex) !== null || source.match(torrentRegex) !== null
|
||||||
|
|
||||||
|
export const parseTorrentTitle = (parsingSource, callback) => {
|
||||||
|
parseTorrent.remote(parsingSource, (err, { name, files } = {}) => {
|
||||||
|
if (!name || err) return callback(null)
|
||||||
|
|
||||||
|
const torrentName = ptt.parse(name).title
|
||||||
|
const nameOfFileInsideTorrent = files ? ptt.parse(files[0].name).title : null
|
||||||
|
|
||||||
|
let newTitle = torrentName
|
||||||
|
if (nameOfFileInsideTorrent) {
|
||||||
|
// taking shorter title because in most cases it is more accurate
|
||||||
|
newTitle = torrentName.length < nameOfFileInsideTorrent.length ? torrentName : nameOfFileInsideTorrent
|
||||||
|
}
|
||||||
|
|
||||||
|
callback(newTitle)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user