Skip to content

Commit

Permalink
Implement module initial version
Browse files Browse the repository at this point in the history
  • Loading branch information
mcartoixa committed Jan 2, 2018
1 parent ebda703 commit c483050
Show file tree
Hide file tree
Showing 18 changed files with 570 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.sonarlint/
vendor/
tmp/

*.lock
*.log
22 changes: 22 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
language: php
php:
- '5.6'

env:
- DLM_PACKAGE_VERSION=1.0.$TRAVIS_BUILD_NUMBER

install:
- php bin/composer.phar install -n

script:
- vendor/bin/phing -f build.xml prepare.version release

deploy:
provider: releases
api_key:
secure: "S3MuWXQ4L7msHHZYWDVh+dSn0YqxG8hcbPBmMZyIgPeqYNmORr6WlBWQIxoDpE/ajMKbsEr3AQ4PbR8Q2xDddnpGGnVkgd4sLrd3rR8qtChhAoGAQJA0KmrdNeijeAZ9RKbO27GqOyCNdNJYR6BZAOdU1dvE5/MNdWY9dPAEQuVesWSfSUUc0u5ZGeuZnMMe+DB0T04FMDmqi9LU6suNz/K4tgqHZLjQ7aYIyZeiS6IHIJB6yMqVt7esO7U6gLtq/92ln400fFMKe7fiqHDXinviov49+C+OgMQWq8/dH21lrckL+UXGfGwIji11jpsyNac0nWMgEFs+Q7UG9Bgju5RuqDhYamsl6xSek94jrjlhtJMxdsj5KYpkgPM3K+Pxy5rsIXa2In8ZOPS1xLv5+qOaasaTCbLevOUt95o0cOUS5aM2n+uL5ZlfJG0R5xS6ScILJzinXeKyd6BXM9nFMwLRcpptl+un70ui+8ZlRbYZJkBfibRV5yL119q+tIUCOKLxOsBCd6GZoDfoQ5uZe6TsDg6UfWhVPYVXvjL3tZ6kUWd3jdu5PdDdFxcCz5rmT5JnUgpcADWsapE0Sm+eqcsHXQsMkxaRMmLy3l1WW1Eu0OsboIdO/tNAtSNMJpILhP0IoYfVRfpTeVpIax37cUBp8TxCv5ms6g4xhdAq848="
file_glob: true
file: tmp/out/bin/*
skip_cleanup: true
on:
tags: true
21 changes: 21 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Place your settings in this file to overwrite default and user settings.
{
"editor.insertSpaces": true,
"editor.tabSize": 4,
"files.eol": "\r\n",
"files.exclude": {
"**/.git": true,
"**/*.lock": true,
"**/*.log": true,
".sonarlint/": true,
"packages/": true,
"tmp/": true,
"**/vendor/": true
},
"files.trimTrailingWhitespace": true,
"php.validate.enable": true,
"terminal.integrated.shellArgs.windows": [
"/K",
"bin\\SetEnv.bat"
]
}
17 changes: 15 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,15 @@
# synology-dlm-rarbg
RarBG search module for Synology Download Manager
[![Build status](https://travis-ci.org/mcartoixa/synology-dlm-rarbg.svg?branch=master)](https://travis-ci.org/mcartoixa/synology-dlm-rarbg)
# Installation
- Download [the latest version of the module](https://github.com/mcartoixa/synology-dlm-rarbg/releases/latest) and install it in the [BT Search section of Download Station](https://www.synology.com/en-global/knowledgebase/DSM/help/DownloadStation/download_setup#torrent).

# Development
## Build

- Run the following command from this directory: `build.bat`
- Prerequisites:
* PHP 5.6:
+ Make sure the following extensions are activated:
- php_curl
- php_mbstring
- php_openssl
+ Set an environment variable `PHP_HOME` that points to the PHP installation folder (e.g `C:\PROGRA~2\PHP\5.6`).
5 changes: 5 additions & 0 deletions bin/SetEnv.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@ECHO OFF

ECHO SET PHP_HOME=%PHP_HOME%

SET PATH=%CD%\bin;%PHP_HOME%;%PATH%
3 changes: 3 additions & 0 deletions bin/composer.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@ECHO OFF

%PHP_HOME%\php.exe "%~dp0composer.phar" %*
Binary file added bin/composer.phar
Binary file not shown.
111 changes: 111 additions & 0 deletions build.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
@ECHO OFF
::--------------------------------------------------------------------
:: Usage: "build [/clean | /rebuild | /release] [/NoPause] [/?]"
::
:: /clean - Cleans the project
:: /rebuild - Cleans and builds the project (default)
:: /release - Rebuilds the project and creates the packages
::
:: /NoPause - Does not pause after completion
:: /? - Gets the usage for this script
::--------------------------------------------------------------------



COLOR 07

:: Reset ERRORLEVEL
VERIFY OTHER 2>nul
SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
IF ERRORLEVEL 1 GOTO ERROR_EXT

SET NO_PAUSE=0
SET PROJECT=build.xml
SET TARGET=rebuild
GOTO ARGS



:: -------------------------------------------------------------------
:: Builds the project
:: -------------------------------------------------------------------
:BUILD

CALL .\bin\composer.bat install -q -n
IF ERRORLEVEL 1 GOTO END_ERROR
ECHO.

CALL .\vendor\bin\phing.bat -f %PROJECT% %TARGET%
IF ERRORLEVEL 1 GOTO END_ERROR
GOTO END



:: -------------------------------------------------------------------
:: Parse command line argument values
:: Note: Currently, last one on the command line wins (ex: /rebuild /clean == /clean)
:: -------------------------------------------------------------------
:ARGS
IF "%PROCESSOR_ARCHITECTURE%"=="x86" (
"C:\Windows\Sysnative\cmd.exe" /C "%0 %*"

IF ERRORLEVEL 1 EXIT /B 1
EXIT /B 0
)
::IF NOT "x%~5"=="x" GOTO ERROR_USAGE

:ARGS_PARSE
IF /I "%~1"=="/clean" SET TARGET=clean& SHIFT & GOTO ARGS_PARSE
IF /I "%~1"=="/rebuild" SET TARGET=rebuild& SHIFT & GOTO ARGS_PARSE
IF /I "%~1"=="/release" SET TARGET=prepare.version release& SHIFT & GOTO ARGS_PARSE
::IF /I "%~1"=="/log" SET VERBOSITY=diagnostic& SHIFT & GOTO ARGS_PARSE
IF /I "%~1"=="/NoPause" SET NO_PAUSE=1& SHIFT & GOTO ARGS_PARSE
IF /I "%~1"=="/?" GOTO ERROR_USAGE
IF "%~1" EQU "" GOTO ARGS_DONE
ECHO Unknown command-line switch: %~1
GOTO ERROR_USAGE

:ARGS_DONE
IF "%DEV_BUILD%"=="True" GOTO SETENV_DEV ELSE GOTO SETENV



:: -------------------------------------------------------------------
:: Set environment variables
:: -------------------------------------------------------------------
:SETENV
CALL bin\SetEnv.bat
ECHO.
GOTO BUILD



:: -------------------------------------------------------------------
:: Errors
:: -------------------------------------------------------------------
:ERROR_EXT
ECHO Could not activate command extensions
GOTO END_ERROR

:ERROR_USAGE
ECHO Usage: "build [/clean | /rebuild | /release] [/NoPause] [/?]"
ECHO.
ECHO /clean - Cleans the project
ECHO /rebuild - Cleans and builds the project (default)
ECHO /release - Rebuilds the project and creates the packages
ECHO.
ECHO /NoPause - Does not pause after completion
ECHO /? - Gets the usage for this script
GOTO END



:: -------------------------------------------------------------------
:: End
:: -------------------------------------------------------------------
:END_ERROR
COLOR 4E

:END
@IF NOT "%NO_PAUSE%"=="1" PAUSE
ENDLOCAL
84 changes: 84 additions & 0 deletions build.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?xml version="1.0" encoding="UTF-8"?>

<project name="synology-dlm-rarbg" default="build">
<autoloader />

<property environment="env" />

<property name="bin.dir" value="${project.basedir}/bin" />
<property name="dlm.dir" value="${project.basedir}/dlm" />
<property name="tmp.dir" value="${project.basedir}/tmp" />

<property name="tmp.bin.dir" value="${tmp.dir}/bin" />
<property name="tmp.obj.dir" value="${tmp.dir}/obj" />
<property name="tmp.out.dir" value="${tmp.dir}/out" />
<property name="tmp.test.dir" value="${tmp.dir}/test" />



<target name="prepare.version" depends="prepare.dlm">
<if>
<and>
<isset property="env.DLM_PACKAGE_VERSION" />
<not>
<equals arg1="${env.DLM_PACKAGE_VERSION}" arg2="0.0.0" />
</not>
</and>
<then>
<phing phingfile="build.xml" dir="./dlm" target="prepare.version" inheritAll="true" haltonfailure="true" />
</then>
</if>
</target>

<target name="prepare.dlm">
<composer command="update" composer="${bin.dir}/composer.phar">
<arg value="-q" />
<arg value="-d" />
<arg path="${dlm.dir}" />
<arg value="-n" />
</composer>
</target>



<target name="clean" depends="prepare.clean">
<phing phingfile="build.xml" dir="${dlm.dir}" target="clean" inheritAll="true" haltonfailure="true" />
</target>

<target name="prepare.clean" depends="prepare.dlm">
<delete dir="${tmp.dir}" includeemptydirs="true" quiet="true" failonerror="false" />
</target>



<target name="build" depends="prepare.build">
<phing phingfile="build.xml" dir="${dlm.dir}" target="build" inheritAll="true" haltonfailure="true" />
</target>

<target name="prepare.build" depends="prepare.dlm">
<mkdir dir="${tmp.dir}" />

<composer command="update" composer="${bin.dir}/composer.phar">
<arg value="-q" />
<arg value="-n" />
</composer>
</target>



<target name="test" depends="prepare.build">
<phing phingfile="build.xml" dir="${dlm.dir}" target="test" inheritAll="true" haltonfailure="true" />
</target>



<target name="rebuild" depends="prepare.clean,prepare.build">
<phing phingfile="build.xml" dir="${dlm.dir}" target="rebuild" inheritAll="true" haltonfailure="true" />
</target>



<target name="release" depends="prepare.clean,prepare.build">
<phing phingfile="build.xml" dir="${dlm.dir}" target="release" inheritAll="true" haltonfailure="true" />
</target>
</project>
10 changes: 10 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "mcartoixa/synology-dlm-rarbg",
"description": "RarBG search module for Synology Download Manager",
"type": "project",
"license": "MIT",
"require-dev": {
"phing/phing": "2.*",
"pear/archive_tar": "*"
}
}
10 changes: 10 additions & 0 deletions dlm/INFO
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "mcartoixa_rarbg",
"displayname": "RarBG",
"description": "RarBG search module for Synology Download Manager",
"version": "0.0.0",
"site": "https://rarbg.to/",
"module": "search.php",
"type": "search",
"class": "SynoDLMSearchRarBG"
}
45 changes: 45 additions & 0 deletions dlm/RarBGToken.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php
require "vendor/autoload.php";

class RarBGToken
{

public function __construct()
{ }

public function __toString()
{
if (empty($this->token))
{
return '';
} else
{
return $this->token;
}
}

public function refresh($force = false)
{
$now = time();
if (empty($this->token) || $force || ($this->expiration <= time()))
{
$this->expiration = $now;
$this->token = NULL;
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_URL => SynoDLMSearchRarBG::API_URL.'get_token=get_token',
CURLOPT_USERAGENT => RARBG_USER_AGENT,
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_SSL_VERIFYPEER => false
));
$response = curl_exec($curl);
$this->expiration = time() + (14 * 60);
$this->token = json_decode($response)->token;
}
}

private $token;
private $expiration;
}
?>
Loading

0 comments on commit c483050

Please sign in to comment.