Skip to content

Commit

Permalink
0.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Vernoxvernax committed Sep 16, 2022
1 parent ae7d90f commit f7a285f
Show file tree
Hide file tree
Showing 10 changed files with 1,228 additions and 0 deletions.
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# DATABASE_URL = sqlite:data/nyaa-comms.sqlite
38 changes: 38 additions & 0 deletions .github/workflows/tag_release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Rust

on:
push:
tags:
- '*'

env:
CARGO_TERM_COLOR: always


jobs:
new_tag:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Build linux binary
run: cargo build --release
- name: release
uses: actions/create-release@v1
id: create_release
with:
draft: false
preprelease: false
release_name: ${{ steps.version.outputs.version }}
tag_name: ${{ github.ref }}
body_path: RECENT_CHANGES.md
env:
GITHUB_TOKEN: ${{ github.token }}
- name: upload linux artifact
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ github.token }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./target/release/nyaa-notifs
asset_name: nyaa-notifications
asset_content_type: application/octet-stream
19 changes: 19 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[package]
name = "nyaa-notifs"
version = "0.1.0"
edition = "2021"

[dependencies]
isahc = "1.7.2"
lettre = { version = "0.10.1", default-features = false, features = ["smtp-transport", "tokio1-rustls-tls", "hostname", "builder"] }
serde = "1.0.144"
serde_derive = "1.0.144"
serenity = { version = "0.11.5", features = ["collector", "rustls_backend"] }
sqlx = { version = "0.6.1", features = ["runtime-tokio-native-tls", "sqlite", "offline"] }
tokio = { version = "1.21.0", features = ["full"] }
toml = "0.5.9"
chrono = "0.4.22"
reqwest = "0.11.11"
http = "0.2.8"
serde_json = "1.0.85"
html-escape = "0.2.11"
46 changes: 46 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
## **Nyaa-Notifications**

*stalk your favourite uploaders and don't miss the drama in the comments*

___

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.

___

### **Supported notification services:**
+ **SMTP/Mail:** (highlight because of newly found release)
![](https://i.imgur.com/XqPZMZt.png)
+ **Discord-Bot:**
![](https://i.imgur.com/KtzIDv6.png)
* **Gotify:**
![](https://i.imgur.com/9UzbkyP.png)

**Notes:**
- 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.

___

### **Important information:**

#### Requirements for input domain:
* Must start at page 1.
* 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)

#### Config notes:
* To add multiple discord-notification channels, you can just continue the `channel_id` list.
* On the first run, I'd highly suggest you to keep all notification services deactivated, so you don't get spammed with outdated news.

#### Misc:
* All requests are executed two seconds from each other.

___

### **Installation:**

Head over to the releases grab the binary and run it.
The output on the first run will tell you what to do next.

___

Please tell me if you'd like to see a specific feature.
1 change: 1 addition & 0 deletions RECENT_CHANGES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
### First commit :)
12 changes: 12 additions & 0 deletions migrations/20220911123513_main.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
-- Add migration script here
CREATE TABLE MAIN (
Category TEXT NO NULL,
Title TEXT NOT NULL,
Comments INTEGER,
Magnet TEXT NOT NULL,
Torrent_File TEXT NOT NULL,
Seeders INTERGER,
Leechers INTEGER,
Completed INTEGER,
Timestamp INTEGER
)
79 changes: 79 additions & 0 deletions sqlx-data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
{
"db": "SQLite",
"34d9c5386a1f25ca9053d2f1e089b522a22e53347527490bb28f1627d8c85ded": {
"describe": {
"columns": [
{
"name": "Category",
"ordinal": 0,
"type_info": "Text"
},
{
"name": "Title",
"ordinal": 1,
"type_info": "Text"
},
{
"name": "Comments",
"ordinal": 2,
"type_info": "Int64"
},
{
"name": "Magnet",
"ordinal": 3,
"type_info": "Text"
},
{
"name": "Torrent_File",
"ordinal": 4,
"type_info": "Text"
},
{
"name": "Seeders",
"ordinal": 5,
"type_info": "Int64"
},
{
"name": "Leechers",
"ordinal": 6,
"type_info": "Int64"
},
{
"name": "Completed",
"ordinal": 7,
"type_info": "Int64"
},
{
"name": "Timestamp",
"ordinal": 8,
"type_info": "Int64"
}
],
"nullable": [
true,
false,
true,
false,
false,
true,
true,
true,
true
],
"parameters": {
"Right": 0
}
},
"query": "SELECT * FROM Main"
},
"c3c8c8d5f1b005801d9299b01b103c6dc29104d5c593e4cc0f93dc1cc412bb2b": {
"describe": {
"columns": [],
"nullable": [],
"parameters": {
"Right": 9
}
},
"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)"
}
}
56 changes: 56 additions & 0 deletions src/database.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
use crate::{NyaaTorrent, Update};


pub async fn updates_to_database(updates: &Vec<Update>) -> Result<(), sqlx::Error> {
let database = sqlx::sqlite::SqlitePoolOptions::new()
.max_connections(2)
.connect_with(
sqlx::sqlite::SqliteConnectOptions::new()
.filename("./data/nyaa-notifs.sqlite")
.create_if_missing(true),
).await.unwrap();
for update in updates.clone() {
let comments = update.nyaa_torrent.comments as i64;
let seeders = update.nyaa_torrent.seeders as i64;
let leechers = update.nyaa_torrent.leechers as i64;
let completed = update.nyaa_torrent.completed as i64;
let timestamp = update.nyaa_torrent.timestamp as i64;
sqlx::query!("INSERT INTO MAIN (Category, Title, Comments, Magnet, Torrent_File, Seeders, Leechers, Completed, Timestamp)
VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9)",
update.nyaa_torrent.category, update.nyaa_torrent.title, comments, update.nyaa_torrent.magnet, update.nyaa_torrent.torrent_file,
seeders, leechers, completed, timestamp
).execute(&database).await.expect("insert error");
};
database.close().await;
Ok(())
}


pub async fn get_database() -> Result<Vec<NyaaTorrent>, sqlx::Error> {
let database = sqlx::sqlite::SqlitePoolOptions::new()
.max_connections(2)
.connect_with(
sqlx::sqlite::SqliteConnectOptions::new()
.filename("./data/nyaa-notifs.sqlite")
.create_if_missing(true),
).await.unwrap();
sqlx::migrate!("./migrations").run(&database).await.unwrap();
if sqlx::query!("SELECT * FROM Main").fetch_one(&database).await.is_ok() {
let rows: Vec<NyaaTorrent> = sqlx::query!("SELECT * FROM Main").fetch_all(&database).await.unwrap().iter().map(|row| NyaaTorrent {
title: row.Title.clone(),
category: row.Category.as_ref().unwrap().to_string(),
comments: row.Comments.unwrap() as u64,
size: "NULL".to_string(),
torrent_file: row.Torrent_File.clone(),
magnet: row.Magnet.clone(),
date: "NULL".to_string(),
seeders: row.Seeders.unwrap() as u64,
leechers: row.Leechers.unwrap() as u64,
completed: row.Completed.unwrap() as u64,
timestamp: row.Timestamp.unwrap() as u64
} ).collect();
Ok(rows)
} else {
Ok([].to_vec())
}
}
Loading

0 comments on commit f7a285f

Please sign in to comment.