Commit 59a9bd06 authored by Julian Hofer's avatar Julian Hofer
Browse files

Get rid of clippy warnings

parent 8b6fc10c
......@@ -22,7 +22,6 @@
use chrono::prelude::*;
use diesel::prelude::*;
use diesel;
use diesel::dsl::exists;
use diesel::select;
......@@ -383,16 +382,19 @@ pub(crate) fn podcast_exists(source_id_: i32) -> Result<bool, DataError> {
.map_err(From::from)
}
#[cfg_attr(rustfmt, rustfmt_skip)]
pub(crate) fn episode_exists(title_: &str, show_id_: i32) -> Result<bool, DataError> {
use crate::schema::episodes::dsl::*;
let db = connection();
let con = db.get()?;
select(exists(episodes.filter(show_id.eq(show_id_)).filter(title.eq(title_))))
.get_result(&con)
.map_err(From::from)
select(exists(
episodes
.filter(show_id.eq(show_id_))
.filter(title.eq(title_)),
))
.get_result(&con)
.map_err(From::from)
}
/// Check if the `episodes table contains any rows
......
......@@ -18,8 +18,6 @@
// SPDX-License-Identifier: GPL-3.0-or-later
use glob::glob;
use mime_guess;
use reqwest;
use reqwest::header::*;
use reqwest::redirect::Policy;
use tempdir::TempDir;
......@@ -103,8 +101,12 @@ fn download_into(
.and_then(|h| h.to_str().ok())
.map(From::from);
ct_len.map(|x| info!("File Length: {}", x));
ct_type.map(|x| info!("Content Type: {}", x));
if let Some(ct_len) = ct_len {
info!("File Length: {}", ct_len);
}
if let Some(ct_type) = ct_type {
info!("Content Type: {}", ct_type);
}
let ext = get_ext(ct_type).unwrap_or_else(|| String::from("unknown"));
info!("Extension: {}", ext);
......@@ -115,13 +117,13 @@ fn download_into(
let tempdir = TempDir::new_in(PODCASTS_CACHE.to_str().unwrap(), "temp_download")?;
let out_file = format!("{}/temp.part", tempdir.path().to_str().unwrap(),);
ct_len.map(|x| {
if let Some(ct_len) = ct_len {
if let Some(ref p) = progress {
if let Ok(mut m) = p.lock() {
m.set_size(x);
m.set_size(ct_len);
}
}
});
};
// Save requested content into the file.
save_io(&out_file, &mut resp, ct_len, progress)?;
......@@ -139,7 +141,7 @@ fn download_into(
/// Determine the file extension from the http content-type header.
fn get_ext(content: Option<&str>) -> Option<String> {
let mut iter = content?.split("/");
let mut iter = content?.split('/');
let type_ = iter.next()?;
let subtype = iter.next()?;
mime_guess::get_extensions(type_, subtype).and_then(|c| {
......@@ -237,26 +239,25 @@ pub fn get_episode(
pub fn cache_image(pd: &ShowCoverModel) -> Result<String, DownloadError> {
let url = pd
.image_uri()
.ok_or_else(|| DownloadError::NoImageLocation)?
.ok_or(DownloadError::NoImageLocation)?
.to_owned();
if url == "" {
if url.is_empty() {
return Err(DownloadError::NoImageLocation);
}
let cache_path = PODCASTS_CACHE
.to_str()
.ok_or_else(|| DownloadError::InvalidCacheLocation)?;
.ok_or(DownloadError::InvalidCacheLocation)?;
let cache_download_fold = format!("{}{}", cache_path, pd.title().to_owned());
// Weird glob magic.
if let Ok(mut foo) = glob(&format!("{}/cover.*", cache_download_fold)) {
// For some reason there is no .first() method so nth(0) is used
let path = foo.nth(0).and_then(|x| x.ok());
if let Ok(mut paths) = glob(&format!("{}/cover.*", cache_download_fold)) {
let path = paths.next().and_then(|x| x.ok());
if let Some(p) = path {
return Ok(p
.to_str()
.ok_or_else(|| DownloadError::InvalidCachedImageLocation)?
.ok_or(DownloadError::InvalidCachedImageLocation)?
.into());
}
};
......
......@@ -17,15 +17,8 @@
//
// SPDX-License-Identifier: GPL-3.0-or-later
use diesel;
use diesel::r2d2;
use diesel_migrations::RunMigrationsError;
use http;
use hyper;
use native_tls;
use reqwest;
use rss;
use xml;
use std::io;
......
......@@ -19,8 +19,6 @@
//! Index Feeds.
use rss;
use crate::dbqueries;
use crate::errors::DataError;
use crate::models::{Index, IndexState, Update};
......
......@@ -108,7 +108,6 @@ pub const USER_AGENT: &str = "Mozilla/5.0 (Windows NT 6.1; rv:60.0) Gecko/201001
#[allow(missing_debug_implementations)]
pub mod xdg_dirs {
use std::path::PathBuf;
use xdg;
lazy_static! {
pub(crate) static ref PODCASTS_XDG: xdg::BaseDirectories = {
......
......@@ -18,7 +18,7 @@
// SPDX-License-Identifier: GPL-3.0-or-later
use chrono::prelude::*;
use diesel;
use diesel::prelude::*;
use diesel::SaveChangesDsl;
......@@ -76,7 +76,7 @@ impl Episode {
///
/// Represents the url(usually) that the media file will be located at.
pub fn uri(&self) -> Option<&str> {
self.uri.as_ref().map(|s| s.as_str())
self.uri.as_deref()
}
/// Get the value of the `local_uri`.
......@@ -84,17 +84,17 @@ impl Episode {
/// Represents the local uri,usually filesystem path,
/// that the media file will be located at.
pub fn local_uri(&self) -> Option<&str> {
self.local_uri.as_ref().map(|s| s.as_str())
self.local_uri.as_deref()
}
/// Get the `description`.
pub fn description(&self) -> Option<&str> {
self.description.as_ref().map(|s| s.as_str())
self.description.as_deref()
}
/// Get the Episode's `guid`.
pub fn guid(&self) -> Option<&str> {
self.guid.as_ref().map(|s| s.as_str())
self.guid.as_deref()
}
/// Get the `epoch` value.
......@@ -199,7 +199,7 @@ impl EpisodeWidgetModel {
///
/// Represents the url(usually) that the media file will be located at.
pub fn uri(&self) -> Option<&str> {
self.uri.as_ref().map(|s| s.as_str())
self.uri.as_deref()
}
/// Get the value of the `local_uri`.
......@@ -207,7 +207,7 @@ impl EpisodeWidgetModel {
/// Represents the local uri,usually filesystem path,
/// that the media file will be located at.
pub fn local_uri(&self) -> Option<&str> {
self.local_uri.as_ref().map(|s| s.as_str())
self.local_uri.as_deref()
}
/// Set the `local_uri`.
......@@ -318,7 +318,7 @@ impl EpisodeCleanerModel {
/// Represents the local uri,usually filesystem path,
/// that the media file will be located at.
pub fn local_uri(&self) -> Option<&str> {
self.local_uri.as_ref().map(|s| s.as_str())
self.local_uri.as_deref()
}
/// Set the `local_uri`.
......@@ -386,12 +386,12 @@ impl EpisodeMinimal {
///
/// Represents the url(usually) that the media file will be located at.
pub fn uri(&self) -> Option<&str> {
self.uri.as_ref().map(|s| s.as_str())
self.uri.as_deref()
}
/// Get the Episode's `guid`.
pub fn guid(&self) -> Option<&str> {
self.guid.as_ref().map(|s| s.as_str())
self.guid.as_deref()
}
/// Get the `epoch` value.
......
......@@ -17,11 +17,8 @@
//
// SPDX-License-Identifier: GPL-3.0-or-later
use ammonia;
use diesel;
use diesel::prelude::*;
use rfc822_sanitizer::parse_from_rfc2822_with_fallback as parse_rfc822;
use rss;
use crate::database::connection;
use crate::dbqueries;
......@@ -163,15 +160,15 @@ impl NewEpisode {
}
pub(crate) fn uri(&self) -> Option<&str> {
self.uri.as_ref().map(|s| s.as_str())
self.uri.as_deref()
}
pub(crate) fn description(&self) -> Option<&str> {
self.description.as_ref().map(|s| s.as_str())
self.description.as_deref()
}
pub(crate) fn guid(&self) -> Option<&str> {
self.guid.as_ref().map(|s| s.as_str())
self.guid.as_deref()
}
pub(crate) fn epoch(&self) -> i32 {
......@@ -278,13 +275,13 @@ impl NewEpisodeMinimal {
// TODO: TryInto is stabilizing in rustc v1.26!
// ^ Jokes on you past self!
pub(crate) fn into_new_episode(self, item: &rss::Item) -> NewEpisode {
let description = item.description().and_then(|s| {
let description = item.description().map(|s| {
let sanitized_html = ammonia::Builder::new()
// Remove `rel` attributes from `<a>` tags
.link_rel(None)
.clean(s.trim())
.to_string();
Some(sanitized_html)
sanitized_html
});
NewEpisodeBuilder::default()
......@@ -308,11 +305,11 @@ impl NewEpisodeMinimal {
}
pub(crate) fn uri(&self) -> Option<&str> {
self.uri.as_ref().map(|s| s.as_str())
self.uri.as_deref()
}
pub(crate) fn guid(&self) -> Option<&str> {
self.guid.as_ref().map(|s| s.as_str())
self.guid.as_deref()
}
pub(crate) fn duration(&self) -> Option<i32> {
......
......@@ -17,10 +17,7 @@
//
// SPDX-License-Identifier: GPL-3.0-or-later
use ammonia;
use diesel;
use diesel::prelude::*;
use rss;
use crate::errors::DataError;
use crate::models::Show;
......@@ -190,7 +187,7 @@ impl NewShow {
}
pub(crate) fn image_uri(&self) -> Option<&str> {
self.image_uri.as_ref().map(|s| s.as_str())
self.image_uri.as_deref()
}
#[cfg(test)]
......
......@@ -17,7 +17,6 @@
//
// SPDX-License-Identifier: GPL-3.0-or-later
use diesel;
use diesel::prelude::*;
use url::Url;
......
......@@ -71,7 +71,7 @@ impl Show {
///
/// Represents the uri(url usually) that the Feed cover image is located at.
pub fn image_uri(&self) -> Option<&str> {
self.image_uri.as_ref().map(|s| s.as_str())
self.image_uri.as_deref()
}
/// Get the `image_uri_hash`.
......@@ -135,10 +135,7 @@ impl Show {
}
},
}
match self.update_image_cached() {
Ok(s) => Ok(s),
Err(e) => Err(e),
}
self.update_image_cached()
}
}
......@@ -180,7 +177,7 @@ impl ShowCoverModel {
///
/// Represents the uri(url usually) that the Feed cover image is located at.
pub fn image_uri(&self) -> Option<&str> {
self.image_uri.as_ref().map(|s| s.as_str())
self.image_uri.as_deref()
}
/// Get the `image_uri_hash`.
......
......@@ -87,7 +87,7 @@ impl Source {
///
/// See [RFC 7231](https://tools.ietf.org/html/rfc7231#section-7.2) for more.
pub fn last_modified(&self) -> Option<&str> {
self.last_modified.as_ref().map(|s| s.as_str())
self.last_modified.as_deref()
}
/// Set `last_modified` value.
......@@ -100,7 +100,7 @@ impl Source {
///
/// See [RFC 7231](https://tools.ietf.org/html/rfc7231#section-7.2) for more.
pub fn http_etag(&self) -> Option<&str> {
self.http_etag.as_ref().map(|s| s.as_str())
self.http_etag.as_deref()
}
/// Set `http_etag` value.
......@@ -325,7 +325,6 @@ async fn response_to_channel(res: Response<Body>) -> Result<Channel, DataError>
mod tests {
use super::*;
use anyhow::Result;
use tokio;
use crate::database::truncate_db;
use crate::utils::get_feed;
......
......@@ -114,7 +114,7 @@ pub fn export_to_file<F: Write>(file: F, export_title: &str) -> Result<()> {
let title_ev: XmlEvent<'_> = XmlEvent::start_element("title").into();
events.push(title_ev);
let title_chars: XmlEvent<'_> = XmlEvent::characters(export_title).into();
let title_chars: XmlEvent<'_> = XmlEvent::characters(export_title);
events.push(title_chars);
// Close <title> & <head>
......@@ -268,7 +268,6 @@ mod tests {
American—and global—politics.",
);
#[cfg_attr(rustfmt, rustfmt_skip)]
let sample1 = format!(
"<?xml version=\"1.0\" encoding=\"UTF-8\"?> \
<opml version=\"2.0\"> \
......
......@@ -38,7 +38,7 @@ use std::path::Path;
/// The resulting vector will always have exactly 8 values.
/// The individual bytes are extracted from the given `u64`, which is parsed as little-endian.
pub fn u64_to_vec_u8(u: u64) -> Vec<u8> {
let bytes: Vec<u8> = u.to_le_bytes().iter().cloned().collect();
let bytes: Vec<u8> = u.to_le_bytes().to_vec();
debug_assert_eq!(bytes.len(), 8);
bytes
}
......@@ -281,7 +281,7 @@ mod tests {
fn test_download_cleaner() -> Result<()> {
let _tmp_dir = helper_db()?;
let mut episode: EpisodeCleanerModel =
dbqueries::get_episode_cleaner_from_pk("foo_bar", 0)?.into();
dbqueries::get_episode_cleaner_from_pk("foo_bar", 0)?;
let valid_path = episode.local_uri().unwrap().to_owned();
delete_local_content(&mut episode)?;
......
......@@ -26,7 +26,6 @@ use glib::{glib_object_impl, glib_object_subclass, glib_object_wrapper, glib_wra
use gio::subclass::ApplicationImplExt;
use gio::{self, prelude::*, ActionMapExt, ApplicationFlags, SettingsExt};
use gtk;
use gtk::prelude::*;
use gettextrs::{bindtextdomain, setlocale, textdomain, LocaleCategory};
......@@ -304,13 +303,13 @@ impl PdApplication {
updater.set_spinner_state(SpinnerState::Active);
let old = window.updater.replace(Some(updater));
old.map(|i| unsafe { i.destroy() });
if let Some(i) = old {
unsafe { i.destroy() }
}
window
.updater
.borrow()
.as_ref()
.map(|i| i.show(&window.overlay));
if let Some(i) = window.updater.borrow().as_ref() {
i.show(&window.overlay)
}
}
Action::InitEpisode(rowid) => {
let res = window.player.initialize_episode(rowid);
......@@ -321,23 +320,25 @@ impl PdApplication {
window.headerbar.set_secondary_menu(menu);
}
Action::EmptyState => {
window
if let Some(refresh_action) = window
.window
.lookup_action("refresh")
.and_then(|action| action.downcast::<gio::SimpleAction>().ok())
// Disable refresh action
.map(|action| action.set_enabled(false));
{
refresh_action.set_enabled(false)
}
window.headerbar.switch.set_sensitive(false);
window.content.switch_to_empty_views();
}
Action::PopulatedState => {
window
if let Some(refresh_action) = window
.window
.lookup_action("refresh")
.and_then(|action| action.downcast::<gio::SimpleAction>().ok())
// Enable refresh action
.map(|action| action.set_enabled(true));
{
refresh_action.set_enabled(true)
}
window.headerbar.switch.set_sensitive(true);
window.content.switch_to_populated();
......
......@@ -17,16 +17,12 @@
//
// SPDX-License-Identifier: GPL-3.0-or-later
use gio;
use glib::clone;
use gtk;
use gtk::prelude::*;
use libhandy;
use libhandy::prelude::*;
use anyhow::Result;
use glib::Sender;
use rayon;
use url::Url;
use podcasts_data::{dbqueries, Source};
......@@ -65,20 +61,20 @@ struct AddPopover {
async fn add_podcast_from_url(url_input: String, sender: &Sender<Action>) -> Result<()> {
let mut url = url_input;
if !(url.starts_with("https://") || url.starts_with("http://")) {
url = format!("http://{}", url).into();
url = format!("http://{}", url);
};
debug!("Url: {}", url);
let url = if url.contains("itunes.com") || url.contains("apple.com") {
info!("Detected itunes url.");
let foo = itunes_to_rss(&url).await?;
info!("Resolved to {}", foo);
foo
let itunes_url = itunes_to_rss(&url).await?;
info!("Resolved to {}", itunes_url);
itunes_url
} else if url.contains("soundcloud.com") && !url.contains("feeds.soundcloud.com") {
info!("Detected soundcloud url.");
let foo = soundcloud_to_rss(&Url::parse(&url)?).await?;
info!("Resolved to {}", foo);
foo.to_string()
let soundcloud_url = soundcloud_to_rss(&Url::parse(&url)?).await?;
info!("Resolved to {}", soundcloud_url);
soundcloud_url.to_string()
} else {
url.to_owned()
};
......
......@@ -34,11 +34,11 @@ fn freplace(input: String, args: &[&str]) -> String {
#[allow(dead_code)]
fn kreplace(input: String, kwargs: &[(&str, &str)]) -> String {
let mut s = input.clone();
let mut s = input;
for (k, v) in kwargs {
if let Ok(re) = Regex::new(&format!("\\{{{}\\}}", k)) {
s = re
.replace_all(&s, |_: &Captures<'_>| v.to_string().clone())
.replace_all(&s, |_: &Captures<'_>| v.to_string())
.to_string();
}
}
......
......@@ -34,6 +34,7 @@
elided_lifetimes_in_paths,
missing_copy_implementations
)]
#![allow(clippy::type_complexity)]
#[macro_use]
extern crate lazy_static;
......
......@@ -18,16 +18,12 @@
// SPDX-License-Identifier: GPL-3.0-or-later
use anyhow::{anyhow, Result};
use rayon;
// use podcasts_data::Episode;
use podcasts_data::dbqueries;
use podcasts_data::downloader::{get_episode, DownloadProgress};
use std::collections::HashMap;
use std::sync::{Arc, Mutex, RwLock};
// use std::sync::atomic::AtomicUsize;
// use std::path::PathBuf;
// This is messy, undocumented and hacky af.
// I am terrible at writing downloaders and download managers.
......@@ -112,8 +108,8 @@ pub(crate) fn add(id: i32, directory: String) -> Result<()> {
.ok();
if let Ok(mut m) = ACTIVE_DOWNLOADS.write() {
let foo = m.remove(&id);
debug!("Removed: {:?}", foo);
let progress = m.remove(&id);
debug!("Removed: {:?}", progress);
}
// if let Ok(m) = ACTIVE_DOWNLOADS.read() {
......
......@@ -16,10 +16,7 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
// SPDX-License-Identifier: GPL-3.0-or-later
use gio;
use gio::{Settings, SettingsExt};
use gtk;
use gtk::GtkWindowExt;
use libhandy as hdy;
......
......@@ -17,7 +17,6 @@
//
// SPDX-License-Identifier: GPL-3.0-or-later
use gtk;
use gtk::prelude::*;
use anyhow::Result;
......
......@@ -17,7 +17,6 @@
//
// SPDX-License-Identifier: GPL-3.0-or-later
use gtk;
use gtk::prelude::*;
use gtk::StackTransitionType;
......
......@@ -17,7 +17,6 @@
//
// SPDX-License-Identifier: GPL-3.0-or-later
use gtk;
use gtk::prelude::*;
use gtk::StackTransitionType;