From 82b9b34a12a393e1018c21e2e69de83e010ab641 Mon Sep 17 00:00:00 2001 From: jemyzhang Date: Thu, 11 Jan 2018 10:33:30 +0800 Subject: [PATCH 1/5] fix bugs, make the scripts work again - urlencode title - fix orignal date if is not a full format - fix backdrops id - fix various errors --- doubanSearch.php | 19 ++++++++----------- search.php | 3 +++ utils.php | 41 ++++++++++++++++++++++++++++------------- 3 files changed, 39 insertions(+), 24 deletions(-) diff --git a/doubanSearch.php b/doubanSearch.php index 2f14b20..c802836 100644 --- a/doubanSearch.php +++ b/doubanSearch.php @@ -2,9 +2,6 @@ require_once(dirname(__FILE__) . '/utils.php'); -$SUPPORTED_TYPE = array('movie'); -$SUPPORTED_PROPERTIES = array('title'); - function GetMovieInfoDouban($movie_data, $data) { /** @@ -22,7 +19,7 @@ function GetMovieInfoDouban($movie_data, $data) $data['extra'][DOUBAN_PLUGINID]['reference']['themoviedb'] = $movie_data->id; $data['doubandb'] = true; - if (isset($movie_data->imdb_id)) { + if (isset($movie_data->imdb)) { $data['extra'][DOUBAN_PLUGINID]['reference']['imdb'] = $movie_data->imdb; // add-on } if ((float)$movie_data->rating) { @@ -31,7 +28,7 @@ function GetMovieInfoDouban($movie_data, $data) if (isset($movie_data->images)) { $data['extra'][DOUBAN_PLUGINID]['poster'] = array($movie_data->images->large); } - if (isset($movie_data->backdrop_path)) { + if (isset($movie_data->backdrop)) { $data['extra'][DOUBAN_PLUGINID]['backdrop'] = array($movie_data->backdrop); // add-on } if (isset($movie_data->belongs_to_collection)) { @@ -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); } } } @@ -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); } } } @@ -77,7 +74,7 @@ function GetMovieInfoDouban($movie_data, $data) return $data; } -function GetMetadataDouban($query_data, $lang) +function GetMetadataDouban($query_data) { global $DATA_TEMPLATE; @@ -123,4 +120,4 @@ function ProcessDouban($input, $lang, $type, $limit, $search_properties, $allowg return GetMetadataDouban($query_data['subjects']); } -?> \ No newline at end of file +?> diff --git a/search.php b/search.php index 8cbfa58..0bc36ac 100644 --- a/search.php +++ b/search.php @@ -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(); diff --git a/utils.php b/utils.php index 731bd8e..ae5addd 100644 --- a/utils.php +++ b/utils.php @@ -7,6 +7,11 @@ 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]; @@ -14,27 +19,37 @@ function RegexByRel($rel, $input) { 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); @@ -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; } @@ -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; -} \ No newline at end of file +} From c8fb85668ef530c52933bd3331c51202003489d6 Mon Sep 17 00:00:00 2001 From: JemyZhang Date: Sat, 13 Jan 2018 11:39:02 +0800 Subject: [PATCH 2/5] update install/uninstall script for safe installing --- install.sh | 45 +++++++++++++++++++++++++++++---------------- uninstall.sh | 22 +++++++++++----------- 2 files changed, 40 insertions(+), 27 deletions(-) diff --git a/install.sh b/install.sh index 8bb85b1..cd459d5 100644 --- a/install.sh +++ b/install.sh @@ -1,27 +1,40 @@ #!/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'; +VERSION='1.1'; +INSTALLED_VERSION= -cd /tmp/; +DOWNLOAD_URL="https://github.com/jemyzhang/synoDoubanVideoInfo/releases/download/$VERSION/douban.tar" +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; \ No newline at end of file diff --git a/uninstall.sh b/uninstall.sh index 327a5e9..0cc836a 100644 --- a/uninstall.sh +++ b/uninstall.sh @@ -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; \ No newline at end of file +rm -f ${PLUGIN_ORIG_TGZ} From 6f8085cb9934b68937455e158270de256ea4d0c7 Mon Sep 17 00:00:00 2001 From: JemyZhang Date: Sun, 14 Jan 2018 16:17:53 +0800 Subject: [PATCH 3/5] filter out tv content --- doubanSearch.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/doubanSearch.php b/doubanSearch.php index c802836..5f509a4 100644 --- a/doubanSearch.php +++ b/doubanSearch.php @@ -82,6 +82,10 @@ function GetMetadataDouban($query_data) $result = array(); foreach($query_data as $item) { + //Filter the content + if($item['subtype'] != 'movie') { + continue; + } //Copy template $data = $DATA_TEMPLATE; From 6d80720696be31b53e16cbb265d4a604e7e0864b Mon Sep 17 00:00:00 2001 From: JemyZhang Date: Mon, 15 Jan 2018 23:16:00 +0800 Subject: [PATCH 4/5] fix plugin data cached in error PLUGINID directory --- doubanSearch.php | 14 +++++++------- utils.php | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/doubanSearch.php b/doubanSearch.php index 5f509a4..548701c 100644 --- a/doubanSearch.php +++ b/doubanSearch.php @@ -15,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)) { - $data['extra'][DOUBAN_PLUGINID]['reference']['imdb'] = $movie_data->imdb; // add-on + $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)) { - $data['extra'][DOUBAN_PLUGINID]['backdrop'] = array($movie_data->backdrop); // add-on + $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 diff --git a/utils.php b/utils.php index ae5addd..81e7b52 100644 --- a/utils.php +++ b/utils.php @@ -2,7 +2,7 @@ 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); From a8b396282a29ed9a684d299337106f349e6d1ca2 Mon Sep 17 00:00:00 2001 From: jemyzhang Date: Fri, 26 Jan 2018 09:17:02 +0800 Subject: [PATCH 5/5] update installer, get the latest version via api --- README.md | 11 +++++++++++ install.sh | 10 +++++++--- uninstall.sh | 0 3 files changed, 18 insertions(+), 3 deletions(-) mode change 100644 => 100755 install.sh mode change 100644 => 100755 uninstall.sh diff --git a/README.md b/README.md index d2f134c..aee98bf 100644 --- a/README.md +++ b/README.md @@ -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. + diff --git a/install.sh b/install.sh old mode 100644 new mode 100755 index cd459d5..0630d74 --- a/install.sh +++ b/install.sh @@ -3,10 +3,14 @@ PLUGIN_PATH=/var/packages/VideoStation/target/plugins/syno_themoviedb PLUGIN_ORIG_TGZ=${PLUGIN_PATH}.orig.tgz -VERSION='1.1'; -INSTALLED_VERSION= -DOWNLOAD_URL="https://github.com/jemyzhang/synoDoubanVideoInfo/releases/download/$VERSION/douban.tar" +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 diff --git a/uninstall.sh b/uninstall.sh old mode 100644 new mode 100755