Skip to content

Commit

Permalink
Merge branch 'development' into fix/notifications-and-cw
Browse files Browse the repository at this point in the history
  • Loading branch information
elpiel committed Aug 10, 2023
2 parents a4238b9 + de6e58a commit 5e3931c
Show file tree
Hide file tree
Showing 26 changed files with 201 additions and 121 deletions.
11 changes: 5 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,23 @@ on: [push]

# Stops the running workflow of previous pushes
concurrency:
group: ${{ github.ref }}
# cancel per workflow
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

env:
RUST_VERSION: stable

jobs:
build:
name: Lint, test and build
runs-on: ubuntu-latest

steps:
- name: Set default Rust version - ${{ env.RUST_VERSION }}
run: rustup default ${{ env.RUST_VERSION }}

- name: Checkout
uses: actions/checkout@v3

- name: Rust setup (stable)
uses: dtolnay/rust-toolchain@stable

- name: Lint - rustfmt
run: cargo fmt --all -- --check

Expand Down
8 changes: 6 additions & 2 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,24 @@ jobs:
- uses: actions/checkout@v3
with:
submodules: true
- uses: actions-rs/toolchain@v1

- name: Rust setup (nightly)
uses: dtolnay/rust-toolchain@master
with:
# Use nightly to build the docs with `--cfg docsrs`
toolchain: nightly
profile: minimal
components: rust-docs

- name: Build docs
# Building locally:
# for `--enable-index-page` it is required to pass `-Z unstable-options` to rustdocs
run: RUSTDOCFLAGS="--cfg docsrs -Z unstable-options --enable-index-page" cargo +nightly doc --all-features --no-deps --workspace

- name: Prepare /docs
run: |
rm -rf ./docs
mv target/doc ./docs
- name: Deploy gh-pages
uses: peaceiris/actions-gh-pages@v3
with:
Expand Down
17 changes: 11 additions & 6 deletions .github/workflows/msrv.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,32 @@
name: MSRV 1.60 build
name: MSRV build

on:
# will checkout the default branch `development`
schedule:
# run every Friday at 17:00
- cron: '00 17 * * 5'
# Or ran manually
workflow_dispatch:

# Stops the running workflow of previous pushes
concurrency:
group: ${{ github.ref }}
# cancel per workflow
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

env:
RUST_MSRV_VERSION: '1.60'
RUST_MSRV_VERSION: '1.67.1'

jobs:
build:
name: Test and build --release
name: Test and build
runs-on: ubuntu-latest

steps:
- name: Set default Rust version - ${{ env.RUST_MSRV_VERSION }}
run: rustup default ${{ env.RUST_MSRV_VERSION }}
- name: Rust setup (MSRV)
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ env.RUST_MSRV_VERSION }}

- name: Checkout
uses: actions/checkout@v3
Expand Down
22 changes: 14 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@
name = "stremio-core"
version = "0.1.0"
authors = ["Smart Code OOD"]
edition = "2018"
edition = "2021"

rust-version = "1.60"
rust-version = "1.67.1"

[workspace]
members = [
"stremio-derive",
"stremio-analytics",
"stremio-watched-bitfield",
]

Expand All @@ -20,20 +19,27 @@ doctest = false
# TODO: env-future-send should be enabled by default
# but our `TestEnv` for `unit_tests` uses a MutexGuard which is not Send.
# default = ["env-future-send"]
default = []

# Adds `Send` marker trait to the `Env` trait methods and `EnvFuture`.
# It's required for environments that do not support `Send`.
# If enabled for `wasm` it will cause a compile error!
# see https://github.com/rustwasm/wasm-bindgen/issues/2833
env-future-send = []

# Exports the Model derive macro from `stremio-derive`
derive = []

# Enable core analytics
analytics = []

[dependencies]
stremio-derive = { path = "stremio-derive" }
stremio-watched-bitfield = { path = "stremio-watched-bitfield" }
stremio-official-addons = "=2.0.10"

# (De)Serialization
serde = "1.0.*"
serde = { version = "1", features = ["derive"]}
serde_json = "1.0.*"
serde_url_params = "0.2.*"
serde_bencode = "0.2.*"
Expand All @@ -51,20 +57,20 @@ percent-encoding = "2.1"
chrono = { version = "0.4", features = ["serde"] }

semver = { version = "1", features = ["serde"] }
base64 = { version = "0.21"}
base64 = "0.21"
sha1 = "0.10"
either = "1.6"
enclose = "1.1"
derivative = "2.2"
derive_more = "0.99"
boolinator = "2.4.*"
strum = { version = "0.24", features = ["derive"] }
boolinator = "2.4"
strum = { version = "0.25", features = ["derive"] }

lazysort = "0.2"

lazy_static = "1.4"
once_cell = "1.4"
itertools = "0.10"
itertools = "0.11"

magnet-url = "2.0"
hex = "0.4"
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
## Stremio - the next generation media center
[![Build Workflow Status](https://img.shields.io/github/actions/workflow/status/Stremio/stremio-core/build.yml?label=Build)](https://github.com/Stremio/stremio-core/actions/workflows/build.yml)
[![Latest MSRV workflow Status](https://img.shields.io/github/actions/workflow/status/Stremio/stremio-core/msrv.yml?label=MSRV)](https://github.com/Stremio/stremio-core/actions/workflows/msrv.yml)
[![Latest deployed docs on GH pages](https://img.shields.io/github/actions/workflow/status/Stremio/stremio-core/docs.yml?event=workflow_dispatch&label=Latest%20deployed%20Docs)](https://stremio.github.io/stremio-core)

Stremio is a full-featured media center designed to help you organize and stream your favorite videos, movies and TV series. It will notify you for new episodes / movies, and allow you to find new content through Discover.

Expand Down
34 changes: 21 additions & 13 deletions stremio-analytics/src/lib.rs → src/analytics.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
use std::{
collections::VecDeque,
marker::PhantomData,
sync::{Arc, Mutex},
};

use derivative::Derivative;
use enclose::enclose;
use futures::future::Either;
use futures::{future, Future, FutureExt};
use futures::{
future::{self, Either},
Future, FutureExt,
};
use serde::Serialize;
use std::collections::VecDeque;
use std::marker::PhantomData;
use std::sync::{Arc, Mutex};
use stremio_core::models::ctx::Ctx;
use stremio_core::models::streaming_server::StreamingServer;
#[cfg(debug_assertions)]
use stremio_core::runtime::EnvFutureExt;
use stremio_core::runtime::{Env, EnvError, TryEnvFuture};
use stremio_core::types::api::{fetch_api, APIRequest, APIResult, SuccessResponse};
use stremio_core::types::profile::AuthKey;

use crate::{
models::{ctx::Ctx, streaming_server::StreamingServer},
runtime::{Env, EnvError, TryEnvFuture},
types::{
api::{fetch_api, APIRequest, APIResult, SuccessResponse},
profile::AuthKey,
},
};

#[cfg(debug_assertions)]
use stremio_core::types::True;
use crate::{runtime::EnvFutureExt, types::True};

#[derive(Clone, PartialEq, Serialize, Debug)]
struct Event {
Expand Down
2 changes: 1 addition & 1 deletion src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub const SCHEMA_VERSION: u32 = 7;
pub const IMDB_LINK_CATEGORY: &str = "imdb";
pub const GENRES_LINK_CATEGORY: &str = "Genres";
pub const CINEMETA_TOP_CATALOG_ID: &str = "top";
/// Only found in Cinemeta catalogs, i.e. [`CINEMETA_CATALOGS_URL`]
/// Only found in Cinemeta catalogs, i.e. [`CINEMETA_CATALOGS_URL`](struct@CINEMETA_CATALOGS_URL)
pub const CINEMETA_FEED_CATALOG_ID: &str = "feed.json";
pub const IMDB_TITLE_PATH: &str = "title";
pub const YOUTUBE_ADDON_ID_PREFIX: &str = "yt_id:";
Expand Down
47 changes: 36 additions & 11 deletions src/deep_links/mod.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
mod error_link;

use crate::constants::URI_COMPONENT_ENCODE_SET;
use crate::deep_links::error_link::ErrorLink;
use crate::models::installed_addons_with_filters::InstalledAddonsRequest;
use crate::models::library_with_filters::LibraryRequest;
use crate::types::addon::{ExtraValue, ResourcePath, ResourceRequest};
use crate::types::library::LibraryItem;
use crate::types::profile::Settings;
use crate::types::query_params_encode;
use crate::types::resource::{MetaItem, MetaItemPreview, Stream, StreamSource, Video};
use percent_encoding::utf8_percent_encode;
use regex::Regex;
use serde::Serialize;
use url::Url;

use crate::{
constants::URI_COMPONENT_ENCODE_SET,
models::{
installed_addons_with_filters::InstalledAddonsRequest, library_with_filters::LibraryRequest,
},
types::{
addon::{ExtraValue, ResourcePath, ResourceRequest},
library::LibraryItem,
profile::Settings,
query_params_encode,
resource::{MetaItem, MetaItemPreview, Stream, StreamSource, Video},
},
};

pub use error_link::ErrorLink;

mod error_link;

#[derive(Default, Serialize, Debug, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct OpenPlayerLink {
Expand Down Expand Up @@ -42,6 +49,12 @@ pub struct ExternalPlayerLink {
}

impl From<(&Stream, &Option<Url>, &Settings)> for ExternalPlayerLink {
/// Create an [`ExternalPlayerLink`] using the [`Stream`],
/// the server url (from [`StreamingServer::base_url`] which indicates a running or not server)
/// and the user's [`Settings`] in order to use the [`Settings::player_type`] for generating a
/// player-specific url.
///
/// [`StreamingServer::base_url`]: crate::models::streaming_server::StreamingServer::base_url
fn from((stream, streaming_server_url, settings): (&Stream, &Option<Url>, &Settings)) -> Self {
let http_regex = Regex::new(r"https?://").unwrap();
let download = stream.download_url();
Expand Down Expand Up @@ -301,6 +314,12 @@ pub struct StreamDeepLinks {
}

impl From<(&Stream, &Option<Url>, &Settings)> for StreamDeepLinks {
/// Create a [`StreamDeepLinks`] using the [`Stream`],
/// the server url (from [`StreamingServer::base_url`] which indicates a running or not server)
/// and the user's [`Settings`] in order to use the [`Settings::player_type`] for generating a
/// player-specific url.
///
/// [`StreamingServer::base_url`]: crate::models::streaming_server::StreamingServer::base_url
fn from((stream, streaming_server_url, settings): (&Stream, &Option<Url>, &Settings)) -> Self {
StreamDeepLinks {
player: stream
Expand All @@ -326,6 +345,12 @@ impl
&Settings,
)> for StreamDeepLinks
{
/// Create a [`StreamDeepLinks`] using the [`Stream`], stream request, meta request,
/// the server url (from [`StreamingServer::base_url`] which indicates a running or not server)
/// and the user's [`Settings`] in order to use the [`Settings::player_type`] for generating a
/// player-specific url.
///
/// [`StreamingServer::base_url`]: crate::models::streaming_server::StreamingServer::base_url
fn from(
(stream, stream_request, meta_request, streaming_server_url, settings): (
&Stream,
Expand Down
8 changes: 8 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
//! # Stremio core
#![allow(clippy::module_inception)]
// Do not allow broken intra doc links
#![deny(rustdoc::broken_intra_doc_links)]
// TODO: Fix async tests that trigger this lock warning
#![cfg_attr(test, allow(clippy::await_holding_lock))]

// Re-export of the derive macro for Model which removes the need for
// depending on `stremio-derive` everywhere.
#[cfg(feature = "derive")]
pub use stremio_derive::Model;

pub mod addon_transport;
#[cfg(feature = "analytics")]
pub mod analytics;
pub mod deep_links;
pub mod models;
pub mod runtime;
Expand Down
2 changes: 0 additions & 2 deletions src/models/continue_watching_preview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ impl<E: Env + 'static> UpdateWithCtx<E> for ContinueWatchingPreview {
match msg {
// library has changed
Msg::Internal(Internal::LibraryChanged(true))
// LibraryItem has been updated (this message alters the `mtime` and will re-order the CW list)
| Msg::Internal(Internal::UpdateLibraryItem(_))
// notifications have been updated
| Msg::Internal(Internal::NotificationsChanged) => {
library_items_update(&mut self.library_items, &ctx.library, &ctx.notifications)
Expand Down
21 changes: 19 additions & 2 deletions src/models/ctx/update_library.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use crate::types::api::{
};
use crate::types::library::{LibraryBucket, LibraryBucketRef, LibraryItem};
use crate::types::profile::{AuthKey, Profile};
use chrono::Utc;
use futures::future::Either;
use futures::{future, FutureExt, TryFutureExt};
use std::collections::HashMap;
Expand Down Expand Up @@ -67,7 +66,7 @@ pub fn update_library<E: Env + 'static>(
Some(library_item) => {
let mut library_item = library_item.to_owned();
library_item.state.time_offset = 0;
library_item.state.last_watched = Some(Utc::now());
library_item.state.last_watched = Some(E::now());
Effects::msg(Msg::Internal(Internal::UpdateLibraryItem(library_item)))
.join(Effects::msg(Msg::Event(Event::LibraryItemRewinded {
id: id.to_owned(),
Expand All @@ -80,6 +79,24 @@ pub fn update_library<E: Env + 'static>(
}))
.unchanged(),
},
Msg::Action(Action::Ctx(ActionCtx::ToggleLibraryItemNotifications(id, state))) => {
match library.items.get(id) {
Some(library_item) => {
let mut library_item = library_item.to_owned();
library_item.state.no_notif = *state;
Effects::msg(Msg::Internal(Internal::UpdateLibraryItem(library_item)))
.join(Effects::msg(Msg::Event(
Event::LibraryItemNotificationsToggled { id: id.to_owned() },
)))
.unchanged()
}
_ => Effects::msg(Msg::Event(Event::Error {
error: CtxError::from(OtherError::LibraryItemNotFound),
source: Box::new(Event::LibraryItemNotificationsToggled { id: id.to_owned() }),
}))
.unchanged(),
}
}
Msg::Action(Action::Ctx(ActionCtx::SyncLibraryWithAPI)) => match auth_key {
Some(auth_key) => Effects::one(plan_sync_with_api::<E>(library, auth_key)).unchanged(),
_ => Effects::msg(Msg::Event(Event::Error {
Expand Down
Loading

0 comments on commit 5e3931c

Please sign in to comment.