Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Argument for having episodes in a directory with their respective season name #49

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,11 @@ Downloads the Crunchyroll videos with the subtitles hardsubbed or softsubbed.
- `--vilos` fetch the videos/subtitles from the Crunchyroll web page. will not work with the unblocked option.
- `--ffmpeg`, `-f` specify custom FFMPEG arguments (default: `-c copy`)
- examples
- `-f="-c copy" -f="-crf 24" -ffmpeg="-vcodec libx264"`
- `-f="-c copy" -f="-crf 24" --ffmpeg="-vcodec libx264"`
- `-f="-vf scale=-1:720"`
- `--overwrite` force overwrite existing files.
- `--folderBySeason` use a specific folder for each season.
- `--moveExists` move existing files to their season folder.

**Downloading with Softsubs**
- `--language` (same as above) which subtitle languages to download. if omitted, will present a list to select from. same options as below for the languages
Expand Down
34 changes: 32 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,15 @@ let argv = yargs
.alias('f', 'ffmpeg')
.default('ffmpeg', '-c copy')

.describe("overwrite", "Overwrite existing files")
.boolean("overwrite")
.describe("overwrite", "Overwrite existing files")
.boolean("overwrite")

.describe("folderBySeason", "Put episodes into folders by their seasons")
.boolean("folderBySeason")

.describe("moveExists", "Move existing files to their season folder (used for merging with folderBySeason) (REQUIRES folderBySeason to be on)")
.boolean("moveExists")

// help
.describe('h', 'Shows this help')
.alias('h', 'help')
Expand All @@ -130,6 +137,9 @@ const episodeRanges = argv['episodes'].toString()
const language = argv.language
const ffmpegArgs = argv['ffmpeg']
const overwrite = argv['overwrite']
const folderBySeason = argv["folderBySeason"]
let moveExists = argv['moveExists']
let seasonName = "null";
let desiredLanguages = language.split(',').map(l => l.trim())

if (language !== 'all' && language !== 'none') {
Expand All @@ -142,6 +152,11 @@ if (language !== 'all' && language !== 'none') {
}
}

if(moveExists && !folderBySeason) {
warn("moveExists has been disabled because folderBySeason is disabled.")
moveExists = false;
}

if (subsOnly && subType !== 'soft') {
info('Changing to soft sub download, to download the subtitles only')
subType = 'hard'
Expand Down Expand Up @@ -727,6 +742,7 @@ const main = async () => {
continue
}
info(`Downloading episode ${media.episode_number || '(not set)'}, "${media.name}", of "${name}"`)
seasonName = name;
await getEpisode(media.media_id, media)
}
}
Expand Down Expand Up @@ -785,12 +801,26 @@ const parsem3u8 = (manifest) => {
}

const downloadEpisode = (url, output, logDownload = true) => {

if(folderBySeason) {
const fs = require("fs");
if(!fs.existsSync(seasonName))
fs.mkdirSync(seasonName)
if(fs.existsSync(output) && moveExists)
return new Promise((resolve) => {
info("Moving " + output + " to " + seasonName + "/" + output);
fs.rename(output, "./" + seasonName + "/" + output, () => {})
resolve()
})
output = "./" + seasonName + "/" + output;
}
if(fs.existsSync(output) && !overwrite)
return new Promise((resolve) => {
info("File already exists, skipping...");
resolve()
})
return new Promise((resolve, reject) => {

ffmpeg(url)
.on('start', () => {
info('Beginning download...')
Expand Down