Skip to content
Merged
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
50 changes: 33 additions & 17 deletions src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ warp = "0.3.7"
if-addrs = "0.13.4"
tokio-util = "0.7.17"
indexmap = "2.12.1"
futures = "0.3.32"
[target.'cfg(any(target_os = "linux", target_os = "macos"))'.dependencies]
shell-words = "1.1.0"
[target.'cfg(target_os = "windows")'.dependencies]
Expand Down
8 changes: 8 additions & 0 deletions src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::collections::HashMap;

#[cfg(any(target_os = "macos", target_os = "windows"))]
use anyhow::Context;
use anyhow::Error;
Expand Down Expand Up @@ -113,6 +115,7 @@ pub fn run() {
hide_channel,
hide_group,
remove_from_history,
get_all_expiries
])
.setup(|app| {
app.manage(Mutex::new(AppState {
Expand Down Expand Up @@ -561,3 +564,8 @@ async fn cancel_play(
.await
.map_err(map_err_frontend)
}

#[tauri::command]
async fn get_all_expiries() -> Result<HashMap<i64, i64>, String> {
xtream::get_all_expiries().await.map_err(map_err_frontend)
}
11 changes: 11 additions & 0 deletions src-tauri/src/sql.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::vec;
use std::{collections::HashMap, sync::LazyLock};

use crate::log::log;
Expand Down Expand Up @@ -1174,6 +1175,16 @@ pub fn get_sources() -> Result<Vec<Source>> {
Ok(sources)
}

pub fn get_sources_by_type(source_type: u8) -> Result<Vec<Source>> {
let sql = get_conn()?;
let sources: Vec<Source> = sql
.prepare("SELECT * FROM sources WHERE source_type = ?")?
.query_map([source_type], row_to_source)?
.filter_map(Result::ok)
.collect();
Ok(sources)
}

pub fn get_enabled_sources() -> Result<Vec<Source>> {
let sql = get_conn()?;
let sources: Vec<Source> = sql
Expand Down
10 changes: 10 additions & 0 deletions src-tauri/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,16 @@ pub struct Source {
pub last_updated: Option<i64>,
}

#[derive(Clone, PartialEq, Debug, Deserialize, Serialize)]
pub struct XtreamStatus {
pub user_info: XtreamStatusUserInfo,
}

#[derive(Clone, PartialEq, Debug, Deserialize, Serialize)]
pub struct XtreamStatusUserInfo {
pub exp_date: serde_json::Value,
}

#[derive(Clone, PartialEq, Debug, Deserialize, Serialize)]
pub struct Settings {
pub recording_path: Option<String>,
Expand Down
27 changes: 27 additions & 0 deletions src-tauri/src/xtream.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
use crate::log;
use crate::media_type;
use crate::source_type;
use crate::sql;
use crate::sql::insert_season;
use crate::types::Channel;
use crate::types::ChannelPreserve;
use crate::types::EPG;
use crate::types::Season;
use crate::types::Source;
use crate::types::XtreamStatus;
use crate::utils::get_local_time;
use crate::utils::get_user_agent_from_source;
use anyhow::anyhow;
Expand All @@ -16,6 +18,7 @@ use base64::prelude::BASE64_STANDARD;
use chrono::DateTime;
use chrono::Local;
use chrono::NaiveDateTime;
use futures::future::join_all;
use reqwest::Client;
use rusqlite::Transaction;
use serde::Deserialize;
Expand Down Expand Up @@ -588,3 +591,27 @@ fn get_timeshift_url(mut url: Url, start: String, end: String, stream_id: &str)
.append_pair("duration", &duration);
Ok(url.to_string())
}

async fn get_status(source: &mut Source) -> Result<(i64, XtreamStatus)> {
let url = build_xtream_url(source)?;
let user_agent = get_user_agent_from_source(&source)?;
let client = Client::builder().user_agent(user_agent).build()?;
let data = client.get(url).send().await?.json::<XtreamStatus>().await?;
Ok((source.id.context("no id")?, data))
}

pub async fn get_all_expiries() -> Result<HashMap<i64, i64>> {
let mut sources = sql::get_sources_by_type(source_type::XTREAM)?;
let to_await = sources.iter_mut().map(|source| get_status(source));
let results: Vec<std::result::Result<(i64, XtreamStatus), anyhow::Error>> =
join_all(to_await).await;
let statuses: HashMap<i64, i64> = results
.into_iter()
.flatten()
.filter_map(|(id, status)| {
let exp_date = get_serde_json_i64(&status.user_info.exp_date)?;
Some((id, exp_date))
})
.collect();
Ok(statuses)
}
2 changes: 2 additions & 0 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@ import { SortItemComponent } from './home/sort-button/sort-item/sort-item.compon
import { DownloadManagerComponent } from './download-manager/download-manager.component';

import { TimeAgoPipe } from "./pipes/time-ago.pipe";
import { TimeUntilPipe } from './pipes/time-until.pipe';

@NgModule({
declarations: [
AppComponent,
TimeAgoPipe,
TimeUntilPipe,
SetupComponent,
LoadingComponent,
SourceNameExistsValidator,
Expand Down
72 changes: 72 additions & 0 deletions src/app/pipes/time-until.pipe.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { Pipe, PipeTransform } from '@angular/core';

@Pipe({
name: 'timeUntil'
})
export class TimeUntilPipe implements PipeTransform {

transform(value: any): string {
if (!value) return '';

const targetDate = new Date(value);
const now = new Date();
const seconds = Math.floor((targetDate.getTime() - now.getTime()) / 1000);
const formattedDate = this.formatExactDate(targetDate);

if (seconds < 0)
return `Expired (${formattedDate})`;

const intervals: { [key: string]: number } = {
'year': 31536000,
'month': 2592000,
'week': 604800,
'day': 86400,
'hour': 3600
};

let counter;
let relativeString = '';

for (const i in intervals) {
counter = Math.floor(seconds / intervals[i]);
if (counter > 0) {
if (counter === 1) {
relativeString = `In ${counter} ${i}`;
} else {
relativeString = `In ${counter} ${i}s`;
}
break;
}
}

if (!relativeString) {
relativeString = 'In less than an hour';
}

return `${relativeString} (${formattedDate})`;
}

private formatExactDate(date: Date): string {
const monthNames = [
"January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"
];

const month = monthNames[date.getMonth()];
const day = date.getDate();
const year = date.getFullYear();
const suffix = this.getOrdinalSuffix(day);

return `${month} ${day}${suffix} ${year}`;
}

private getOrdinalSuffix(day: number): string {
if (day > 3 && day < 21) return 'th';
switch (day % 10) {
case 1: return "st";
case 2: return "nd";
case 3: return "rd";
default: return "th";
}
}
}
Loading
Loading