Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix bugs, make the scripts work again #1

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,13 @@
# synoDoubanVideoInfo
A search Video Info Plugin for Synology NAS Video Station

# Installation
Get the latest install.sh from the [release](https://github.com/jemyzhang/synoDoubanVideoInfo/releases), and run under the shell of Syno-Station.
The orignal plugin will be packaged backup, you can use the uninstall.sh to restore the backup.

# Upgrade
Run the install.sh again, the lastest version will be checked and installed.

# Uninstall
Get the latest uninstall.sh from the [release](https://github.com/jemyzhang/synoDoubanVideoInfo/releases), and run under the shell of Syno-Station.

37 changes: 19 additions & 18 deletions doubanSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

require_once(dirname(__FILE__) . '/utils.php');

$SUPPORTED_TYPE = array('movie');
$SUPPORTED_PROPERTIES = array('title');

function GetMovieInfoDouban($movie_data, $data)
{
/**
Expand All @@ -18,24 +15,24 @@ function GetMovieInfoDouban($movie_data, $data)

//extra
$data['extra'] = array();
$data['extra'][DOUBAN_PLUGINID] = array('reference' => array());
$data['extra'][DOUBAN_PLUGINID]['reference']['themoviedb'] = $movie_data->id;
$data['extra'][PLUGINID] = array('reference' => array());
$data['extra'][PLUGINID]['reference']['themoviedb'] = $movie_data->id;
$data['doubandb'] = true;

if (isset($movie_data->imdb_id)) {
$data['extra'][DOUBAN_PLUGINID]['reference']['imdb'] = $movie_data->imdb; // add-on
if (isset($movie_data->imdb)) {
$data['extra'][PLUGINID]['reference']['imdb'] = $movie_data->imdb; // add-on
}
if ((float)$movie_data->rating) {
$data['extra'][DOUBAN_PLUGINID]['rating'] = array('themoviedb' => $movie_data->rating->average);
$data['extra'][PLUGINID]['rating'] = array('themoviedb' => $movie_data->rating->average);
}
if (isset($movie_data->images)) {
$data['extra'][DOUBAN_PLUGINID]['poster'] = array($movie_data->images->large);
$data['extra'][PLUGINID]['poster'] = array($movie_data->images->large);
}
if (isset($movie_data->backdrop_path)) {
$data['extra'][DOUBAN_PLUGINID]['backdrop'] = array($movie_data->backdrop); // add-on
if (isset($movie_data->backdrop)) {
$data['extra'][PLUGINID]['backdrop'] = array($movie_data->backdrop); // add-on
}
if (isset($movie_data->belongs_to_collection)) {
$data['extra'][DOUBAN_PLUGINID]['collection_id'] = array('themoviedb' => $movie_data->belongs_to_collection->id);
$data['extra'][PLUGINID]['collection_id'] = array('themoviedb' => $movie_data->belongs_to_collection->id);
}

// genre
Expand All @@ -49,8 +46,8 @@ function GetMovieInfoDouban($movie_data, $data)
// actor
if( isset($movie_data->casts) ){ // add-on
foreach ($movie_data->casts as $item) {
if (!in_array($item->name, $data['actor'])) {
array_push($data['actor'], $item->name);
if (!in_array($item, $data['actor'])) {
array_push($data['actor'], $item);
}
}
}
Expand All @@ -67,8 +64,8 @@ function GetMovieInfoDouban($movie_data, $data)
// writer
if( isset($movie_data->writers) ){ // add-on
foreach ($movie_data->writers as $item) {
if (!in_array($item->name, $data['writer'])) {
array_push($data['writer'], $item->name);
if (!in_array($item, $data['writer'])) {
array_push($data['writer'], $item);
}
}
}
Expand All @@ -77,14 +74,18 @@ function GetMovieInfoDouban($movie_data, $data)
return $data;
}

function GetMetadataDouban($query_data, $lang)
function GetMetadataDouban($query_data)
{
global $DATA_TEMPLATE;

//Foreach query result
$result = array();

foreach($query_data as $item) {
//Filter the content
if($item['subtype'] != 'movie') {
continue;
}
//Copy template
$data = $DATA_TEMPLATE;

Expand Down Expand Up @@ -123,4 +124,4 @@ function ProcessDouban($input, $lang, $type, $limit, $search_properties, $allowg
return GetMetadataDouban($query_data['subjects']);
}

?>
?>
49 changes: 33 additions & 16 deletions install.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,27 +1,44 @@
#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH

clear;
PLUGIN_PATH=/var/packages/VideoStation/target/plugins/syno_themoviedb
PLUGIN_ORIG_TGZ=${PLUGIN_PATH}.orig.tgz

version='1.0';

cd /tmp/;
DOWNLOAD_URL=$(\
curl -s https://api.github.com/repos/jemyzhang/synoDoubanVideoInfo/releases/latest \
| grep "browser_download_url.*tar" \
| cut -d '"' -f 4 \
)
VERSION=$(echo $DOWNLOAD_URL | sed 's#^.*/download/\(.*\)/douban.tar#\1#')
INSTALLED_VERSION=
DOWNLOADED_FILE=/tmp/douban.tar
VERSION_FLAG=${PLUGIN_PATH}/.douban.plugin

mv -R /var/packages/VideoStation/target/plugins/syno_themoviedb /var/packages/VideoStation/target/plugins/syno_themoviedb.orig
if [ -e ${VERSION_FLAG} ]; then
INSTALLED_VERSION=$(cat ${VERSION_FLAG})
fi

wget --no-check-certificate "https://github.com/AtrisMio/synoDoubanVideoInfo/releases/download/$version/douban.tar" -O douban.tar;
mkdir /var/packages/VideoStation/target/plugins/syno_themoviedb;
tar -xvf douban.tar -C /var/packages/VideoStation/target/plugins/syno_themoviedb;
if [ x"$INSTALLED_VERSION"x = x"$VERSION"x ]; then
echo "The latest version of plugin was installed"
exit 0
fi

rm -rf ./douban.tar;
if [ -z "$INSTALLED_VERSION" ]; then
echo "The fresh installation, backing up the orignal plugins"
tar czf ${PLUGIN_ORIG_TGZ} -C ${PLUGIN_PATH} .
fi

cp /var/packages/VideoStation/target/plugins/syno_themoviedb.orig/INFO;
cp /var/packages/VideoStation/target/plugins/syno_themoviedb.orig/loader.sh;
wget --no-check-certificate ${DOWNLOAD_URL} -O ${DOWNLOADED_FILE}
mkdir -p ${PLUGIN_PATH}
tar -xf ${DOWNLOADED_FILE} -C ${PLUGIN_PATH}
echo $VERSION > $VERSION_FLAG
chown VideoStation:VideoStation -R ${PLUGIN_PATH}

chmod 0755 /var/packages/VideoStation/target/plugins/syno_themoviedb/*.php;
rm -f ${DOWNLOADED_FILE}

chown VideoStation:VideoStation -R /var/packages/VideoStation/target/plugins/syno_themoviedb;
if [ -z "$INSTALLED_VERSION" ]; then
echo "Plugin version: $VERSION installed"
else
echo "Plugin updated from $INSTALLED_VERSION to $VERSION"
fi

cd -;
rm -rf install.sh;
3 changes: 3 additions & 0 deletions search.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

require_once(dirname(__FILE__) . '/../search.inc.php');

$SUPPORTED_TYPE = array('movie');
$SUPPORTED_PROPERTIES = array('title');

function Process($input, $lang, $type, $limit, $search_properties, $allowguess, $id)
{
$RET = array();
Expand Down
22 changes: 11 additions & 11 deletions uninstall.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH

clear;
PLUGIN_PATH=/var/packages/VideoStation/target/plugins/syno_themoviedb
PLUGIN_ORIG_TGZ=${PLUGIN_PATH}.orig.tgz

cd /tmp/;
if [ ! -f ${PLUGIN_ORIG_TGZ} ]; then
echo "douban plugin was not installed"
exit 1
fi

rm -rf /var/packages/VideoStation/target/plugins/syno_themoviedb.removed;
mv /var/packages/VideoStation/target/plugins/syno_themoviedb /var/packages/VideoStation/target/plugins/syno_themoviedb.removed;
rm -rf $PLUGIN_PATH

mv /var/packages/VideoStation/target/plugins/syno_themoviedb.orig /var/packages/VideoStation/target/plugins/syno_themoviedb;
mkdir -p ${PLUGIN_PATH}
tar xf ${PLUGIN_ORIG_TGZ} -C ${PLUGIN_PATH}

chmod 0755 /var/packages/VideoStation/target/plugins/syno_themoviedb/*.php;
chown VideoStation:VideoStation -R /var/packages/VideoStation/target/plugins/syno_themoviedb;
chown VideoStation:VideoStation -R ${PLUGIN_PATH}

cd -;
rm -rf uninstall.sh;
rm -f ${PLUGIN_ORIG_TGZ}
43 changes: 29 additions & 14 deletions utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,54 @@

require_once(dirname(__FILE__) . '/../constant.php');

define('DOUBAN_PLUGINID', 'com.synology.TheMovieDb');
define('PLUGINID', 'com.synology.TheMovieDb');
define('API_URL', 'https://api.douban.com/v2/movie/');
define('DEFAULT_EXPIRED_TIME', 86400);
define('DEFAULT_LONG_EXPIRED_TIME', 30*86400);

function getImdbID($input) {
preg_match_all('/<([^\s\/]+)[^>]*imdb\.com[^>]*(rel|property)="nofollow"[^>]*>([^<]*?)<\/\1>/', $input, $matches);
return implode("", $matches[3]);
}

function RegexByRel($rel, $input) {
preg_match_all('/<([^\s\/]+)(?=[^>]*>)[^>]*(rel|property)="' . $rel . '"[^>]*>([^<]*?)<\/\1>/', $input, $matches);
return $matches[3];
}

function getWriter($input) {
preg_match_all('/<([^\s\/]+)(?=[^>]*>)[^>]*>[\s]*<([^\s\/]+)(?=[^>]*>)[^>]*>编剧<\/\2>[\s\S]*?<([^\s\/]+)(?=[^>]*>)[^>]*>([\s\S]*?)<\/\3><\/\1>/', $input, $target);
$target = $target[4];
$target = implode("", $target[4]);
preg_match_all('/<([^\s\/]+)(?=[^>]*>)[^>]*>([\s\S]*?)<\/\1>/', $target, $matches);
return $matches[2];
}

function getBackdrop($input) {
preg_match_all('/<([^\s\/]+)(?=[^>]*>)[^>]*class="related-pic-bd"[^>]*>[\s\S]*?\/photos\/photo\/(\d+)\/[\s\S]*?<\/\1>/', $input, $matches);
return $matches[2];
preg_match_all('/<([^\s\/]+)(?=[^>]*>)[^>]*class="related-pic-bd[^>]*"[^>]*>[\s\S]*?\/photos\/photo\/(\d+)\/[\s\S]*?<\/\1>/', $input, $matches);
return implode("", $matches[2]);
}

function getRegexDate($input) {
if( is_array($input) ) {
$input = implode(";", $input);
}
preg_match('/\d{4}-\d{2}-\d{2}/', $input, $matches);
if(empty($matches)) {
preg_match('/\d{4}-\d{2}/', $input, $matches);
}
if(empty($matches)) {
preg_match('/\d{4}/', $input, $matches);
}
return $matches[0];
}

function getDoubanRawData($title, $limit = 20) {
$title = urlencode($title);
return json_decode( HTTPGETRequest( API_URL . "search?q={$title}&count={$limit}" ) , true);
}

function getDoubanMovieData($id) {
$cache_path = GetPluginDataDirectory(PLUGINID) . "/{$id}/moiveInfo.json";
$cache_path = GetPluginDataDirectory(PLUGINID) . "/{$id}/movieInfo.json";
$url = API_URL . "subject/{$id}";
$ret = DownloadMovieData($url, $cache_path);

Expand Down Expand Up @@ -82,9 +97,9 @@ function DownloadMovieData($url, $cache_path) {

//If we need refresh cache file, grab rawdata from url website
if (FALSE === $json) {
$response = json_decode(HTTPGETRequest($url));
refreshCache($response, $cache_path);
}
$json = json_decode(HTTPGETRequest($url));
refreshCache($json, $cache_path);
}

return $json;
}
Expand All @@ -97,17 +112,17 @@ function DownloadAddOnInfo ($url, $cache_path, $ret) {
$html = HTTPGETRequest($url);
$json = array();
$json['original_available'] = getRegexDate(RegexByRel('v:initialReleaseDate', $html));
$json['imdb'] = RegexByRel('nofollow', $html);
$json['backdrop'] = 'https://img3.doubanio.com/view/photo/photo/public/p' . getBackdrop($html) . '.webp';
$json['genres'] = RegexByRel('v:genre');
$json['casts'] = RegexByRel('v:starring');
$json['imdb'] = getImdbID($html);
$json['backdrop'] = 'https://img3.doubanio.com/view/photo/photo/public/p' . getBackdrop($html) . '.jpg';
$json['genres'] = RegexByRel('v:genre', $html);
$json['casts'] = RegexByRel('v:starring', $html);
$json['writers'] = getWriter($html);
refreshCache($json, $cache_path);
}

foreach($json as $key => $val) {
$ret[$key] = $val;
$ret->$key = $val;
}

return $ret;
}
}