Add torrent metadata #22
@ -9,6 +9,7 @@ import (
|
||||
"git.quimbo.fr/odwrtw/canape/backend/auth"
|
||||
"git.quimbo.fr/odwrtw/canape/backend/web"
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/odwrtw/papi"
|
||||
|
||||
polochon "github.com/odwrtw/polochon/lib"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
@ -16,7 +17,8 @@ import (
|
||||
// DownloadHandler downloads a movie via polochon
|
||||
func DownloadHandler(env *web.Env, w http.ResponseWriter, r *http.Request) error {
|
||||
var data struct {
|
||||
URL string `json:"url"`
|
||||
URL string `json:"url"`
|
||||
PouuleT
commented
T'as pas mis explicitement URL de l'autre coté? T'as pas mis explicitement URL de l'autre coté?
gregdel
commented
Ca c'est les parametres de l'app en js Ca c'est les parametres de l'app en js
|
||||
Metadata *papi.TorrentMetadata `json:"metadata"`
|
||||
}
|
||||
err := json.NewDecoder(r.Body).Decode(&data)
|
||||
if err != nil {
|
||||
@ -34,7 +36,7 @@ func DownloadHandler(env *web.Env, w http.ResponseWriter, r *http.Request) error
|
||||
return env.RenderError(w, err)
|
||||
}
|
||||
|
||||
err = client.AddTorrent(data.URL)
|
||||
err = client.AddTorrent(data.URL, data.Metadata)
|
||||
if err != nil {
|
||||
return env.RenderError(w, err)
|
||||
}
|
||||
|
@ -2,11 +2,12 @@ import { configureAxios, request } from "../requests";
|
||||
|
||||
import { addAlertOk } from "./alerts";
|
||||
|
||||
export function addTorrent(url) {
|
||||
export function addTorrent(torrent) {
|
||||
return request(
|
||||
"ADD_TORRENT",
|
||||
configureAxios().post("/torrents", {
|
||||
url: url,
|
||||
url: torrent.url,
|
||||
metadata: torrent.metadata,
|
||||
}),
|
||||
[addAlertOk("Torrent added")]
|
||||
);
|
||||
|
@ -27,8 +27,8 @@ const buildMenuItems = (torrents) => {
|
||||
entries.push({
|
||||
type: "entry",
|
||||
quality: torrent.quality,
|
||||
url: torrent.url,
|
||||
size: torrent.size,
|
||||
torrent: torrent,
|
||||
});
|
||||
});
|
||||
|
||||
@ -109,7 +109,7 @@ export const TorrentsButton = ({ torrents, search, searching, url }) => {
|
||||
return (
|
||||
<Dropdown.Item
|
||||
key={index}
|
||||
onClick={() => dispatch(addTorrent(e.url))}
|
||||
onClick={() => dispatch(addTorrent(e.torrent))}
|
||||
>
|
||||
{e.quality}
|
||||
{e.size !== 0 && (
|
||||
|
@ -25,7 +25,7 @@ const AddTorrent = () => {
|
||||
if (url === "") {
|
||||
return;
|
||||
}
|
||||
dispatch(addTorrent(url));
|
||||
dispatch(addTorrent({ url: url, metdata: null }));
|
||||
setUrl("");
|
||||
};
|
||||
|
||||
|
@ -163,7 +163,9 @@ const Torrent = ({ torrent }) => {
|
||||
<div className="align-self-end ml-3">
|
||||
<i
|
||||
className="fa fa-cloud-download clickable"
|
||||
onClick={() => dispatch(addTorrent(torrent.url))}
|
||||
onClick={() =>
|
||||
dispatch(addTorrent({ url: torrent.url, metadata: null }))
|
||||
}
|
||||
></i>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -1,5 +1,4 @@
|
||||
import { produce } from "immer";
|
||||
import { formatTorrents } from "../utils";
|
||||
|
||||
const defaultState = {
|
||||
loading: false,
|
||||
@ -9,10 +8,33 @@ const defaultState = {
|
||||
exploreOptions: {},
|
||||
};
|
||||
|
||||
const formatTorrents = (movie) => {
|
||||
if (!movie.torrents || movie.torrents.length == 0) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
let torrentMap = new Map();
|
||||
movie.torrents.forEach((torrent) => {
|
||||
if (!torrentMap.has(torrent.source)) {
|
||||
torrentMap.set(torrent.source, new Map());
|
||||
}
|
||||
|
||||
torrent.metadata = {
|
||||
type: "movie",
|
||||
imdb_id: movie.imdb_id, // eslint-disable-line camelcase
|
||||
quality: torrent.quality,
|
||||
};
|
||||
|
||||
torrentMap.get(torrent.source).set(torrent.quality, torrent);
|
||||
});
|
||||
|
||||
return torrentMap;
|
||||
};
|
||||
|
||||
const formatMovie = (movie) => {
|
||||
movie.fetchingDetails = false;
|
||||
movie.fetchingSubtitles = false;
|
||||
movie.torrents = formatTorrents(movie.torrents);
|
||||
movie.torrents = formatTorrents(movie);
|
||||
return movie;
|
||||
};
|
||||
|
||||
|
@ -1,14 +1,38 @@
|
||||
import { produce } from "immer";
|
||||
import { formatTorrents } from "../utils";
|
||||
|
||||
const defaultState = {
|
||||
loading: false,
|
||||
show: {},
|
||||
};
|
||||
|
||||
const formatTorrents = (episode) => {
|
||||
if (!episode.torrents || episode.torrents.length == 0) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
let torrentMap = new Map();
|
||||
episode.torrents.forEach((torrent) => {
|
||||
if (!torrentMap.has(torrent.source)) {
|
||||
torrentMap.set(torrent.source, new Map());
|
||||
}
|
||||
|
||||
torrent.metadata = {
|
||||
type: "episode",
|
||||
imdb_id: episode.show_imdb_id, // eslint-disable-line camelcase
|
||||
quality: torrent.quality,
|
||||
season: episode.season,
|
||||
episode: episode.episode,
|
||||
};
|
||||
|
||||
torrentMap.get(torrent.source).set(torrent.quality, torrent);
|
||||
});
|
||||
|
||||
return torrentMap;
|
||||
};
|
||||
|
||||
const formatEpisode = (episode) => {
|
||||
// Format the episode's torrents
|
||||
episode.torrents = formatTorrents(episode.torrents);
|
||||
episode.torrents = formatTorrents(episode);
|
||||
|
||||
// Set the default fetching data
|
||||
episode.fetching = false;
|
||||
|
@ -31,19 +31,3 @@ export const prettySize = (fileSizeInBytes) => {
|
||||
|
||||
return Math.max(fileSizeInBytes, 0.1).toFixed(1) + byteUnits[i];
|
||||
};
|
||||
|
||||
export const formatTorrents = (torrents = []) => {
|
||||
if (!torrents || torrents.length == 0) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
let torrentMap = new Map();
|
||||
torrents.forEach((torrent) => {
|
||||
if (!torrentMap.has(torrent.source)) {
|
||||
torrentMap.set(torrent.source, new Map());
|
||||
}
|
||||
torrentMap.get(torrent.source).set(torrent.quality, torrent);
|
||||
});
|
||||
|
||||
return torrentMap;
|
||||
};
|
||||
|
4
go.mod
4
go.mod
@ -15,8 +15,8 @@ require (
|
||||
github.com/mattn/go-sqlite3 v1.10.0 // indirect
|
||||
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646
|
||||
github.com/odwrtw/errors v0.0.0-20170604160533-c747b9d17833
|
||||
github.com/odwrtw/papi v0.0.0-20190511132159-936937ad8b6a
|
||||
github.com/odwrtw/polochon v0.0.0-20200404170220-273fe65c963b
|
||||
github.com/odwrtw/papi v0.0.0-20200408160729-930e92b452fd
|
||||
github.com/odwrtw/polochon v0.0.0-20200408160701-0455bb96acb0
|
||||
github.com/phyber/negroni-gzip v0.0.0-20180113114010-ef6356a5d029
|
||||
github.com/pioz/tvdb v0.0.0-20190503215423-f45c687faba9 // indirect
|
||||
github.com/robfig/cron v1.1.0
|
||||
|
12
go.sum
12
go.sum
@ -135,16 +135,16 @@ github.com/odwrtw/imdb-watchlist v0.0.0-20190417175016-b7a9f7503d69 h1:ow6b/4Jj7
|
||||
github.com/odwrtw/imdb-watchlist v0.0.0-20190417175016-b7a9f7503d69/go.mod h1:o2tLH95CtNdqhDb0aS2NbU+1I4PmaNsODpr33Ry0JC0=
|
||||
github.com/odwrtw/papi v0.0.0-20190413103029-bd5bfea85ae6 h1:bF8XKFfYNY4quRdqJ5E9ERd+FdR26H1X1Z2fNRGePSk=
|
||||
github.com/odwrtw/papi v0.0.0-20190413103029-bd5bfea85ae6/go.mod h1:CXotdtODLpW0/yuFV5XH8Rmrj0eAfPLvdMKykPM2WCk=
|
||||
github.com/odwrtw/papi v0.0.0-20190511132159-936937ad8b6a h1:9mdPet/ianrckPWR2jSekoafz6BaqbF7kPXLnDEIKu8=
|
||||
github.com/odwrtw/papi v0.0.0-20190511132159-936937ad8b6a/go.mod h1:eY0skvVHJBwbSJ18uq2c1T4SvhdEV8R0XFSb0zKh5Yo=
|
||||
github.com/odwrtw/polochon v0.0.0-20200404170220-273fe65c963b h1:XBJs10QfMcVOr+jMpB2k8Pwfe4ohIWNMfNGStJdi1Pg=
|
||||
github.com/odwrtw/polochon v0.0.0-20200404170220-273fe65c963b/go.mod h1:6/D6IYxfGqRi8KioWN8ViiwssUdjhZV+U7gw5Xb8Aqk=
|
||||
github.com/odwrtw/papi v0.0.0-20200408160729-930e92b452fd h1:LsBK0gVXC8oRxyAwvkCg5fQWTD678Jl7n6a8MZpdUKo=
|
||||
github.com/odwrtw/papi v0.0.0-20200408160729-930e92b452fd/go.mod h1:eY0skvVHJBwbSJ18uq2c1T4SvhdEV8R0XFSb0zKh5Yo=
|
||||
github.com/odwrtw/polochon v0.0.0-20200408160701-0455bb96acb0 h1:p0pXoG89JVL/bZWJpqu2KRQwCU44yYnNnoP46SIPNPQ=
|
||||
github.com/odwrtw/polochon v0.0.0-20200408160701-0455bb96acb0/go.mod h1:sAYf/A5tDmins2GHZn2mEFarmYltAZv+bcmSKSxDUaI=
|
||||
github.com/odwrtw/tpb v0.0.0-20200130133144-c846aa382c6f h1:fwEIGT+o3e8+XkBqrwsE3/+9ketTQXflPhCkv3/w990=
|
||||
github.com/odwrtw/tpb v0.0.0-20200130133144-c846aa382c6f/go.mod h1:updLvMbQo2xHoz94MX9+GqmSoKhf6E8fs/J+wLvvu6A=
|
||||
github.com/odwrtw/trakttv v0.0.0-20200404161731-0d594827e4f9 h1:PuQLHO75MXUsJpf9BcTVxvR/FCkdn1MZnZt6h3o6cJI=
|
||||
github.com/odwrtw/trakttv v0.0.0-20200404161731-0d594827e4f9/go.mod h1:I2ogRfOYYqNpMhljPYdFUVUrLbZQ89Ba7QdfiW6EcJ0=
|
||||
github.com/odwrtw/transmission v0.0.0-20170515140915-08885b3058e7 h1:NZz8yuBWWG4o3EGdoMap4o+JPKLBhqeSQ7nTfX6XPos=
|
||||
github.com/odwrtw/transmission v0.0.0-20170515140915-08885b3058e7/go.mod h1:geyfqmhRrxMwbEo5RPwf5rw5vITQHHQlA7+azUQSIJM=
|
||||
github.com/odwrtw/transmission v0.0.0-20200408122227-b562b9fbcbee h1:BttuvaEGtpe3rL7zm+e2RwVkj1DBo/Mb6XdbWd0a7ds=
|
||||
github.com/odwrtw/transmission v0.0.0-20200408122227-b562b9fbcbee/go.mod h1:o+HdjqpVQPFqVTG4jncidwE0/cQoAfCJ4JMFaB481xc=
|
||||
github.com/odwrtw/yifysubs v0.0.0-20190417174645-d3bba6e4cfe0 h1:LasNCTYd9Pc3x34xc1p054ZF8rVPLhD2Vfk3Db2KSpo=
|
||||
github.com/odwrtw/yifysubs v0.0.0-20190417174645-d3bba6e4cfe0/go.mod h1:9TPMeWCUplybvf4aCW6Hu3KwJian+oSeK6jZ597z9i4=
|
||||
github.com/odwrtw/yts v0.0.0-20190417175129-d51f8755d93d h1:f100x20G/oZHNqC4iebFULY0wj4Inv5HRN+j53flOaA=
|
||||
|
Loading…
x
Reference in New Issue
Block a user
Why papi and not polochon?
Si t'expand le code tu vois que c'est un papi client