From a637970f70148f835fca4baba3409aaeb62d7dca Mon Sep 17 00:00:00 2001 From: Mosh Feu Date: Mon, 17 Dec 2018 08:57:36 +0200 Subject: [PATCH] resolve #8 - Enable download a single video --- README.md | 63 +++++++++++++++++++++++--------- app-resources/readme/linux.svg | 37 +++++++++++++++++++ app-resources/readme/mac.svg | 40 ++++++++++++++++++++ app-resources/readme/windows.svg | 43 ++++++++++++++++++++++ package.json | 5 ++- src/factories/video-entity.ts | 10 +++++ src/services/api.ts | 39 ++++++++++++-------- 7 files changed, 203 insertions(+), 34 deletions(-) create mode 100644 app-resources/readme/linux.svg create mode 100644 app-resources/readme/mac.svg create mode 100644 app-resources/readme/windows.svg create mode 100644 src/factories/video-entity.ts diff --git a/README.md b/README.md index 8206378..8c37b20 100644 --- a/README.md +++ b/README.md @@ -11,20 +11,13 @@ A simple desktop application to download Youtube videos to mp3, one by one or al video demo -Mp3 files will be saved to a **y2mp3** folder in the **Download** folder (mac and windows) +Mp3 files will be saved to a **y2mp3** folder in the **Download** folder -## Stack +## Supported os -- [electron](http://electronjs.org/) -- [reactjs](https://reactjs.org/) -- [typescript](https://www.typescriptlang.org/) -- [webpack](https://webpack.js.org/) - -### Libraries - -- [youtube-mp3-downloader](https://github.com/ytb2mp3/youtube-mp3-downloader) -- [youtube-playlist](https://github.com/CodeDotJS/youtube-playlist) -- [ffbinaries](https://github.com/vot/ffbinaries-node) +windows +mac +linux ## Download @@ -33,14 +26,50 @@ Mp3 files will be saved to a **y2mp3** folder in the **Download** folder (mac an Find your download: [https://github.com/moshfeu/y2mp3/releases/latest](https://github.com/moshfeu/y2mp3/releases/latest) -## TODO +## Change log -🖖🎖 Thanks you for your willing to contribute! You can find the list in the [project](https://github.com/moshfeu/y2mp3/projects/1#column-3954836) page. +##### 1.1.0 +Allow fetch and download a single video -## License -MIT +##### 1.0.0 +Fetch videos from youtube playlist and download them one by one or all. ## Disclaimer 1. Please use this app for downloading only public resources. -2. The app doesn't store ANY media files ANYWHERE except on the device who use this app. \ No newline at end of file +2. The app doesn't store ANY media files ANYWHERE except on the device who use this app. + +
+ Icons made by Pixel perfect from www.flaticon.com is licensed by CC 3.0 BY +
+ +## Development + +``` +npm run webpack +npm run electron +``` + +### Stack + +- [electron](http://electronjs.org/) +- [reactjs](https://reactjs.org/) +- [typescript](https://www.typescriptlang.org/) +- [webpack](https://webpack.js.org/) + +#### Tests + +- [jest](https://jestjs.io/) + +#### Libraries + +- [youtube-mp3-downloader](https://github.com/ytb2mp3/youtube-mp3-downloader) +- [youtube-playlist](https://github.com/CodeDotJS/youtube-playlist) +- [ffbinaries](https://github.com/vot/ffbinaries-node) + +### TODO + +🖖🎖 Thanks you for your willing to contribute! You can find the list in the [project](https://github.com/moshfeu/y2mp3/projects/1#column-3954836) page. + +## License +MIT \ No newline at end of file diff --git a/app-resources/readme/linux.svg b/app-resources/readme/linux.svg new file mode 100644 index 0000000..d036f47 --- /dev/null +++ b/app-resources/readme/linux.svg @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app-resources/readme/mac.svg b/app-resources/readme/mac.svg new file mode 100644 index 0000000..bc4270b --- /dev/null +++ b/app-resources/readme/mac.svg @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app-resources/readme/windows.svg b/app-resources/readme/windows.svg new file mode 100644 index 0000000..bd05db7 --- /dev/null +++ b/app-resources/readme/windows.svg @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/package.json b/package.json index 0692f80..58f427a 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "y2mp3", "appname": "y2mp3", "productName": "y2mp3", - "version": "1.0.5", + "version": "1.1.0", "main": "main.js", "author": { "name": "MosheF", @@ -13,7 +13,7 @@ "license": "MIT", "description": "An app to download youtube videos as mp3", "scripts": { - "start": "webpack", + "webpack": "webpack", "electron": "electron .", "dist": "npm run build && electron-builder", "dist-linux": "npm run dist --linux", @@ -30,6 +30,7 @@ "electron-is-dev": "^1.0.1", "enzyme": "^3.7.0", "enzyme-adapter-react-16": "^1.7.1", + "js-video-url-parser": "^0.2.8", "react": "^16.5.2", "react-dom": "^16.5.2", "semantic-ui-react": "^0.84.0", diff --git a/src/factories/video-entity.ts b/src/factories/video-entity.ts new file mode 100644 index 0000000..9e56330 --- /dev/null +++ b/src/factories/video-entity.ts @@ -0,0 +1,10 @@ +import { IVideoEntity, EVideoStatus } from '../types'; + +export function createVideoEntity(name: string, id: string): IVideoEntity { + return { + name, + id, + progress: 0, + status: EVideoStatus.NOT_STARTED + } +} \ No newline at end of file diff --git a/src/services/api.ts b/src/services/api.ts index cc278ab..b5e5850 100644 --- a/src/services/api.ts +++ b/src/services/api.ts @@ -2,7 +2,11 @@ import * as YoutubeMp3Downloader from 'youtube-mp3-downloader'; import * as ytlist from 'youtube-playlist'; import { IVideoEntity, IPlaylistYoutube, EVideoStatus } from '../types'; import { DOWNLOADS_FOLDER, ffmpegPath } from './path'; -var ffmpeg = require("fluent-ffmpeg"); +import * as urlParser from 'js-video-url-parser'; +import { getBasicInfo } from 'ytdl-core'; +import { createVideoEntity } from '../factories/video-entity'; + +import * as ffmpeg from 'fluent-ffmpeg'; export const downloader = new YoutubeMp3Downloader({ ffmpegPath: ffmpegPath(), // Where is the FFmpeg binary located? @@ -13,24 +17,29 @@ export const downloader = new YoutubeMp3Downloader({ }); export function setFfmpegPath() { - ffmpeg.setFfmpegPath(ffmpegPath()); + // remove it when @types/ffmpeg will updated + (ffmpeg as any).setFfmpegPath(ffmpegPath()); } -export function fetchVideos(playlistUrl: string): Promise { - - //Configure YoutubeMp3Downloader with your settings +export function fetchVideos(term: string): Promise { try { - return ytlist(playlistUrl). - then((data: IPlaylistYoutube) => { - const { data: {playlist} } = data; - return playlist.map(video => ({ - id: video.id, - name: video.name, - progress: 0, - status: EVideoStatus.NOT_STARTED - })); - }); + const parsedTerm = urlParser.parse(term); + if (parsedTerm.list) { + return fetchVideosFromList(term); + } + return fetchVideoFromSingle(term); } catch (error) { console.error(error); } } + +async function fetchVideoFromSingle(videoUrl: string): Promise { + const { title, video_id } = await getBasicInfo(videoUrl); + return [createVideoEntity(title, video_id)]; +} + +async function fetchVideosFromList(playlistUrl: string): Promise { + const data: IPlaylistYoutube = await ytlist(playlistUrl); + const { data: {playlist} } = data; + return playlist.map(video => createVideoEntity(video.name, video.id)); +}