mirror of
https://github.com/OMGeeky/twba.uploader.git
synced 2026-01-01 08:59:57 +01:00
move data mod out of youtube mod
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
use crate::client::youtube::data::VideoData;
|
||||
use crate::client::youtube::data::{create_youtube_description, create_youtube_title};
|
||||
use crate::client::data::VideoData;
|
||||
use crate::client::data::{create_youtube_description, create_youtube_title};
|
||||
use crate::prelude::*;
|
||||
use crate::CONF;
|
||||
use data::Location;
|
||||
use google_youtube3::api::enums::{PlaylistStatusPrivacyStatusEnum, VideoStatusPrivacyStatusEnum};
|
||||
use google_youtube3::api::Scope;
|
||||
use lazy_static::lazy_static;
|
||||
@@ -15,8 +16,8 @@ use twba_local_db::re_exports::sea_orm::{
|
||||
ActiveModelTrait, ActiveValue, ColumnTrait, DatabaseConnection, EntityTrait, IntoActiveModel,
|
||||
Order, QueryFilter, QueryOrder, QuerySelect,
|
||||
};
|
||||
use youtube::data::Location;
|
||||
|
||||
pub(crate) mod data;
|
||||
mod youtube;
|
||||
|
||||
lazy_static! {
|
||||
@@ -277,14 +278,10 @@ impl UploaderClient {
|
||||
let users = twba_local_db::get_watched_users(&db).await?;
|
||||
for user in users {
|
||||
let user_id = user.id.to_string();
|
||||
let client = youtube::YoutubeClient::new(&YOUTUBE_DEFAULT_SCOPES, Some(user)).await?;
|
||||
let client =
|
||||
youtube::YoutubeClient::new(&YOUTUBE_DEFAULT_SCOPES, Some(user.youtube_id)).await?;
|
||||
clients.insert(user_id, client);
|
||||
}
|
||||
if clients.is_empty() {
|
||||
//insert default user/client
|
||||
let client = youtube::YoutubeClient::new(&YOUTUBE_DEFAULT_SCOPES, None).await?;
|
||||
clients.insert("unknown".into(), client);
|
||||
}
|
||||
|
||||
Ok(Self {
|
||||
db,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::client::youtube::data::substitutions::*;
|
||||
use crate::client::data::substitutions::*;
|
||||
use crate::prelude::*;
|
||||
use crate::CONF;
|
||||
use chrono::{DateTime, Datelike, ParseResult, Utc};
|
||||
@@ -196,8 +196,8 @@ fn parse_date(date: &str) -> ParseResult<DateTime<Utc>> {
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::client::youtube::data::create_youtube_title;
|
||||
use crate::client::youtube::data::Location;
|
||||
use crate::client::data::create_youtube_title;
|
||||
use crate::client::data::Location;
|
||||
use crate::prelude::twba_local_db::prelude::{Status, UsersModel, VideosModel};
|
||||
|
||||
#[test]
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::client::youtube::data::VideoData;
|
||||
use crate::client::data::VideoData;
|
||||
use crate::prelude::*;
|
||||
use google_youtube3::api::{
|
||||
Playlist, PlaylistSnippet, PlaylistStatus, Scope, VideoSnippet, VideoStatus,
|
||||
@@ -14,10 +14,8 @@ use std::fmt::{Debug, Formatter};
|
||||
use std::path::{Path, PathBuf};
|
||||
use tokio::fs;
|
||||
use tracing::instrument;
|
||||
use twba_local_db::prelude::UsersModel;
|
||||
|
||||
mod auth;
|
||||
pub(crate) mod data;
|
||||
mod flow_delegate;
|
||||
|
||||
pub struct YoutubeClient {
|
||||
@@ -150,8 +148,8 @@ impl Debug for YoutubeClient {
|
||||
}
|
||||
|
||||
impl YoutubeClient {
|
||||
#[tracing::instrument(skip(user), fields(user.id = user.as_ref().map(|x| x.id),user.twitch_id = user.as_ref().map(|x| &x.twitch_id)))]
|
||||
pub async fn new(scopes: &Vec<Scope>, user: Option<UsersModel>) -> Result<Self> {
|
||||
#[tracing::instrument]
|
||||
pub async fn new(scopes: &Vec<Scope>, user: Option<String>) -> Result<Self> {
|
||||
let hyper_client = Self::create_hyper_client()?;
|
||||
let application_secret_path = PathBuf::from(
|
||||
&shellexpand::full(&crate::CONF.google.youtube.client_secret_path)
|
||||
@@ -159,12 +157,7 @@ impl YoutubeClient {
|
||||
.to_string(),
|
||||
);
|
||||
|
||||
let auth = auth::get_auth(
|
||||
&application_secret_path,
|
||||
scopes,
|
||||
user.as_ref().map(|x| &x.youtube_id),
|
||||
)
|
||||
.await?;
|
||||
let auth = auth::get_auth(&application_secret_path, scopes, user).await?;
|
||||
let client = google_youtube3::YouTube::new(hyper_client, auth);
|
||||
Ok(Self { client })
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user