Skip to content

Commit

Permalink
opt: format code
Browse files Browse the repository at this point in the history
  • Loading branch information
Kingtous committed Sep 22, 2022
1 parent d37026d commit 772774a
Show file tree
Hide file tree
Showing 16 changed files with 45 additions and 91 deletions.
14 changes: 6 additions & 8 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@
// along with RustPlayer. If not, see <http://www.gnu.org/licenses/>.

use std::{
io::{stdout, Stdout},
io::stdout,
sync::mpsc,
thread::{self, sleep_ms},
time::{self, Duration, SystemTime},
thread::{self},
vec,
};

use crossterm::{
event::{self, DisableMouseCapture, EnableMouseCapture, Event, KeyCode},
event::{self, Event, KeyCode},
execute,
terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen},
};
Expand All @@ -33,16 +32,15 @@ use tui::{
backend::{Backend, CrosstermBackend},
layout::{Alignment, Constraint, Direction, Layout, Rect},
style::{Color, Style},
text::{Span, Text},
widgets::{Block, BorderType, Borders, ListState, Paragraph, Widget, Wrap},
text::Text,
widgets::{Block, BorderType, Borders, ListState, Paragraph, Wrap},
Frame, Terminal,
};

use crate::{
config::Config,
fs::FsExplorer,
handler::handle_keyboard_event,
main,
media::player::{MusicPlayer, Player, RadioPlayer},
ui::{
fs::draw_fs_tree,
Expand Down Expand Up @@ -231,7 +229,7 @@ impl App {
// .margin(2)
.split(area);
// 左侧
if (self.active_modules == ActiveModules::RadioList) {
if self.active_modules == ActiveModules::RadioList {
draw_radio_list(self, frame, main_layout[0]);
} else {
draw_fs_tree(self, frame, main_layout[0]);
Expand Down
1 change: 0 additions & 1 deletion src/handler/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ use crate::{
media::{Media, Source},
player::Player,
},
ui::fs,
};

fn add_media_to_player(app: &mut App, once: bool) -> bool {
Expand Down
7 changes: 1 addition & 6 deletions src/handler/music_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,9 @@
// You should have received a copy of the GNU General Public License
// along with RustPlayer. If not, see <http://www.gnu.org/licenses/>.

use std::cmp::max;

use crossterm::event::KeyCode;

use crate::{
app::{ActiveModules, App},
media::player::Player,
};
use crate::{app::App, media::player::Player};

pub fn handle_music_controller(app: &mut App, code: KeyCode) -> bool {
// if app.active_modules != ActiveModules::MusicController {
Expand Down
2 changes: 0 additions & 2 deletions src/handler/player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
// You should have received a copy of the GNU General Public License
// along with RustPlayer. If not, see <http://www.gnu.org/licenses/>.

use std::cmp::max;

use crossterm::event::KeyCode;

use crate::{app::App, media::player::Player};
Expand Down
3 changes: 1 addition & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
// along with RustPlayer. If not, see <http://www.gnu.org/licenses/>.

use app::*;
use handler::*;
use media::*;

use ui::*;
use util::*;

Expand Down
35 changes: 11 additions & 24 deletions src/media/player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,40 +15,27 @@
// You should have received a copy of the GNU General Public License
// along with RustPlayer. If not, see <http://www.gnu.org/licenses/>.

use bytes::Bytes;
use std::cmp::max;
use std::fs;
use std::future::Future;
use std::io::Cursor;
use std::sync::mpsc::{Receiver, Sender, TryRecvError};

use std::sync::mpsc::{Receiver, Sender};
use std::{
cell::{Ref, RefCell},
fmt::Debug,
fs::File,
io::{BufReader, Error, Write},
io::{BufReader, Write},
ops::Add,
path::Path,
ptr::null,
sync::{
mpsc::{self, channel},
Arc, Mutex,
},
sync::mpsc::channel,
thread,
time::{Duration, Instant, SystemTime},
};

use m3u8_rs::{MediaPlaylist, Playlist};
use rodio::decoder::DecoderError;
use rodio::{cpal, source::Delay};
use rodio::{Decoder, Devices, OutputStream, OutputStreamHandle, Sink, Source};

use rodio::cpal;
use rodio::{Decoder, OutputStream, OutputStreamHandle, Sink, Source};
use tui::widgets::ListState;

use crate::net::download;
use crate::util::lyrics::Lyrics;
use crate::util::m3u8::empty_cache;
use crate::{
app,
util::lyrics::{Lyric, Lyrics},
};
use crate::{m3u8::download_m3u8_playlist, util::net::download_as_bytes};

use super::media::Media;
Expand Down Expand Up @@ -159,7 +146,7 @@ impl Player for MusicPlayer {
super::media::Source::Local(path) => {
return self.play_with_file(path, once);
}
super::media::Source::M3u8(path) => false,
super::media::Source::M3u8(_path) => false,
}
}

Expand Down Expand Up @@ -448,7 +435,7 @@ impl Player for RadioPlayer {
match src {
super::media::Source::Http(_) => false,
super::media::Source::M3u8(url) => {
let (tx, mut rx) = channel();
let (tx, rx) = channel();
let m3u8_url = url.url.clone();
thread::spawn(move || {
let playlist = download_m3u8_playlist(m3u8_url);
Expand All @@ -472,7 +459,7 @@ impl Player for RadioPlayer {
return true;
}
}
Err(err) => {
Err(_err) => {
// ignore
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/ui/effects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ use std::vec;
use rand::Rng;
use tui::{
backend::Backend,
layout::{Alignment, Constraint, Direction, Layout, Rect},
layout::{Alignment, Rect},
style::{Color, Modifier, Style},
widgets::{BarChart, Block, BorderType, Borders, List, ListItem, Paragraph},
widgets::{BarChart, Block, BorderType, Borders, List, ListItem},
Frame,
};

Expand Down
11 changes: 4 additions & 7 deletions src/ui/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,17 @@
// along with RustPlayer. If not, see <http://www.gnu.org/licenses/>.

use std::env::current_dir;
use std::fmt::{Debug, Display, Formatter};
use std::fs::{DirEntry, ReadDir};
use std::fmt::Debug;
use std::fs;
use std::fs::DirEntry;
use std::path::Path;
use std::{fs, os};

use crossterm::style::Colors;
use failure::{Error, Fail};
use tui::backend::Backend;
use tui::layout::{Alignment, Constraint, Direction, Layout, Rect};
use tui::style::{Color, Style};
use tui::text::Text;
use tui::widgets::{
Block, BorderType, Borders, List, ListItem, ListState, Paragraph, Widget, Wrap,
};
use tui::widgets::{Block, BorderType, Borders, List, ListItem, ListState, Paragraph, Wrap};
use tui::Frame;

use crate::app::ActiveModules;
Expand Down
9 changes: 4 additions & 5 deletions src/ui/help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,17 @@

use std::vec;

use rand::Rng;
use tui::{
backend::Backend,
layout::{self, Alignment, Constraint, Direction, Layout, Rect},
style::{Color, Modifier, Style},
widgets::{BarChart, Block, BorderType, Borders, Paragraph, Row, Table},
layout::{Constraint, Direction, Layout, Rect},
style::{Color, Style},
widgets::{Block, BorderType, Borders, Paragraph, Row, Table},
Frame,
};

use crate::{app::App, media::player::Player};

pub fn draw_help<B>(app: &mut App, frame: &mut Frame<B>, area: Rect)
pub fn draw_help<B>(_app: &mut App, frame: &mut Frame<B>, area: Rect)
where
B: Backend,
{
Expand Down
5 changes: 1 addition & 4 deletions src/ui/music_board.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@ use tui::{
Frame,
};

use crate::{
app::{ActiveModules, App},
media::player::Player,
};
use crate::{app::App, media::player::Player};

use super::{effects::draw_bar_charts_effect, play_list::draw_play_list, progress::draw_progress};

Expand Down
6 changes: 2 additions & 4 deletions src/ui/progress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,12 @@
// You should have received a copy of the GNU General Public License
// along with RustPlayer. If not, see <http://www.gnu.org/licenses/>.

use std::time::Duration;

use tui::{
backend::Backend,
layout::{Constraint, Layout, Rect},
style::{Color, Modifier, Style},
symbols::{self, line::Set, Marker},
widgets::{Block, BorderType, Borders, Gauge, LineGauge},
symbols::{self},
widgets::LineGauge,
Frame,
};

Expand Down
2 changes: 1 addition & 1 deletion src/ui/radio.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::{
fs::{self, File},
fs::File,
io::{BufRead, BufReader},
vec,
};
Expand Down
9 changes: 1 addition & 8 deletions src/util/lyrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,7 @@
// You should have received a copy of the GNU General Public License
// along with RustPlayer. If not, see <http://www.gnu.org/licenses/>.

use std::{
fmt::Display,
fs::File,
io::Read,
path::{Path, PathBuf},
time::Duration,
vec,
};
use std::{fmt::Display, fs::File, io::Read, path::PathBuf, time::Duration, vec};

use regex::Regex;

Expand Down
13 changes: 6 additions & 7 deletions src/util/m3u8.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
use std::fs::{read_dir, File};
use std::fs::read_dir;
use std::sync::mpsc;
use std::sync::mpsc::RecvTimeoutError;

use std::thread;
use std::time::Duration;
use std::{fmt::format, fs};

use failure::{format_err, Error};
use m3u8_rs::{MediaPlaylist, Playlist};
use failure::format_err;
use m3u8_rs::Playlist;

use crate::net::{download, DownloadTimeoutError};
use crate::net::download;

pub fn download_m3u8_playlist(url: String) -> Result<Playlist, failure::Error> {
let (tx, rx) = mpsc::channel();
Expand All @@ -18,7 +17,7 @@ pub fn download_m3u8_playlist(url: String) -> Result<Playlist, failure::Error> {
let playlist = m3u8_rs::parse_playlist(data.as_bytes());
match playlist {
Ok(list) => Ok(list.1),
Err(err) => Err(format_err!("Parse Playlist Failed")),
Err(_err) => Err(format_err!("Parse Playlist Failed")),
}
} else {
println!("{:?}", resp);
Expand Down
4 changes: 2 additions & 2 deletions src/util/net.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::fmt::{write, Debug, Display, Formatter};
use std::io::Bytes;
use std::fmt::{Debug, Display, Formatter};

use std::sync::mpsc::Sender;

pub struct DownloadTimeoutError {
Expand Down
11 changes: 3 additions & 8 deletions tests/m3u8.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
use m3u8_rs::Playlist;
use std::{
io::{Error, Result},
sync::mpsc,
thread,
time::Duration,
};
use std::{sync::mpsc, thread, time::Duration};

include!("../src/util/net.rs");

Expand All @@ -21,7 +16,7 @@ fn fetch_and_play() {
let entity = m3u8_rs::parse_playlist(s.as_bytes()).unwrap();
let list = entity.1;
match list {
Playlist::MasterPlaylist(master_play_list) => {}
Playlist::MasterPlaylist(_master_play_list) => {}
Playlist::MediaPlaylist(media_play_list) => {
for seg in &media_play_list.segments {
println!("{}", seg.uri);
Expand All @@ -30,7 +25,7 @@ fn fetch_and_play() {
}
}
}
Err(e) => {
Err(_e) => {
assert!(false);
}
}
Expand Down

0 comments on commit 772774a

Please sign in to comment.