1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
use crate::types::addon::{Descriptor, ExtraProp, OptionsLimit};
use lazy_static::lazy_static;
use percent_encoding::{AsciiSet, NON_ALPHANUMERIC};
use std::collections::HashMap;
use url::Url;

pub const SCHEMA_VERSION_STORAGE_KEY: &str = "schema_version";
pub const PROFILE_STORAGE_KEY: &str = "profile";
pub const LIBRARY_STORAGE_KEY: &str = "library";
pub const LIBRARY_RECENT_STORAGE_KEY: &str = "library_recent";
pub const STREAMS_STORAGE_KEY: &str = "streams";
pub const SEARCH_HISTORY_STORAGE_KEY: &str = "search_history";
pub const NOTIFICATIONS_STORAGE_KEY: &str = "notifications";
pub const DISMISSED_EVENTS_STORAGE_KEY: &str = "dismissed_events";
pub const LIBRARY_COLLECTION_NAME: &str = "libraryItem";
pub const SEARCH_EXTRA_NAME: &str = "search";
/// `https://{ADDON_UR}/meta/...` resource
pub const META_RESOURCE_NAME: &str = "meta";
pub const STREAM_RESOURCE_NAME: &str = "stream";
/// `https://{ADDON_URL}/catalog/...` resource
pub const CATALOG_RESOURCE_NAME: &str = "catalog";
pub const SUBTITLES_RESOURCE_NAME: &str = "subtitles";
pub const ADDON_MANIFEST_PATH: &str = "/manifest.json";
pub const ADDON_LEGACY_PATH: &str = "/stremio/v1";
pub const CATALOG_PAGE_SIZE: usize = 100;
pub const CATALOG_PREVIEW_SIZE: usize = 100;
pub const LIBRARY_RECENT_COUNT: usize = 200;
pub const NOTIFICATION_ITEMS_COUNT: usize = 100;

/// A `LibraryItem` is considered watched once we've watched more than the `duration * threshold`:
///
/// `LibraryItem.state.time_watched` > `LibraryItem.state.duration` * [`WATCHED_THRESHOLD_COEF`]
pub const WATCHED_THRESHOLD_COEF: f64 = 0.7;
pub const CREDITS_THRESHOLD_COEF: f64 = 0.9;
/// The latest migration scheme version
pub const SCHEMA_VERSION: u32 = 14;
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`](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:";
pub const URI_COMPONENT_ENCODE_SET: &AsciiSet = &NON_ALPHANUMERIC
    .remove(b'-')
    .remove(b'_')
    .remove(b'.')
    .remove(b'!')
    .remove(b'~')
    .remove(b'*')
    .remove(b'\'')
    .remove(b'(')
    .remove(b')');

/// In milliseconds
pub const PLAYER_IGNORE_SEEK_AFTER: u64 = 600_000;

pub static BASE64: base64::engine::general_purpose::GeneralPurpose =
    base64::engine::general_purpose::STANDARD;

lazy_static! {
    pub static ref CINEMETA_CATALOGS_URL: Url = Url::parse("https://cinemeta-catalogs.strem.io")
        .expect("CINEMETA_URL parse failed");

    /// Manifest URL for Cinemeta V3
    pub static ref CINEMETA_URL: Url = Url::parse("https://v3-cinemeta.strem.io/manifest.json")
        .expect("CINEMETA_URL parse failed");
    pub static ref API_URL: Url = Url::parse("https://api.strem.io").expect("API_URL parse failed");
    pub static ref LINK_API_URL: Url =
        Url::parse("https://link.stremio.com").expect("LINK_API_URL parse failed");
    pub static ref STREAMING_SERVER_URL: Url =
        Url::parse("http://127.0.0.1:11470").expect("STREAMING_SERVER_URL parse failed");
    pub static ref IMDB_URL: Url = Url::parse("https://imdb.com").expect("IMDB_URL parse failed");
    pub static ref OFFICIAL_ADDONS: Vec<Descriptor> =
        serde_json::from_slice(stremio_official_addons::ADDONS)
            .expect("OFFICIAL_ADDONS parse failed");
    pub static ref SKIP_EXTRA_PROP: ExtraProp = ExtraProp {
        name: "skip".to_owned(),
        is_required: false,
        options: vec![],
        options_limit: OptionsLimit::default(),
    };
    pub static ref VIDEO_HASH_EXTRA_PROP: ExtraProp = ExtraProp {
        name: "videoHash".to_owned(),
        is_required: false,
        options: vec![],
        options_limit: OptionsLimit::default(),
    };
    pub static ref VIDEO_SIZE_EXTRA_PROP: ExtraProp = ExtraProp {
        name: "videoSize".to_owned(),
        is_required: false,
        options: vec![],
        options_limit: OptionsLimit::default(),
    };
    pub static ref VIDEO_FILENAME_EXTRA_PROP: ExtraProp = ExtraProp {
        name: "filename".to_owned(),
        is_required: false,
        options: vec![],
        options_limit: OptionsLimit::default(),
    };
    pub static ref LAST_VIDEOS_IDS_EXTRA_PROP: ExtraProp = ExtraProp {
        name: "lastVideosIds".to_owned(),
        is_required: false,
        options: vec![],
        options_limit: OptionsLimit(1),
    };
    pub static ref TYPE_PRIORITIES: HashMap<&'static str, i32> = vec![
        ("all", 5),
        ("movie", 4),
        ("series", 3),
        ("channel", 2),
        ("tv", 1),
        ("other", i32::MIN)
    ]
    .into_iter()
    .collect();
}