Skip to content

Commit

Permalink
resolve #8 - Enable download a single video
Browse files Browse the repository at this point in the history
  • Loading branch information
moshfeu committed Dec 17, 2018
1 parent 48c3afe commit a637970
Show file tree
Hide file tree
Showing 7 changed files with 203 additions and 34 deletions.
63 changes: 46 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,13 @@ A simple desktop application to download Youtube videos to mp3, one by one or al

<img src="app-resources/video.gif" alt="video demo" width="320" />

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)
<img width="30" alt="windows" src="app-resources/readme/windows.svg">
<img width="30" alt="mac" src="app-resources/readme/mac.svg">
<img width="30" alt="linux" src="app-resources/readme/linux.svg">

## Download

Expand All @@ -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.
2. The app doesn't store ANY media files ANYWHERE except on the device who use this app.

<div>
Icons made by <a href="https://www.flaticon.com/authors/pixel-perfect" title="Pixel perfect">Pixel perfect</a> from <a href="https://www.flaticon.com/" title="Flaticon">www.flaticon.com</a> is licensed by <a href="http://creativecommons.org/licenses/by/3.0/" title="Creative Commons BY 3.0" target="_blank">CC 3.0 BY</a>
</div>

## 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
37 changes: 37 additions & 0 deletions app-resources/readme/linux.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
40 changes: 40 additions & 0 deletions app-resources/readme/mac.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
43 changes: 43 additions & 0 deletions app-resources/readme/windows.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "y2mp3",
"appname": "y2mp3",
"productName": "y2mp3",
"version": "1.0.5",
"version": "1.1.0",
"main": "main.js",
"author": {
"name": "MosheF",
Expand All @@ -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",
Expand All @@ -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",
Expand Down
10 changes: 10 additions & 0 deletions src/factories/video-entity.ts
Original file line number Diff line number Diff line change
@@ -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
}
}
39 changes: 24 additions & 15 deletions src/services/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand All @@ -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<IVideoEntity[]> {

//Configure YoutubeMp3Downloader with your settings
export function fetchVideos(term: string): Promise<IVideoEntity[]> {
try {
return ytlist(playlistUrl).
then((data: IPlaylistYoutube) => {
const { data: {playlist} } = data;
return playlist.map(video => (<IVideoEntity>{
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<IVideoEntity[]> {
const { title, video_id } = await getBasicInfo(videoUrl);
return [createVideoEntity(title, video_id)];
}

async function fetchVideosFromList(playlistUrl: string): Promise<IVideoEntity[]> {
const data: IPlaylistYoutube = await ytlist(playlistUrl);
const { data: {playlist} } = data;
return playlist.map(video => createVideoEntity(video.name, video.id));
}

0 comments on commit a637970

Please sign in to comment.