Skip to content

Commit f7a285f

Browse files
committed
0.1.0
1 parent ae7d90f commit f7a285f

File tree

10 files changed

+1228
-0
lines changed

10 files changed

+1228
-0
lines changed

.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# DATABASE_URL = sqlite:data/nyaa-comms.sqlite

.github/workflows/tag_release.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Rust
2+
3+
on:
4+
push:
5+
tags:
6+
- '*'
7+
8+
env:
9+
CARGO_TERM_COLOR: always
10+
11+
12+
jobs:
13+
new_tag:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v3
17+
- name: Build linux binary
18+
run: cargo build --release
19+
- name: release
20+
uses: actions/create-release@v1
21+
id: create_release
22+
with:
23+
draft: false
24+
preprelease: false
25+
release_name: ${{ steps.version.outputs.version }}
26+
tag_name: ${{ github.ref }}
27+
body_path: RECENT_CHANGES.md
28+
env:
29+
GITHUB_TOKEN: ${{ github.token }}
30+
- name: upload linux artifact
31+
uses: actions/upload-release-asset@v1
32+
env:
33+
GITHUB_TOKEN: ${{ github.token }}
34+
with:
35+
upload_url: ${{ steps.create_release.outputs.upload_url }}
36+
asset_path: ./target/release/nyaa-notifs
37+
asset_name: nyaa-notifications
38+
asset_content_type: application/octet-stream

Cargo.toml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[package]
2+
name = "nyaa-notifs"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[dependencies]
7+
isahc = "1.7.2"
8+
lettre = { version = "0.10.1", default-features = false, features = ["smtp-transport", "tokio1-rustls-tls", "hostname", "builder"] }
9+
serde = "1.0.144"
10+
serde_derive = "1.0.144"
11+
serenity = { version = "0.11.5", features = ["collector", "rustls_backend"] }
12+
sqlx = { version = "0.6.1", features = ["runtime-tokio-native-tls", "sqlite", "offline"] }
13+
tokio = { version = "1.21.0", features = ["full"] }
14+
toml = "0.5.9"
15+
chrono = "0.4.22"
16+
reqwest = "0.11.11"
17+
http = "0.2.8"
18+
serde_json = "1.0.85"
19+
html-escape = "0.2.11"

README.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
## **Nyaa-Notifications**
2+
3+
*stalk your favourite uploaders and don't miss the drama in the comments*
4+
5+
___
6+
7+
As the rss feed from nyaa doesn't provide comments and anything after the first page, I had to basically strip down the html to retrieve the data I want. Meaning: any changes to nyaa will likely brick this application and make it completely useless... until I fix it.
8+
9+
___
10+
11+
### **Supported notification services:**
12+
+ **SMTP/Mail:** (highlight because of newly found release)
13+
![](https://i.imgur.com/XqPZMZt.png)
14+
+ **Discord-Bot:**
15+
![](https://i.imgur.com/KtzIDv6.png)
16+
* **Gotify:**
17+
![](https://i.imgur.com/9UzbkyP.png)
18+
19+
**Notes:**
20+
- The avatar images of users aren't locally parsed. They are attached using their original gravatar.com link from nyaa. This might be an issue for privacy concerend individuals.
21+
22+
___
23+
24+
### **Important information:**
25+
26+
#### Requirements for input domain:
27+
* Must start at page 1.
28+
* If the input url contains search patterns (aside from "newest"), the script will download all pages to find a new release. This can get your ip **banned** if you input the wrong url. (`complete_result = false`: limits everything to the first page)
29+
30+
#### Config notes:
31+
* To add multiple discord-notification channels, you can just continue the `channel_id` list.
32+
* On the first run, I'd highly suggest you to keep all notification services deactivated, so you don't get spammed with outdated news.
33+
34+
#### Misc:
35+
* All requests are executed two seconds from each other.
36+
37+
___
38+
39+
### **Installation:**
40+
41+
Head over to the releases grab the binary and run it.
42+
The output on the first run will tell you what to do next.
43+
44+
___
45+
46+
Please tell me if you'd like to see a specific feature.

RECENT_CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
### First commit :)

migrations/20220911123513_main.sql

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
-- Add migration script here
2+
CREATE TABLE MAIN (
3+
Category TEXT NO NULL,
4+
Title TEXT NOT NULL,
5+
Comments INTEGER,
6+
Magnet TEXT NOT NULL,
7+
Torrent_File TEXT NOT NULL,
8+
Seeders INTERGER,
9+
Leechers INTEGER,
10+
Completed INTEGER,
11+
Timestamp INTEGER
12+
)

sqlx-data.json

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
{
2+
"db": "SQLite",
3+
"34d9c5386a1f25ca9053d2f1e089b522a22e53347527490bb28f1627d8c85ded": {
4+
"describe": {
5+
"columns": [
6+
{
7+
"name": "Category",
8+
"ordinal": 0,
9+
"type_info": "Text"
10+
},
11+
{
12+
"name": "Title",
13+
"ordinal": 1,
14+
"type_info": "Text"
15+
},
16+
{
17+
"name": "Comments",
18+
"ordinal": 2,
19+
"type_info": "Int64"
20+
},
21+
{
22+
"name": "Magnet",
23+
"ordinal": 3,
24+
"type_info": "Text"
25+
},
26+
{
27+
"name": "Torrent_File",
28+
"ordinal": 4,
29+
"type_info": "Text"
30+
},
31+
{
32+
"name": "Seeders",
33+
"ordinal": 5,
34+
"type_info": "Int64"
35+
},
36+
{
37+
"name": "Leechers",
38+
"ordinal": 6,
39+
"type_info": "Int64"
40+
},
41+
{
42+
"name": "Completed",
43+
"ordinal": 7,
44+
"type_info": "Int64"
45+
},
46+
{
47+
"name": "Timestamp",
48+
"ordinal": 8,
49+
"type_info": "Int64"
50+
}
51+
],
52+
"nullable": [
53+
true,
54+
false,
55+
true,
56+
false,
57+
false,
58+
true,
59+
true,
60+
true,
61+
true
62+
],
63+
"parameters": {
64+
"Right": 0
65+
}
66+
},
67+
"query": "SELECT * FROM Main"
68+
},
69+
"c3c8c8d5f1b005801d9299b01b103c6dc29104d5c593e4cc0f93dc1cc412bb2b": {
70+
"describe": {
71+
"columns": [],
72+
"nullable": [],
73+
"parameters": {
74+
"Right": 9
75+
}
76+
},
77+
"query": "INSERT INTO MAIN (Category, Title, Comments, Magnet, Torrent_File, Seeders, Leechers, Completed, Timestamp) \n VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9)"
78+
}
79+
}

src/database.rs

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
use crate::{NyaaTorrent, Update};
2+
3+
4+
pub async fn updates_to_database(updates: &Vec<Update>) -> Result<(), sqlx::Error> {
5+
let database = sqlx::sqlite::SqlitePoolOptions::new()
6+
.max_connections(2)
7+
.connect_with(
8+
sqlx::sqlite::SqliteConnectOptions::new()
9+
.filename("./data/nyaa-notifs.sqlite")
10+
.create_if_missing(true),
11+
).await.unwrap();
12+
for update in updates.clone() {
13+
let comments = update.nyaa_torrent.comments as i64;
14+
let seeders = update.nyaa_torrent.seeders as i64;
15+
let leechers = update.nyaa_torrent.leechers as i64;
16+
let completed = update.nyaa_torrent.completed as i64;
17+
let timestamp = update.nyaa_torrent.timestamp as i64;
18+
sqlx::query!("INSERT INTO MAIN (Category, Title, Comments, Magnet, Torrent_File, Seeders, Leechers, Completed, Timestamp)
19+
VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9)",
20+
update.nyaa_torrent.category, update.nyaa_torrent.title, comments, update.nyaa_torrent.magnet, update.nyaa_torrent.torrent_file,
21+
seeders, leechers, completed, timestamp
22+
).execute(&database).await.expect("insert error");
23+
};
24+
database.close().await;
25+
Ok(())
26+
}
27+
28+
29+
pub async fn get_database() -> Result<Vec<NyaaTorrent>, sqlx::Error> {
30+
let database = sqlx::sqlite::SqlitePoolOptions::new()
31+
.max_connections(2)
32+
.connect_with(
33+
sqlx::sqlite::SqliteConnectOptions::new()
34+
.filename("./data/nyaa-notifs.sqlite")
35+
.create_if_missing(true),
36+
).await.unwrap();
37+
sqlx::migrate!("./migrations").run(&database).await.unwrap();
38+
if sqlx::query!("SELECT * FROM Main").fetch_one(&database).await.is_ok() {
39+
let rows: Vec<NyaaTorrent> = sqlx::query!("SELECT * FROM Main").fetch_all(&database).await.unwrap().iter().map(|row| NyaaTorrent {
40+
title: row.Title.clone(),
41+
category: row.Category.as_ref().unwrap().to_string(),
42+
comments: row.Comments.unwrap() as u64,
43+
size: "NULL".to_string(),
44+
torrent_file: row.Torrent_File.clone(),
45+
magnet: row.Magnet.clone(),
46+
date: "NULL".to_string(),
47+
seeders: row.Seeders.unwrap() as u64,
48+
leechers: row.Leechers.unwrap() as u64,
49+
completed: row.Completed.unwrap() as u64,
50+
timestamp: row.Timestamp.unwrap() as u64
51+
} ).collect();
52+
Ok(rows)
53+
} else {
54+
Ok([].to_vec())
55+
}
56+
}

0 commit comments

Comments
 (0)