Skip to content
This repository has been archived by the owner on Jul 4, 2024. It is now read-only.

Commit

Permalink
Add more output format options (#284)
Browse files Browse the repository at this point in the history
bytedream committed Dec 23, 2023

Verified

This commit was signed with the committer’s verified signature. The key has expired.
acaloiaro Adriano Caloiaro
1 parent 0da81a4 commit 19935df
Showing 3 changed files with 79 additions and 5 deletions.
17 changes: 15 additions & 2 deletions crunchy-cli-core/src/archive/command.rs
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@ use anyhow::Result;
use chrono::Duration;
use crunchyroll_rs::media::{Resolution, Subtitle};
use crunchyroll_rs::Locale;
use log::debug;
use log::{debug, warn};
use std::collections::HashMap;
use std::path::PathBuf;

@@ -43,12 +43,16 @@ pub struct Archive {
{series_name} → Name of the series\n \
{season_name} → Name of the season\n \
{audio} → Audio language of the video\n \
{resolution} → Resolution of the video\n \
{width} → Width of the video\n \
{height} → Height of the video\n \
{season_number} → Number of the season\n \
{episode_number} → Number of the episode\n \
{relative_episode_number} → Number of the episode relative to its season\n \
{sequence_number} → Like '{episode_number}' but without possible non-number characters\n \
{relative_sequence_number} → Like '{relative_episode_number}' but with support for episode 0's and .5's\n \
{release_year} → Release year of the video\n \
{release_month} → Release month of the video\n \
{release_day} → Release day of the video\n \
{series_id} → ID of the series\n \
{season_id} → ID of the season\n \
{episode_id} → ID of the episode")]
@@ -157,6 +161,15 @@ impl Execute for Archive {
}
}

if self.output.contains("{resolution}")
|| self
.output_specials
.as_ref()
.map_or(false, |os| os.contains("{resolution}"))
{
warn!("The '{{resolution}}' format option is deprecated and will be removed in a future version. Please use '{{width}}' and '{{height}}' instead")
}

self.audio = all_locale_in_locales(self.audio.clone());
self.subtitle = all_locale_in_locales(self.subtitle.clone());

15 changes: 14 additions & 1 deletion crunchy-cli-core/src/download/command.rs
Original file line number Diff line number Diff line change
@@ -39,12 +39,16 @@ pub struct Download {
{series_name} → Name of the series\n \
{season_name} → Name of the season\n \
{audio} → Audio language of the video\n \
{resolution} → Resolution of the video\n \
{width} → Width of the video\n \
{height} → Height of the video\n \
{season_number} → Number of the season\n \
{episode_number} → Number of the episode\n \
{relative_episode_number} → Number of the episode relative to its season\n \
{sequence_number} → Like '{episode_number}' but without possible non-number characters\n \
{relative_sequence_number} → Like '{relative_episode_number}' but with support for episode 0's and .5's\n \
{release_year} → Release year of the video\n \
{release_month} → Release month of the video\n \
{release_day} → Release day of the video\n \
{series_id} → ID of the series\n \
{season_id} → ID of the season\n \
{episode_id} → ID of the episode")]
@@ -153,6 +157,15 @@ impl Execute for Download {
}
}

if self.output.contains("{resolution}")
|| self
.output_specials
.as_ref()
.map_or(false, |os| os.contains("{resolution}"))
{
warn!("The '{{resolution}}' format option is deprecated and will be removed in a future version. Please use '{{width}}' and '{{height}}' instead")
}

Ok(())
}

52 changes: 50 additions & 2 deletions crunchy-cli-core/src/utils/format.rs
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@ use crate::utils::filter::real_dedup_vec;
use crate::utils::log::tab_info;
use crate::utils::os::{is_special_file, sanitize};
use anyhow::Result;
use chrono::Duration;
use chrono::{Datelike, Duration};
use crunchyroll_rs::media::{Resolution, Stream, Subtitle, VariantData};
use crunchyroll_rs::{Concert, Episode, Locale, MediaCollection, Movie, MusicVideo};
use log::{debug, info};
@@ -17,6 +17,10 @@ pub struct SingleFormat {
pub title: String,
pub description: String,

pub release_year: u64,
pub release_month: u64,
pub release_day: u64,

pub audio: Locale,
pub subtitles: Vec<Locale>,

@@ -60,6 +64,9 @@ impl SingleFormat {
},
title: episode.title.clone(),
description: episode.description.clone(),
release_year: episode.episode_air_date.year() as u64,
release_month: episode.episode_air_date.month() as u64,
release_day: episode.episode_air_date.day() as u64,
audio: episode.audio_locale.clone(),
subtitles,
series_id: episode.series_id.clone(),
@@ -86,6 +93,9 @@ impl SingleFormat {
identifier: movie.id.clone(),
title: movie.title.clone(),
description: movie.description.clone(),
release_year: movie.free_available_date.year() as u64,
release_month: movie.free_available_date.month() as u64,
release_day: movie.free_available_date.day() as u64,
audio: Locale::ja_JP,
subtitles,
series_id: movie.movie_listing_id.clone(),
@@ -108,6 +118,9 @@ impl SingleFormat {
identifier: music_video.id.clone(),
title: music_video.title.clone(),
description: music_video.description.clone(),
release_year: music_video.original_release.year() as u64,
release_month: music_video.original_release.month() as u64,
release_day: music_video.original_release.day() as u64,
audio: Locale::ja_JP,
subtitles: vec![],
series_id: music_video.id.clone(),
@@ -130,6 +143,9 @@ impl SingleFormat {
identifier: concert.id.clone(),
title: concert.title.clone(),
description: concert.description.clone(),
release_year: concert.original_release.year() as u64,
release_month: concert.original_release.month() as u64,
release_day: concert.original_release.day() as u64,
audio: Locale::ja_JP,
subtitles: vec![],
series_id: concert.id.clone(),
@@ -324,9 +340,16 @@ pub struct Format {

pub locales: Vec<(Locale, Vec<Locale>)>,

// deprecated
pub resolution: Resolution,
pub width: u64,
pub height: u64,
pub fps: f64,

pub release_year: u64,
pub release_month: u64,
pub release_day: u64,

pub series_id: String,
pub series_name: String,

@@ -364,8 +387,13 @@ impl Format {
title: first_format.title,
description: first_format.description,
locales,
resolution: first_stream.resolution,
resolution: first_stream.resolution.clone(),
width: first_stream.resolution.width,
height: first_stream.resolution.height,
fps: first_stream.fps,
release_year: first_format.release_year,
release_month: first_format.release_month,
release_day: first_format.release_day,
series_id: first_format.series_id,
series_name: first_format.series_name,
season_id: first_format.season_id,
@@ -396,6 +424,14 @@ impl Format {
),
)
.replace("{resolution}", &sanitize(self.resolution.to_string(), true))
.replace(
"{width}",
&sanitize(self.resolution.width.to_string(), true),
)
.replace(
"{height}",
&sanitize(self.resolution.height.to_string(), true),
)
.replace("{series_id}", &sanitize(&self.series_id, true))
.replace("{series_name}", &sanitize(&self.series_name, true))
.replace("{season_id}", &sanitize(&self.season_id, true))
@@ -434,6 +470,18 @@ impl Format {
true,
)
),
)
.replace(
"{release_year}",
&sanitize(self.release_year.to_string(), true),
)
.replace(
"{release_month}",
&format!("{:0>2}", sanitize(self.release_month.to_string(), true)),
)
.replace(
"{release_day}",
&format!("{:0>2}", sanitize(self.release_day.to_string(), true)),
);

PathBuf::from(path)

0 comments on commit 19935df

Please sign in to comment.