Skip to content

Commit 33b7bc6

Browse files
committed
fix: fix youtube downloading "bad" file paths and video segmentation broken,
add support for 720p and 480p downloads
1 parent c7ef9b7 commit 33b7bc6

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
"react-data-table-component": "^6.2.2",
8383
"react-dropzone": "^10.1.8",
8484
"react-icons": "^3.9.0",
85-
"react-image-annotate": "^0.2.4",
85+
"react-image-annotate": "^1.0.4",
8686
"react-scripts": "^3.4.1",
8787
"react-select": "^3.0.8",
8888
"rfc6902": "^3.0.4",

src/components/ImportFromYoutubeUrls/download-youtube-video.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
const idify = (s) =>
2+
s
3+
.toLowerCase()
4+
.replace(/[^a-z0-9]/g, "_")
5+
.replace(/_+/g, "_")
6+
17
export default ({
28
youtubeUrl,
39
title: videoTitle,
@@ -6,16 +12,16 @@ export default ({
612
downloadPath,
713
onProgress,
814
onComplete,
9-
overallProgress,
15+
onChangeOverallProgress,
1016
}) => {
1117
let starttime = Date.now()
1218

1319
const ytdl = remote.require("ytdl-core")
1420
const path = remote.require("path")
1521

1622
const videoName = videoQuality.includes("audio")
17-
? `${videoTitle + ".mp3"}`
18-
: `${videoTitle + ".mp4"}`
23+
? `${idify(videoTitle) + ".mp3"}`
24+
: `${idify(videoTitle) + ".mp4"}`
1925

2026
const fullVideoPath = path.join(downloadPath, videoName)
2127
const writableVideoFile = remote
@@ -53,7 +59,7 @@ export default ({
5359
progress: percent * 100,
5460
})
5561

56-
overallProgress(percent * 100)
62+
onChangeOverallProgress(percent * 100)
5763
})
5864

5965
youtubeVideoWithOptions.on("end", () => onComplete(fullVideoPath))

src/components/ImportFromYoutubeUrls/index.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,12 @@ const CompletedVideoTitle = styled("h3")({
4242
})
4343

4444
const qualityOptions = [
45+
{ value: "136", label: "720p" },
46+
{ value: "135", label: "480p" },
4547
{ value: "lowestvideo", label: "Lowest Video Only" },
46-
{ value: "lowest", label: "lowest" },
47-
{ value: "highest", label: "Highest" },
48+
// TODO these did not seem to work in a local test (missing video)
49+
// { value: "lowest", label: "lowest" },
50+
// { value: "highest", label: "Highest" },
4851
{ value: "highestvideo", label: "Highest Video Only" },
4952
{ value: "lowestaudio", label: "Lowest Audio Only" },
5053
{ value: "highestaudio", label: "Highest Audio Only" },
@@ -54,7 +57,7 @@ const ImportFromYoutubeUrls = ({ open, onClose, onAddSamples }) => {
5457
const { remote } = useElectron() || {}
5558

5659
const [urlsFromTextArea, setUrlsFromTextArea] = useState([])
57-
const [videoQuality, setVideoQuality] = useState("lowest")
60+
const [videoQuality, setVideoQuality] = useState(qualityOptions[0].value)
5861
const [downloadPath, setDownloadPath] = useState(null)
5962
const [error, setError] = useState(null)
6063

@@ -136,7 +139,7 @@ const ImportFromYoutubeUrls = ({ open, onClose, onAddSamples }) => {
136139
youtubeUrl: youtubeVideoInfo.url,
137140
title: youtubeVideoInfo.title,
138141
videoQuality,
139-
overallProgress: (currentProgress) =>
142+
onChangeOverallProgress: (currentProgress) =>
140143
setOverallProgress(
141144
((completedVideoTitlesArray.length * 100 +
142145
currentProgress) /

0 commit comments

Comments
 (0)