From f97ea1e00314766203a783415ef6690f34c19f8a Mon Sep 17 00:00:00 2001 From: jonnyboy Date: Fri, 29 Mar 2013 11:47:33 -0400 Subject: [PATCH] more updates from ugo and more tweaks from me --- bin/monitor.php | 7 +- commit.sh | 5 +- conf/jonnyboys_defaults.sh | 541 ---- ugo/automake.php | 2 +- ugo/automake_threaded.php | 47 +- ugo/misc_sorter3.php | 4606 +++++++++++++++++----------------- ugo/misc_sorter_threaded.php | 278 +- 7 files changed, 2497 insertions(+), 2989 deletions(-) delete mode 100644 conf/jonnyboys_defaults.sh diff --git a/bin/monitor.php b/bin/monitor.php index 2f99e3264..1941fa27e 100644 --- a/bin/monitor.php +++ b/bin/monitor.php @@ -2,7 +2,7 @@ require(dirname(__FILE__)."/config.php"); require(WWW_DIR.'/lib/postprocess.php'); -$version="0.1r753"; +$version="0.1r754"; $db = new DB(); @@ -62,8 +62,6 @@ $mysql_command_1 = "$_mysql --defaults-file=$_conf/my.cnf -u$_DB_USER -h $_DB_HO $reset_bin = "UPDATE binaries SET procstat=0, procattempts=0, regexID=NULL, relpart=0, reltotalpart=0, relname=NULL;"; $mysql_command_2 = "$_mysql --defaults-file=$_conf/my.cnf -u$_DB_USER -h $_DB_HOST $_DB_NAME -e \"$reset_bin\""; -$rel = $db->query("UPDATE `binaries` SET `procstat`=0,`procattempts`=0,`regexID`=NULL, `relpart`=0,`reltotalpart`=0,`relname`=NULL WHERE procstat not in (4, 6)"); - //got microtime function microtime_float() { @@ -353,6 +351,7 @@ while( $i > 0 ) printf("$a.."); sleep(1); } + $rel = $db->query("UPDATE `binaries` SET `procstat`=0,`procattempts`=0,`regexID`=NULL, `relpart`=0,`reltotalpart`=0,`relname`=NULL WHERE procstat not in (4, 6)"); } //defrag the query cache every 15 minutes @@ -1061,7 +1060,7 @@ while( $i > 0 ) if (( $array['MAX_LOAD_RELEASES'] >= get_load()) && ( $array['RELEASES'] == "true" ) && ( $array['UGO_THREADED'] == "true" ) && ( $optimize_safe_to_run != "true" )) { $color = get_color(); $log = writelog($panes0[5]); - shell_exec("$_tmux respawnp -t {$array['TMUX_SESSION']}:0.5 'echo \"\033[38;5;\"$color\"m\" && $ds1 $panes0[5] $ds2 && cd $_ugo && $_php automake_threaded.php && cd $_bin && $_php update_releases.php 2>&1 $log && echo \" \033[1;0;33m\" && echo \"sleeping\033[38;5;\"$color\"m {$array['RELEASES_SLEEP']} seconds...\" && sleep {$array['RELEASES_SLEEP']} && $ds1 $panes0[5] $ds3' 2>&1 1> /dev/null"); + shell_exec("$_tmux respawnp -t {$array['TMUX_SESSION']}:0.5 'echo \"\033[38;5;\"$color\"m\" && $ds1 $panes0[5] $ds2 && cd $_ugo && $_php automake_threaded.php && cd $_bin && $_php update_releases.php && cd $_ugo && php misc_sorter_threaded.php 2>&1 $log && echo \" \033[1;0;33m\" && echo \"sleeping\033[38;5;\"$color\"m {$array['RELEASES_SLEEP']} seconds...\" && sleep {$array['RELEASES_SLEEP']} && $ds1 $panes0[5] $ds3' 2>&1 1> /dev/null"); } elseif (( $array['MAX_LOAD_RELEASES'] >= get_load()) && ( $array['RELEASES'] == "true" ) && ( $optimize_safe_to_run != "true" )) { $color = get_color(); $log = writelog($panes0[5]); diff --git a/commit.sh b/commit.sh index 852aa6f23..e00d7883f 100755 --- a/commit.sh +++ b/commit.sh @@ -4,8 +4,9 @@ commit=`git log | grep "^commit" | wc -l` commit=`expr $commit + 1` sed -i -e "s/\$version=.*$/\$version=\"0.1r$commit\";/" bin/monitor.php -cp -f defaults.sh conf/jonnyboys_defaults.sh -sed -i -e 's/export SVN_PASSWORD=.*$/export SVN_PASSWORD="password"/' conf/jonnyboys_defaults.sh +cp -f /etc/mysql/my.cnf conf/my.cnf +cp -f defaults.sh conf/defaults.sh +sed -i -e 's/export SVN_PASSWORD=.*$/export SVN_PASSWORD="password"/' conf/defaults.sh git commit -a diff --git a/conf/jonnyboys_defaults.sh b/conf/jonnyboys_defaults.sh deleted file mode 100644 index a652af640..000000000 --- a/conf/jonnyboys_defaults.sh +++ /dev/null @@ -1,541 +0,0 @@ -#!/usr/bin/env bash -DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" - -#Copy this file to defaults.sh -#DO NOT EDIT THIS FILE - -#########################EDIT THESE######################### -############################################################ - -#This is the shutdown, true/false -#on, it runs, off and no scripts will be RESTARTED, when all panes are DEAD, killall tmux -#if this is set to false, the script will run 1 loop and terminate -export RUNNING="true" - -#these scripts set the 'nice'ness of each script, default is 19, the lowest, the highest is -20 -#anything between -1 and -20 require root/sudo to run -export NICENESS="10" - -#these scripts can add some serious load to your system, without proper monitoring it can be -#to much, you can set the max load that any pane will be started at -#for example, if you set load to 2, no pane will start when your system load exceeds 2 -#this does not mean the the desired load will not be exceeded, just that no panes will be be restarted -#this one is for all panes except update_releases -export MAX_LOAD="4.25" - -#this one is for update_releases -export MAX_LOAD_RELEASES="4.25" - - -############################################################ - -#Set paths -export NEWZPATH="/var/www/newznab" - -#Should not need to change -export NEWZNAB_PATH=$NEWZPATH"/misc/update_scripts" -export TESTING_PATH=$NEWZPATH"/misc/testing" -export ADMIN_PATH=$NEWZPATH"/www/admin" - -############################################################ - -#Post Processing Additional is the post processing that downloads rar files and attempts to get info for your site -#you are able to set the number of process to be run from 1-32, remember that each process uses 1 of your nntp connections -#so, if you have 20, and you set this to 32, you will have errors, lots of errors, nfo lookup uses 1 -3 connections -#binaries and backfill threaded default up to 10 connections each and predb uses 1, so understand how many connections you are using when setting -#trial and error for this, set to 1 will run > 0, set to 2 will run > 200, 3 will run > 300 and so on. -#At some point, increasing this begins to slow things down. It will need to be adjusted for your system -#to get the desired performance, 0 will disable all post processing -export POST_TO_RUN="10" - -#or you can run them as they are run in stock, during update releases, this will disable all postprocessing windows and only run during update_releases -export ALMOST_STOCK="true" - -############################################################ - -#post processing per category, setting the above to 0 does not disable these -#run processNfos -export NFOS="true" - -#run processGames -export GAMES="true" - -#run processMovies -export MOVIES="true" - -#run processMusic -export MUSIC="true" - -#run processTV -export TVRAGE="true" - -#run processEbook -export EBOOK="true" - -#run processOther -export OTHERS="true" - -#run processUnwanted -export UNWANTED="true" - -############################################################ - -#Enter the session name to be used by tmux, no spaces allowed in the name, this can be changed after scripts start -#if you are running multiple servers, you could put your hostname here -export TMUX_SESSION="Ubuntu-dev" - -#Set, in seconds - how often the monitor.php (left top pane) script should update run the queries against the database -#the monitor script will update itself and each pane, once every 5 seconds plus the lagg time time on the loop the db is queried -#to press the point, the db is not queried any sooner than the time set below, but the script loops each iteration once every 5 seconds -#this makes it more responsive to stop/kill without slamming the db with needless queries, starts are still controlled by the queries -export MONITOR_UPDATE="30" - -#you may want to kill the update_binaries, backfill and import if no releases have been add in x minutes, set the timer to anything other than 0 to enable -#this will only run every 5 loops of monitor -export KILL_UPDATES="0" - -#do you want to just cause it to restart or keep off until a release is created, true for off until a release is created -#this will stop all downloads and imports -export KEEP_KILLED="false" - -############################################################ - -#You can have backfill loop constantly and interject binaries every so often -#by setting this next to true, if true, the normal backfill pane will be dead -#this works by setting the 2 start timers and which is run at the start of the loop is determined like this -#if at the start of the loop, the BINARIES_SEQ_TIMER has expired, then update_binaries will run and the BINARIES_SEQ_TIMER timer is reset -#if BINARIES_SEQ_TIMER has not expired, then if BACKFILL_SEQ_TIMER has expired, the backfill will run and BACKFILL_SEQ_TIMER timer is reset -export SEQUENTIAL="true" - -#time between loop start for update_binaries, in seconds, this is a countdown timer, not a sleep after it runs -#default is 30 minutes -#will run on first loop and then not again for at least 1800 seconds -export BINARIES_SEQ_TIMER="900" - -#this will not run on first loop, time between loop start for backfill, in seconds -#default is 10 seconds, this will run after time has expired, binaries will take precedence and run before this, if its time has expired -export BACKFILL_SEQ_TIMER="10" - -############################################################ - -#Choose to run update_binaries true/false -export BINARIES="true" - -#Choose to run the threaded or non-threaded newznab binaries scripts true/false -#update_binaries.php or update_binaries_threaded.php -export BINARIES_THREADS="true" - -#Set, in seconds - how long the update_binaries should sleep between runs -#top right pane -#sleep timers are not used when using SEQ -export BINARIES_SLEEP="900" - -#Set the max amount of binaries in the binaries table and still allow update_binaries to run -#set to 0 to disable -export BINARIES_MAX_BINS="0" - -#Set the max amount of unprocessed releases and still allow update_binaries to run -#set to 0 to disable -export BINARIES_MAX_RELEASES="0" - -#Set the max amount of of rows in the parts table and still allow update_binaries to run -#set to 0 to disable -export BINARIES_MAX_ROWS="0" - -############################################################ - -#Choose to run backfill script true/false -export BACKFILL="true" - -#Choose to run the threaded or non-threaded newznab backfill scripts true/false -#backfill.php or backfill_threaded.php -export BACKFILL_THREADS="true" - -#Set, in seconds - how long the backfill should sleep between runs -#in pane below update_binaries -#sleep timers are not used when using SEQ -export BACKFILL_SLEEP="5" - -#Set the max amount of unprocessed releases and still allow backfill to run -#set to 0 to disable -export BACKFILL_MAX_RELEASES="0" - -#Set the max amount of binaries in the binaries table and still allow backfill to run -#set to 0 to disable -export BACKFILL_MAX_BINS="0" - -#Set the max amount of of rows in the parts table and still allow backfill to run -#set to 0 to disable -export BACKFILL_MAX_ROWS="0" - -#Set the maximum days to backfill, you set the Newznab+ admin/edit backfill to 1 -#this will increment your database by 1 after each backfill loop -#once your backfill numbers reach $MAXDAYS, then it will no long increment the database -#backfill will continue to run, and do no work, at that point you should disable backfill, below -export MAXDAYS="1700" - -############################################################ - -#use kevin123's safer_backfill_parts.php instead of normal backfill or backfill threaded -#this is the script I use, it does 1 group at a time from z to a (wanted to start with tv groups first) 100k parts, -#then the script stops (once per loop), if your first_record_postdate on the group is 2012-06-24 -#it will be skipped (target reached). When that group is done, it will do another ( again from z to a). -#this does not use increment, it works by the date set below -#you also need to enable kevin's compression mod, those files are needed and you still need to enable BACKFILL -export KEVIN_SAFER="trued" - -#use kevin123's backfill_parts.php instead of normal backfill -export KEVIN_BACKFILL_PARTS="trued" - -#use kevin123's backfill_parts_threaded.php instead of normal -export KEVIN_THREADED="truef" - -#set the date to go back to, must be in the format of YYYY-MM-DD, like 2012-06-24 -export KEVIN_DATE="2008-08-15" - -#set the number of articles/headers to download at one time -export KEVIN_PARTS="500000" - -############################################################ - -#Set the path to the nzb dump you downloaded from torrents, this is the path to bulk files folder of nzbs -#this does not recurse through subfolders, unless you set NZB_THREADS to true -export NZBS="/path/to/nzbs" - -#Choose to run import nzb script true/false -export IMPORT="false" - -#If, you have all of your nzbs in one folder select false -#If, you have all of you nzbs split into separate in with the root at $NZBS then select true -#and 10 nzbs will be imported from each subfolder per loop. -#Importing this way, allows all post processing scripts to run, such as book, music, movies -#Instead of doing all 1 type at once, spread the load -export NZB_THREADS="false" - -#Set max number of folders to process per loop. This includes empty folders. -export NZB_FOLDER_COUNT="20" - -#How many nzbs to import per loop, if using NZB_THREADS=true the per folder -export NZBCOUNT="10" - -#Set, in seconds - how long the nzb-import should sleep between runs -#below backfill -export IMPORT_SLEEP="40" - -#Set the max amount of unprocessed releases and still allow nzb-import to run -#set to 0 to disable -export IMPORT_MAX_RELEASES="0" - -#Set the max amount of of rows in the parts table and still allow nzb-import to run -#set to 0 to disable -export IMPORT_MAX_ROWS="0" - -#import nzbs using the filename as the release name true/false -export IMPORT_TRUE="false" - -############################################################ - -#MAX_RELEASES for each can be calculated on the total post processing or just the Misc category -#to calculate on just the Misc, enable this -export MISC_ONLY="true" - -############################################################ - -#run ugo's automake.php script to create releases, this does not use regexes and will run in a loop prior -#to update_releases.php -export UGO_THREADED="truef" - -############################################################ - -#Create releases, this is really only necessary to turn off when you only want to post process -export RELEASES="true" - -#Set, in seconds - how long the update_release should sleep between runs -#bottom right -export RELEASES_SLEEP="5" - -############################################################ - -#Choose to run optimize_innodb.php or optimize_mysiam.php script true/false -#set to false by default, you should test the optimize scripts in bin first -#optimize_myisam on small tables runs after every 5th loop of update_releases -export OPTIMIZE="truej" - -#optimize can wait, patiently while all other panes stop and then run -#or, forcefully terminate all panes while it runs, to kill all panes and run optimize, enable -export OPTIMIZE_KILL="true" - -#How often to run optimize_myisam on small tables seconds, default is 10 min -export MYISAM_SMALL="1800" - -#How often to run optimize_myisam on large tables seconds, default is 1 hr -export MYISAM_LARGE="3600" - -#How often to run optimize_innodb on small tables in seconds, default is 2 hr -export INNODB_SMALL="7200" - -#How often to run optimize_innodb on large tables in seconds, default is 48 hrs -export INNODB_LARGE="172800" - -############################################################ - -#Choose your database engine, comment the one true/false -#you should have already converted your database to InnoDB engine, if you select true here -export INNODB="false" - -############################################################ - -#Choose to run update_cleanup.php and removespecial.php true/false -#set to false by default, you will need to edit /misc/testing/update_cleanup.php and /misc/testing/update_parsing.php -#to actually do anything, directions are in the file -export CLEANUP="false" - -#edit update_cleanup.php and update_parsing.php and svn up, this will only mod files when you run scripts/update_svn.sh or scripts/fix_files.sh -export CLEANUP_EDIT="true" - -#How often do you want update_cleanup.php and removespecial.php to run, in seconds -export CLEANUP_TIMER="3600" - -############################################################ - -#Choose to run update_parsing.php true/false -#set to false by default, you will need to edit /misc/testing/update_parsing.php -#to actually do anything, directions are in the file -export PARSING="true" - -#choose to use kevin123's update_parsing script -#this also includes kevin123's categorymod.php, you must run either update_svn.sh or fix_files.sh to copy the file into place -export PARSING_MOD="true" - -#run update_parsing.php against the whole db or just the last 24 hours -export PAST_24_HOURS="false" - -#How often do you want update_parsing.php to run, in seconds. this takes alot of memory and processing time, default is every 12 hrs -export PARSING_TIMER="300" - -############################################################ - -#Choose to run update_predb.php -export PREDB="true" - -#How often to update the PreDB in seconds -export PREDB_TIMER="900" - -############################################################ - -#Choose to run processSpotnab.php -export SPOTNAB="true" - -#How often to update the PreDB in seconds -export SPOTNAB_TIMER="900" - -#automatically set ALL sources to active after retrieving sources -export SPOTNAB_ACTIVE="true" - -############################################################ - -#update the tv schedule and in theaters listings -export TV_SCHEDULE="true" - -#How often to update the TV Schedule and the In Theaters in seconds -export TVRAGE_TIMER="43200" - -############################################################ - -#Choose to run sphinx.php script true/false -#set to false by default, you should test the script first, php sphinx.php from the bin folder -export SPHINX="false" - -#How often to run sphinx in seconds -export SPHINX_TIMER="3600" - -############################################################ - -#mediainfo and ffmpeg can hang occasionally, set timer, in seconds, to anything other than 0 to enable -#it should not need to run longer that 120 seconds -export KILL_PROCESS="120" - -#look at man killall - if you have the -q option, enable this, otherwise leave it disabled -export KILL_QUIET="true" - -############################################################ - -#Delete parts and binaries older than retention days, which is set in edit - site -#this uses a script posted by cj https://github.com/NNScripts/nn-custom-scripts -export DELETE_PARTS="trued" - -#how often should this be run, default it 1 hr -export DELETE_TIMER="3600" - -#Releases may be added/edited with an imdb-id that does not exists in the movieinfo table. This script, update_missing_movie_info, -#will fetch all the missing imdb id's from the releases table. -export FETCH_MOVIE="true" - -#how often should this be run, default it 12 hr -export MOVIE_TIMER="43200" - -############################################################ - -#Specify your SED binary, if you are using freebsd or mac, you need to install gnu sed (gsed) and adjust the path -export SED="/bin/sed" -#export SED="/usr/local/bin/gsed" - -#freebsd, and maybe mac, does not contain SIGSTKFLT, SIGCLD, SIGPOLL, SIGPWR -#and powerprocess.php will error on one of those, but appears to work if they -#are commented out, enable to have the script comment them out while running update_svn -export FIX_POSIX="false" - -############################################################ - -#Select some monitoring script, if they are not installed, it will not affect the running of the scripts -#these are set to false by default, enable if you want them -export USE_HTOP="false" -export USE_BWMNG="false" -export USE_MYTOP="false" -export USE_VNSTAT="false" -export USE_ATOP="false" -export USE_NMON="false" -export USE_IOTOP="false" - -#freebsd does not have iotop, but can run top -m io -o total -export USE_TOP="false" - -export USE_IFTOP="false" -#select interface to listen, only 1 interface -export INTERFACE="eth0" - -#an additional window can be created manually with Ctrl-a c or it can be created at start of script -export USE_CONSOLE="false" - -############################################################ - -#Use powerline scripts to display the status bar -#To display properly, you need a modified font, download and install the font and then select that font in your terminal -#This is done on the terminal computer, not the newznab++ server -#download fonts from https://github.com/jonnyboy/powerline-fonts -#I recommend Consolas if you are using putty in Win7 -export POWERLINE="true" - -############################################################ - -#set your LANG to which ever you like, only effects these scripts -export LANG="en_US.UTF-8" - -#to help IMDB return only English titles, enable this, you will need to run update_svn.php or fix_files.sh -export EN_IMDB="true" - -############################################################ - -#newzdash is a web front end to show statistics of your Newznab+ install -#to use, you must first install from https://github.com/AlienXAXS/newzdash - -#this is YOUR shared key and allows these scripts to communicate with newzdash -export NEWZDASH_SHARED_SECRET="" - -#the url of your newzdash install, ensure it include HTTP:// or HTTPS:// or it will fail -#to disable leave blank ie. export NEWZDASH_URL="" -export NEWZDASH_URL="" - -########################################################### - -#Use tmpfs to run post processing on true/false -#to keep from running scripts as root, you can create your own ramdisk by adding the next line to /etc/fstab -#tmpfs /var/www/newznab/nzbfiles/tmpunrar1 tmpfs user,nodev,nodiratime,nosuid,size=256M,mode=777 0 0 -#edit the path, the path MUST be the path in site edit with a "1" appended to the end, like above -#you still need to set this to true or mount it manually as your user, not as root -export RAMDISK="true" - -#for freebsd, it is just a little different, you can either create the ramdisk and mount it by adding the next line to /etc/fstab -#tmpfs /var/www/newznab/nzbfiles/tmpunrar1 tmpfs rw,size=256M,mode=777 0 0 -#or, give users the permission to mount it by running sudo sysctl vfs.usermount=1 and then add the next line to /etc/fstab -#tmpfs /var/www/newznab/nzbfiles/tmpunrar1 tmpfs rw,noauto,size=256M,mode=777 0 0 - -############################################################ - -#set svn password, for use with scripts/update_svn.sh -#update_svn.sh is destructive, it update your version to match the svn version -export SVN_PASSWORD="password" - -#running update_svn as root will change file ownership of every file in the svn path -#to chown -R the path, enable and set user/group -#newznab/nzbfiles is not chown'd -export CHOWN_TRUE="true" - -#set CHOWN_TRUE="true" and WWW_USER="{youruser}:www-data" and run update_svn.sh or fix_files.sh -#and you will will not need root to run these scripts -export WWW_USER="jonnyboy:www-data" - -########################################################### - -#if you have a ramdisk and would like to monitor it's use, set path here -#this is not the same as RAMDISK above, I keep my parts table on a ramdisk -export RAMDISK_PATH="/var/ramdisk" - -########################################################### - -#logs can be written, per pane, to the logs folder -export WRITE_LOGS="truel" - -########################################################### - -#user defined scripts, you can define 3 scripts to run at specific times -#you must have them in the user_scripts, no other location -#This one will run before tmux creates the ui, so if you want to run something before the scripts add here -#it is assumed that the script is a bash script and has been chmod +x -export USER_DEF_ONE="" - -#this one will run before MyIsam Large -export USER_DEF_TWO="" - -#this one will run after MyIsam Large -export USER_DEF_THREE="" - -########################################################### - -#By using this script you understand that the programmer is not responsible for any loss of data, users, or sanity. -#You also agree that you were smart enough to make a backup of your database and files. Do you agree? yes/no -export AGREED="yes" - -############################################################ - -##END OF EDITS## - -command -v mysql >/dev/null 2>&1 || { echo >&2 "I require mysql but it's not installed. Aborting."; exit 1; } && export MYSQL=`command -v mysql` -command -v php5 >/dev/null 2>&1 && export PHP=`command -v php5` || { export PHP=`command -v php`; } -command -v tmux >/dev/null 2>&1 || { echo >&2 "I require tmux but it's not installed. Aborting."; exit 1; } && export TMUXCMD=`command -v tmux` -command -v nice >/dev/null 2>&1 || { echo >&2 "I require nice but it's not installed. Aborting."; exit 1; } && export NICE=`command -v nice` -command -v tee >/dev/null 2>&1 || { echo >&2 "I require tee but it's not installed. Aborting."; exit 1; } && export TEE=`command -v tee` - -if [[ $USE_HTOP == "true" ]]; then - command -v htop >/dev/null 2>&1|| { echo >&2 "I require htop but it's not installed. Aborting."; exit 1; } && export HTOP=`command -v htop` -fi -if [[ $USE_NMON == "true" ]]; then - command -v nmon >/dev/null 2>&1 || { echo >&2 "I require nmon but it's not installed. Aborting."; exit 1; } && export NMON=`command -v nmon` -fi -if [[ $USE_BWMNG == "true" ]]; then - command -v bwm-ng >/dev/null 2>&1|| { echo >&2 "I require bwm-ng but it's not installed. Aborting."; exit 1; } && export BWMNG=`command -v bwm-ng` -fi -if [[ $USE_IOTOP == "true" ]]; then - command -v iotop >/dev/null 2>&1|| { echo >&2 "I require iotop but it's not installed. Aborting."; exit 1; } && export IOTOP=`command -v iotop` -fi -if [[ $USE_TOP == "true" ]]; then - command -v top >/dev/null 2>&1|| { echo >&2 "I require top but it's not installed. Aborting."; exit 1; } && export TOP=`command -v top` -fi -if [[ $USE_MYTOP == "true" ]]; then - command -v mytop >/dev/null 2>&1|| { echo >&2 "I require mytop but it's not installed. Aborting."; exit 1; } && export MYTOP=`command -v mytop` -fi -if [[ $USE_VNSTAT == "true" ]]; then - command -v vnstat >/dev/null 2>&1|| { echo >&2 "I require vnstat but it's not installed. Aborting."; exit 1; } && export VNSTAT=`command -v vnstat` -fi -if [[ $USE_IFTOP == "true" ]]; then - command -v iftop >/dev/null 2>&1|| { echo >&2 "I require iftop but it's not installed. Aborting."; exit 1; } && export IFTOP=`command -v iftop` -fi -if [[ $USE_ATOP == "true" ]]; then - command -v atop >/dev/null 2>&1|| { echo >&2 "I require atop but it's not installed. Aborting."; exit 1; } && export ATOP=`command -v atop` -fi -if [[ $POWERLINE == "true" ]]; then - export TMUX_CONF="powerline/tmux.conf" -else - export TMUX_CONF="conf/tmux.conf" -fi - diff --git a/ugo/automake.php b/ugo/automake.php index ec9a0f2f5..21696a76d 100644 --- a/ugo/automake.php +++ b/ugo/automake.php @@ -718,7 +718,7 @@ global $db; $time = microtime(true) - $time; - if ($time > .5) + if ($time > .75) trigger_error("\ntime = $time \tmatches = ".count($matches)."\nquery = ".$query."\n"); echo count($matches)." ".$query."\n"; diff --git a/ugo/automake_threaded.php b/ugo/automake_threaded.php index 27d56050f..634361190 100644 --- a/ugo/automake_threaded.php +++ b/ugo/automake_threaded.php @@ -21,10 +21,21 @@ if (isset($argv[1])) } } -echo "Getting list of spam\n"; -$rel = $db->query("UPDATE `binaries` SET `procstat`=-2 WHERE `xref` REGEXP '(.+:[0-9]+ ){5,}'"); -echo "spam ".$db->getAffectedRows()."\n"; +echo "cleaning spam..... can take a few moments\n"; +//$db->disableAutoCommit(); +//$db->disableForeignKeyChecks(); + +$rel = $db->query("SELECT `ID` from `binaries` WHERE `xref` REGEXP '(.+:[0-9]+ ){5,}' AND `procstat` = 0"); + +foreach($rel as $r) +{ + $db->query("UPDATE `binaries` set `procstat` = -2 WHERE `ID` = ".$r['ID']); + if ($db->getLastError() != '') + var_dump($db->getLastError()); +} + +echo "spam count ".count($rel)."\n"; $rel = $db->query("UPDATE `binaries` SET `procstat`=0,`procattempts`=0,`regexID`=NULL, `relpart`=0,`reltotalpart`=0,`relname`=NULL WHERE procstat = -6"); @@ -42,20 +53,9 @@ function get_load() { return $load[0]; } -//get variables from config.sh and defaults.sh -$path = dirname(__FILE__); -$varnames = shell_exec("cat ".$path."/../config.sh | grep ^export | cut -d \= -f1 | awk '{print $2;}'"); -$varnames .= shell_exec("cat ".$path."/../defaults.sh | grep ^export | cut -d \= -f1 | awk '{print $2;}'"); -$vardata = shell_exec("cat ".$path."/../config.sh | grep ^export | cut -d \\\" -f2 | awk '{print $1;}'"); -$vardata .= shell_exec("cat ".$path."/../defaults.sh | grep ^export | cut -d \\\" -f2 | awk '{print $1;}'"); -$varnames = explode("\n", $varnames); -$vardata = explode("\n", $vardata); -$array = array_combine($varnames, $vardata); -unset($array['']); - -$ps = new PowerProcess(8,0,false); +$ps = new PowerProcess(4,0,false); $ps->RegisterCallback('psUpdateComplete'); -$ps->maxChildren = 8; +$ps->maxChildren = 4; $ps->tickCount = 10000; // value in usecs. change this to 1000000 (one second) to reduce cpu use $ps->threadTimeLimit = 0; // Disable child timeout @@ -72,6 +72,17 @@ while ($ps->RunControlCode()) $listcount = count($theList); if ($listcount) { + //get variables from config.sh and defaults.sh + $path = dirname(__FILE__); + $varnames = shell_exec("cat ".$path."/../config.sh | grep ^export | cut -d \= -f1 | awk '{print $2;}'"); + $varnames .= shell_exec("cat ".$path."/../defaults.sh | grep ^export | cut -d \= -f1 | awk '{print $2;}'"); + $vardata = shell_exec("cat ".$path."/../config.sh | grep ^export | cut -d \\\" -f2 | awk '{print $1;}'"); + $vardata .= shell_exec("cat ".$path."/../defaults.sh | grep ^export | cut -d \\\" -f2 | awk '{print $1;}'"); + $varnames = explode("\n", $varnames); + $vardata = explode("\n", $vardata); + $array = array_combine($varnames, $vardata); + unset($array['']); + // We still have groups to process if ( $array['MAX_LOAD_RELEASES'] >= get_load()) { if ($ps->SpawnReady()) @@ -91,6 +102,10 @@ while ($ps->RunControlCode()) } else { // No more groups to process echo "\nNo more posts to process - Initiating shutdown\n"; + $ps->threadTimeLimit = 200; + do { + $ps->tick(); + } while ($ps->myThreads); $ps->Shutdown(); echo "Shutdown complete\n"; $tim = microtime(true) - $time; diff --git a/ugo/misc_sorter3.php b/ugo/misc_sorter3.php index 43c8ffa23..8d604b95b 100644 --- a/ugo/misc_sorter3.php +++ b/ugo/misc_sorter3.php @@ -1,2287 +1,2319 @@ - 1) - $author = trim($tmp[1]." ".$tmp[0]); - - $rel = $book->getBookInfoByName($author, $title); - - echo "book1 "; - var_dump($rel); - - if ($rel === false) - { - $query = "Select * from `bookinfo` WHERE `title` LIKE '%".$title."%' AND ID in (SELECT ID FROM `bookinfo` WHERE `author` sounds LIKE '".$author."')"; - $rel = $db->query($query); - - echo "book2 "; - var_dump($rel); - - if (isset($rel[0]["ID"])) - { - $bookID = $rel[0]["ID"]; - } else { - - $bookID = $book->updateBookInfo($author, $title); - } - } else { - $bookID = $rel['ID']; - } - unset($book); - echo "book ".$bookID."\n"; - return $bookID; -} - - -function findmusicname($row, $cat = 3010) -{ - global $db; - $ok = false; - - $query = "SELECT * FROM releases WHERE ( releases.passwordstatus < 0 AND releases.haspreview < 0 ) AND ID = ".$row['ID']; - $rel = $db->queryOneRow($query); - - if ($rel !== false) - return false; - - $query = "SELECT releasevideo.releaseID FROM releasevideo WHERE releasevideo.releaseID = ".$row['ID']; - $rel = $db->queryOneRow($query); - - if ($rel !== false) - return false; - - $query = "SELECT releasefiles.releaseID, releasefiles.`name` FROM releasefiles INNER JOIN releases ON releasefiles.releaseID = releases.ID WHERE releases.ID = ".$row['ID']." order by releasefiles.`name`"; - $rel = $db->query($query); - - $name = ''; - $ok = false; - - $m3u = ''; - $alt = ''; - $mp3 = false; - $mp3name = ''; - $files = 0; - $extras = 0; - $folder = ''; - $bookId = 0; - $musicId = 0; - - if (count($rel) > 0) - { - echo "findmusicname ".$row['ID']." ".count($rel)."\n"; - foreach($rel as $r) - { - $sub = $r['name']."\n"; - - $sub = preg_replace('/[\x01-\x1f]/', '', $sub); - - $sub = preg_replace('/(? 0.7) && $mp3)." ".$mp3." ".$m3u."\n"; - - if (($m3u != '' || (($files + $extras) / count($rel) > 0.7)) && $mp3) - { - $name = $m3u; - - if ($files == 1) - $name = $mp3name; - - if (empty($name)) - { - $name = matchnames($row['name'], $alt); - } - - echo $row['guid']." ".$name.' '.$mp3.' '.($files + $extras) / count($rel)."\n"; - } - - - // if (preg_match('/\.mp3|\.m3u|\.sfv|\.nfo|\.flac/|\.asf/', $r['name'])) - // echo "release file ".$r['name']."\n"; - - $name = preg_replace("/^\d+\-/i", '', $name); - $name = trim(preg_replace("/\\\\|^ +| +$/i", ' ', $name)); - -echo "file name $name\n"; - - } else { - $name = domusicfiles ($row); - } - -echo "found name $name\n"; - - if ($name != '') - { - $music = new Music(); - $result = $music->parseArtist($name); - $artist = $result['artist']; - $album = $result['album']; - - if (empty($album) && empty($artist)) - $album = $name; - -echo "1artist = $artist album = $album\n"; - - $album = stripname($album); - $artist = stripname($artist); - - $artist = preg_replace('/\d+/', '', $artist); - - $tmp = explode(",", $artist); - - if (count($tmp) > 1) - $artist = trim($tmp[1]." ".$tmp[0]); - - -echo "2artist = $artist album = $album\n"; - - $rel = $music->getMusicInfoByName($artist, $album); -// var_dump($rel); - $musicId = $rel['ID']; - - if ($musicId <= 1) - { - echo "amazon music1 "; - $musicId = $music->updateMusicInfo($artist, $album, 0); - - if ($musicId === false) - { -// $book = new Book(true); -// $bookId = $book->updateBookInfo($artist, $album); -// unset($book); - $bookId = findbookid ($artist, $album); - } -//var_dump($musicId); - } - -if (preg_match('/\.flac/', $mp3name)) - $cat = 3040; - -echo "music name: $name $musicId $bookId\n"; - if ($musicId > 1) - { - $ok = dodbupdate($row['ID'], $cat, $name, $musicId, 'music'); - } else if ($bookId > 0) { - $ok = dodbupdate($row['ID'], 3030, $name, $bookId, 'book'); - } else { - if (preg_match('/book/i', $row['gname'])) - $ok = dodbupdate($row['ID'], 3030, $name); - else - $ok = dodbupdate($row['ID'], $cat, $name); - } - - unset($music); - } - return $ok; -} - -function stripname($name) -{ - if (is_array($name)) - return $name; - - global $qualities; - - $quality = preg_replace('/(.+?)/iU', "/\b\\1\b.*?$/iU", $qualities); - -// var_dump($quality); - - $name1 = $name; - - do { - $original = $name1; -// echo "fm1: $name1\n"; - $name1 = preg_replace($quality, " ", $name1); - $name1 = preg_replace('/(as )?(requested|request|req):?/i', " ", $name1); - $name1 = preg_replace('/Thanks To Original Poster/i', " ", $name1); - $name1 = preg_replace('/\b[a-z]{1,2}[0-9]{1,2} /i', " ", $name1); - $name1 = preg_replace('/^\d+|\d+$/', '', $name1); - $name1 = preg_replace('/\battn:? [^ ]+\b/i', " ", $name1); - $name1 = preg_replace('/^National.?Geographic|^nat.?geo|^bbc/i', " ", $name1); - $name1 = preg_replace("/\.?(s\d+?e\d+?)\.?/iU", " \\1 ", $name1); - $name1 = preg_replace("/^(\[\d+\].\[.+\].(\[#?a.b.[^\]]+\])*?.)/iU", "", $name1); - $name1 = preg_replace("/\[(?![^\[]+\])|\((?![^\(]+\))|\{(?![^\{]+\})/iU", " ", $name1); - $name1 = preg_replace("/^\(?\?+?\)/iU", " ", $name1); - $name1 = preg_replace("/[\x01-\x1f\_\!\?\[\{\}\]\/\:\|]/iU", " ", $name1); - $name1 = preg_replace("/(?parseNameEpSeason($name); - - if (empty($showinfo['cleanname'])) - { - $showinfo['name'] = $name; - $showinfo['cleanname'] = $name; - } - -echo "clean ".$showinfo['cleanname']."\n"; - - $rageID = $tvrage->getByTitle($showinfo['cleanname']); - - } - -// echo "1 $name\n"; - - if ($rageID == false) - { - $rageID = $tvrage->parseRageIdFromNfo($nfo); - - $name1 = $tvrage->getRageInfoFromService($rageID); -// var_dump($name1); - if (isset($name1['name']) && $name1['name'] != '') - $name = $name1['name']; - else - { - if (!isset($showinfo['cleanname'])) - $showinfo = $tvrage->parseNameEpSeason($name); - $showInfo1 = array( - 'name' => '', - 'season' => '', - 'episode' => '', - 'seriesfull' => '', - 'airdate' => '', - 'country' => '', - 'year' => '', - 'cleanname' => '' - ); - foreach ($showInfo1 as $k => $v) - if (isset($showinfo[$k])) - $showInfo1[$k] = $showinfo[$k]; - $showinfo = $showInfo1; - echo "calling rage $name\n"; -// var_dump($showinfo); - try { - $tvrShow = $tvrage->getRageMatch($showinfo); -// var_dump($tvrShow); - if (isset($tvrShow["showid"])) - $rageID = $tvrShow["showid"]; -// echo "$rageID \n"; - } catch (Exception $e) { - echo 'Caught exception: ', $e->getMessage(), "\n"; - } - } - if (isset($tvrShow) && $rageID > 0) - $tvrage->updateRageInfo($rageID, $showinfo, $tvrShow, null); - } - -// echo "2 $name\n"; - - if ($rageID == false) - { - $query = "SELECT * FROM releases WHERE ( releases.passwordstatus < 0 AND releases.haspreview < 0 ) AND ID = ".$row['ID']; - $rel = $db->queryOneRow($query); - - if ($rel !== false) - return false; - - $query = "SELECT releasevideo.releaseID FROM releasevideo WHERE releasevideo.releaseID = ".$row['ID']; - $rel = $db->queryOneRow($query); - - if ($rel === false) - return false; - - $query = "SELECT releasefiles.releaseID, releasefiles.`name` FROM releasefiles INNER JOIN releases ON releasefiles.releaseID = releases.ID WHERE releases.ID = ".$row['ID']; - $rel = $db->query($query); - - foreach($rel as $r) - { - $name1 = preg_replace('/(?parseNameEpSeason($name1); - -// var_dump($parsed); - - $rageID = $tvrage->getByTitle($parsed['cleanname']); - - if ($rageID == false) - { - if ($parsed) - $name1 = $parsed['cleanname']; - $sql = sprintf("SELECT rageID from tvrage where (releasetitle = %s or releasetitle = %s)", $db->escapeString($name1), $db->escapeString(str_replace(' and ', ' & ', $name1))); - - $sql = str_replace(" = '", " like '%", $sql); - $sql = str_replace("' or", "%' or", $sql); - $sql = str_replace("')", "%')", $sql); - -// echo "$sql\n"; - - $res = $db->queryOneRow($sql); - if ($res) - $rageID = $res["rageID"]; - } - } - if ($rageID != 0 && $name1 != '') - $name = $name1; - } - - $tmp = $tvrage->getByRageID($rageID); - -// echo "ltvrageid = $rageID\n"; -// var_dump($tmp); - - if (!isset($tmp[0])) - { - - $name = preg_replace('/[\_\.]|bbc|nat.?geo|national.?geographic/i', " ", $name1); -// $name = preg_replace('/(19|20)\d{2}.*$/i', " ", $name); - $name = preg_replace('/\d{1,3} ?of ?\d{1,3}.*$/i', " ", $name); - $name = preg_replace('/^[\]\}\)]|[\[\{\(]/i', "", $name); - $name = trim($name); - -echo "name == $name\n"; - $showinfo = $tvrage->parseNameEpSeason($name); - if (!isset($showinfo['cleanname'])) - $showinfo = array( - 'name' => $name, - 'season' => '', - 'episode' => '', - 'seriesfull' => '', - 'airdate' => '', - 'country' => '', - 'year' => '', - 'cleanname' => $name - ); - - - - try { - $tvrShow = $tvrage->getRageMatch($showinfo); - if (isset($tvrShow["showid"])) - $rageID = $tvrShow["showid"]; - } catch (Exception $e) { - echo 'Caught exception: ', $e->getMessage(), "\n"; - } -// var_dump($tvrShow); - if ($tvrShow === false) - { - $name1 = preg_replace('/(\D+?)( s?\d{1,3}?(?!\d).*?)/iU', '\1', $name); - $showinfo = $tvrage->parseNameEpSeason($name1); - if (!isset($showinfo['cleanname'])) - $showinfo = array( - 'name' => $name1, - 'season' => '', - 'episode' => '', - 'seriesfull' => '', - 'airdate' => '', - 'country' => '', - 'year' => '', - 'cleanname' => $name1 - ); -echo "$name1\n"; - $tvrShow = $tvrage->getRageMatch($showinfo); -// var_dump($tvrShow); - if ($tvrShow !== false) - { - if (isset($tvrShow["showid"])) - $rageID = $tvrShow["showid"]; - } - } - - if (($tvrShow !== false && is_array($tvrShow) && $tvrShow['title'] == $name) || $rageID) - { - $showinfo['name'] = $tvrShow["title"]; - $showinfo['cleanname'] = $tvrShow["title"]; - if ($rageID != 0) - $tvrage->updateRageInfo($rageID, $showinfo, $tvrShow, NULL); - } - $tmp = $tvrage->getByRageID($rageID); - } - - if (isset($tmp[0])) - { -// echo "rageID = $rageID\n"; -// echo "title = ".$tmp[0]['releasetitle']."\n"; -// var_dump($tmp); - - $show = $tvrage->parseNameEpSeason($tmp[0]["releasetitle"]." ".$row['searchname']); -// var_dump($tvrage->getEpisodeInfo($rageID, $show['season'], $show['episode'])); - - $name = matchnames($row['name'], $tmp[0]['releasetitle']." ".$show['seriesfull']); - - $name = findquality ($nfo, $name); - - if (dodbupdate($row['ID'], $cat, $name, $rageID, 'tv')) - { - if (is_array($show) && $show['name'] != '') - { - // $tvrage->updateEpInfo($show, $row['ID']); - } - $ok = $rageID; - } - } - - unset($tvrage); - return $ok; -} - -function cleanname($name) -{ - global $qualities; - - $quality = preg_replace('/(.+?)/iU', "/\.*?(\b\\1\b)\.*?/iU", $qualities); - - do { - $original = $name; -// echo "CN: $name\n"; - $name = preg_replace($quality, " \\1 ", $name); - $name = preg_replace("/\.?(s\d+?e\d+?)\.?/iU", " \\1 ", $name); - $name = preg_replace("/yenc/iU", " ", $name); - $name = preg_replace("/^(\[\d+\].\[.+\].(\[#?a.b.[^\]]+\])*?.)/iU", "", $name); - $name = preg_replace("/\[(?![^\[]+\])|\((?![^\(]+\))|\{(?![^\{]+\})/iU", " ", $name); - $name = preg_replace("/^\(?\?+?\)/iU", " ", $name); - $name = preg_replace("/[\x01-\x1f\_\!\?\[\{\}\]\/\:\|]/iU", " ", $name); - $name = preg_replace("/(?getByRageID($rageID); - unset($tvrage); - - $name1 = $name1[0]["releasetitle"]; - - $name = matchnames($row['name'], $name1); - - echo "doing tv1 ".$name." ".$row['guid']."\n"; - - $ok = dodbupdate($id, $cat, $name, $rageID, 'tv'); - - } else { - -//echo "$name $name1\n"; - - $name = matchnames($row['name'], $name1); - - echo "doing tv2 ".$name." ".$row['guid']."\n"; - -// $matches = preg_split('/(\btitle\:|\bname=)[ \.\_]*?(.*)\r/iU', $nfo, 0, PREG_SPLIT_DELIM_CAPTURE); - -// echo $matches[1]."\n"; - - if (empty($name)) - { - $ok = dodbupdate($id, $cat, ''); - } else { - $ok = dodbupdate($id, $cat, $name); - } - } - return $ok; -} - -function doAmazon ($name, $id, $nfo = "", $q, $region = 'com', $case = false, $nfo ='', $row = '') -{ - global $db; - $s = new Sites(); - $site = $s->get(); - $amazon = new AmazonProductAPI($site->amazonpubkey, $site->amazonprivkey, $site->amazonassociatetag); - $ok = false; - - - try { - switch ($case) - { - case 'upc': - $amaz = $amazon->getItemByUpc(trim($q), $region); - break; - case 'asin': - $amaz = $amazon->getItemByAsin(trim($q), $region); - break; - case 'isbn': - $amaz = $amazon->searchProducts(trim($q), '', "ISBN"); - break; - } - } catch (Exception $e) { - echo 'Caught exception: ', $e->getMessage(), "\n"; - unset($s); - unset($amaz); - unset($amazon); - return $ok; - } - - if (!isset($amaz->Items->Item)) - return $ok; - - $type = $amaz->Items->Item->ItemAttributes->ProductGroup; - - switch ($type) - { - case 'Book': - case 'eBooks': - $new = (string) $amaz->Items->Item->ItemAttributes->Author; - $new = $new . " - ". (string) $amaz->Items->Item->ItemAttributes->Title; - $name = matchnames($name, $new); - - $query = "SELECT ID FROM `bookinfo` WHERE `asin` = '".(string) $amaz->Items->Item->ASIN."'"; - $rel = $db->query($query); - if (count($rel) == 0) - { - $book = new Book(); - $item = array(); - $item["asin"] = (string) $amaz->Items->Item->ASIN; - $item["url"] = (string) $amaz->Items->Item->DetailPageURL; - $item["coverurl"] = (string) $amaz->Items->Item->LargeImage->URL; - if ($item['coverurl'] != "") - $item['cover'] = 1; - else - $item['cover'] = 0; - $item["author"] = (string) $amaz->Items->Item->ItemAttributes->Author; - $item["dewey"] = (string) $amaz->Items->Item->ItemAttributes->DeweyDecimalNumber; - $item["ean"] = (string) $amaz->Items->Item->ItemAttributes->EAN; - $item["isbn"] = (string) $amaz->Items->Item->ItemAttributes->ISBN; - $item["publisher"] = (string) $amaz->Items->Item->ItemAttributes->Publisher; - $item["publishdate"] = (string) $amaz->Items->Item->ItemAttributes->PublicationDate; - $item["pages"] = (string) $amaz->Items->Item->ItemAttributes->NumberOfPages; - $item["title"] = (string) $amaz->Items->Item->ItemAttributes->Title; - $item["review"] = ""; - if (isset($amaz->Items->Item->EditorialReviews)) - $item["review"] = trim(strip_tags((string) $amaz->Items->Item->EditorialReviews->EditorialReview->Content)); - - $bookId = $book->addUpdateBookInfo($item['title'], $item['asin'], $item['url'], - $item['author'], $item['publisher'], $item['publishdate'], $item['review'], - $item['cover'], $item['dewey'], $item['ean'], $item['isbn'], $item['pages'] ); - unset($book); - } else { - $bookId = $rel[0]['ID']; - } - - - $query = "SELECT * FROM releases INNER JOIN releaseaudio ON releases.ID = releaseaudio.releaseID WHERE releases.ID = $id"; - $rel = $db->query($query); - if (count($rel) == 0) - { - $ok = dodbupdate($id, 7020, $name, $bookId, 'book'); - } else { - $ok = dodbupdate($id, 3030, $name, $bookId, 'book'); - } - unset($rel); - break; - - case 'Digital Music Track': - case 'Digital Music Album': - case 'Music': - $new = (string) $amaz->Items->Item->ItemAttributes->Artist; - if ($new != '') - $new = $new . " - "; - $new = $new .(string) $amaz->Items->Item->ItemAttributes->Title; - $name = matchnames($name, $new); - - $query = "SELECT * FROM `bookinfo` WHERE `asin` = '".(string) $amaz->Items->Item->ASIN."'"; - -// echo "$query\n"; - $rel = $db->query($query); - if (count($rel) == 0) - { - $mus = array(); - $mus['coverurl'] = (string) $amaz->Items->Item->LargeImage->URL; - if ($mus['coverurl'] != "") - $mus['cover'] = 1; - else - $mus['cover'] = 0; - - $mus['title'] = (string) $amaz->Items->Item->ItemAttributes->Title; - - $mus['asin'] = (string) $amaz->Items->Item->ASIN; - - $mus['url'] = (string) $amaz->Items->Item->DetailPageURL; - - $mus['salesrank'] = (string) $amaz->Items->Item->SalesRank; - if (empty($mus['salesrank'])) - $mus['salesrank'] = 'null'; - - $mus['artist'] = (string) $amaz->Items->Item->ItemAttributes->Artist; - - $mus['publisher'] = (string) $amaz->Items->Item->ItemAttributes->Publisher; - - $mus['releasedate'] = $db->escapeString((string) $amaz->Items->Item->ItemAttributes->ReleaseDate); - if ($mus['releasedate'] == "''") - $mus['releasedate'] = 'null'; - - $mus['review'] = ''; - if (isset($amaz->Items->Item->EditorialReviews)) - $mus['review'] = trim(strip_tags((string) $amaz->Items->Item->EditorialReviews->EditorialReview->Content)); - - $mus['year'] = ($mus['releasedate'] != 'null' ? substr($mus['releasedate'], 1, 4) : date("Y")); - - $mus['tracks'] = ''; - if (isset($amaz->Items->Item->Tracks)) - { - $tmpTracks = (array) $amaz->Items->Item->Tracks->Disc; - $tracks = $tmpTracks['Track']; - $mus['tracks'] = (is_array($tracks) && !empty($tracks)) ? implode('|', $tracks) : ''; - } - - $music = new Music(); - $musicId = $music->addUpdateMusicInfo($mus['title'], $mus['asin'], $mus['url'], - $mus['salesrank'], $mus['artist'], $mus['publisher'], $mus['releasedate'], $mus['review'], - $mus['year'],'', $mus['tracks'], $mus['cover'] ); - - unset($music); - } else { - $musicId = $rel[0]['ID']; - } - - $ok = dodbupdate($id, 3010, $name, $musicId, 'music'); - break; - - case 'Movies': - case 'DVD': - $new = (string) $amaz->Items->Item->ItemAttributes->Title; - $new = $new . " (" . substr((string) $amaz->Items->Item->ItemAttributes->ReleaseDate, 0, 4) . ")"; - $name = matchnames($name, $new); - - $ok = matchimdb ($nfo, $row); - - if (!$ok) - { - $name = findquality ($nfo, $name); - $ok = dodbupdate($id, 2000, $name); - } - break; - - default: - echo "* * * * * * uncatched amazon category $type ".$name; - break; - } -//echo $query."\n"; - - unset($s); - unset($amaz); - unset($amazon); - return $ok; -} - -function doarray($matches) -{ - $r = array(); - - foreach ($matches as $m) - { - if (strlen($m) < 50) - { - $str = preg_replace("/\s/iU", "", $m); - - $m = strtolower($str); - - if ($m == 'audiobook') { - $r[-1] = $m; - } else if ($m == 'anidb.net') { - $r[-2] = $m; - } else if ($m == 'upc') { - $r[-3] = $m; - } else if ($m == 'amazon.') { - $r[-4] = $m; - } else if ($m == 'asin') { - $r[-5] = $m; - } else if ($m == 'imdb') { - $r[-6] = $m; - } else if ($m == 'os') { - $r[-7] = $m; - } else if ($m == 'mac' || $m == 'macintosh' || $m == 'dmg' || $m == 'macos' || $m == 'macosx' || $m == 'osx') { - $r[-8] = $m; - } else if ($m == 'itunes.apple.com/') { - $r[-9] = $m; - } else if (preg_match('/sports|deportes|nhl|nfl|\bnba/i', $m)) { - $r[1000] = $m; - } else if (preg_match('/avi|xvid|divx|mkv/i', $m)) { - $r[1001] = $m; - } else { - $r[] = $m; - } - } - } - - ksort($r); - return $r; -} - -function doOS ($nfo, $name, $cat, $id) -{ - global $db; - - $ok = false; - - $pattern = '/(.*v(?:er)?[\.\s]*?\d+\.\d(?:\.\d+)??[^\v]*?)|(?getNZBPath($row['guid']); - $m3u = ''; - $alt = ''; - $mp3 = false; - $mp3name = ''; - $files = 0; - $extras = 0; - - echo "doing music ".$row['guid']."\n"; - - if ($nzbinfo->loadFromFile($file)) - { - $name = $row['name']; - - $name = preg_replace("/\//",' ', $name); - -// echo "$name\n"; - - $name = preg_quote($name); - - - echo "$name\n"; - - - foreach($nzbinfo->nzb as $nzbsubject) - { - - $sub = $nzbsubject['subject']."\n"; - - $sub = preg_replace("/$name/i",'', $sub); - -// echo "doing music file = $sub\n"; - - if (preg_match('/\.(vol\d{1,3}?\+\d{1,3}?|par2|nfo\b|sfv|par\b|p\d{1,3}?|sv\b)/iU', $sub)) - { - $extras++; - $alt = preg_replace('/(\.vol\d{1,3}?\+\d{1,3}?|\.par2|\.[a-z][a-z0-9]{2})+?".+?/iU', '', $sub); - } - - if (preg_match('/\.mp3|\.flac/', $sub, $matches)) - { - $mp3name = preg_replace('/(\.mp3".+?)/iU', '.mp3', $sub); - $mp3name = preg_replace('/(\.flac".+?)/iU', '.flac', $sub); - $mp3name = preg_replace('/(?iU)^[^\"]+\"(0\d+?-?(00)??)??/iU', '', $mp3name); - - $mp3 = true; - $files++; - } - - if (preg_match('/\.m3u|\"00+[ \-\_\.]+?|\.nfo\b|\.sfv/iU', $sub, $matches)) - { - if (preg_match('/\.url|playlist/iU', $sub)) - { - continue; - } - $sub = preg_replace('/(\.vol\d{1,3}?\+\d{1,3}?|\.par2|\.[a-z][a-z0-9]{2})+?".+?/iU', '', $sub); - - $m3u = preg_replace('/(?iU)^[^\"]+\"(0\d+?-?(00)??)??/iU', '', $sub); - } - - } - } - $name = ''; - - if ( count($nzbinfo->nzb) > 0) - { - - echo (($m3u != '' || ($files + $extras) / count($nzbinfo->nzb) > 0.7) && $mp3)." ".$mp3." ".$m3u."\n"; - - if (($m3u != '' || (($files + $extras) / count($nzbinfo->nzb) > 0.7)) && $mp3) - { - $name = $m3u; - - if ($files == 1) - $name = $mp3name; - - if (empty($name)) - { - $name = matchnames($row['name'], $alt); - } - - echo $row['guid']." ".$name.' '.$mp3.' '.($files + $extras) / count($nzbinfo->nzb)."\n"; - - } - - echo (($m3u != '' || ($files + $extras) / count($nzbinfo->nzb) > 0.7) && $mp3)." ".$mp3." ".$m3u."\n"; - - } - -echo "music files $name\n"; - $name = cleanname($name); -echo "cleaned name $name\n"; - unset($file); - - unset($nzbinfo); - unset($nzb); - - return $name; -} - -function findquality ($nfo, $name) -{ - global $qualities; - $qual = array(); -// echo "$name\n"; - foreach ($qualities as $quality) - { - if (preg_match("/(?$quality) - { - if (preg_match("/$quality/iU", $name)) - { - unset($qual[$key]); - } - } - - $n = ''; - if (count($qual) > 0) - { - foreach ($qual as $quality) - { - $n = $n ." ".$quality; - } - } - - return trim($name .' '.$n); -} - -function matchanime ($nfo, $id, $name) -{ - $ok = false; - $anime = ''; - - if (preg_match('/anidb.net.*aid=(\d+?)/iU', $nfo, $set)) - { - $anidb = new AniDB(); - if ($anidb->getAnimeInfo($set[1]) === false) - { - $anidb->addTitle($anidb->AniDBAPI($set[1])); - } - $anime = $anidb->getAnimeInfo($set[1]); - - if ($anime !== false) - { - - $anime = matchnames($name, $anime['title']); - - $ok = dodbupdate($id, 5070, $anime, $set[1], 'anime'); - } - unset($anidb); - - } - return $ok; -} - -function matchimdb ($nfo, $row) -{ - $ok = false; - - preg_match('/imdb\.[a-z0-9\.\_\-\/]+?(?:tt|\?)(\d+?)\/?/iU', $nfo, $set); - -// echo "imdb name= ".$row['name']."\n"; - - if (isset($set[1])) - { - $imdb = $set[1] + 0; - - $movie = new Movie(); - - $title = $movie->getMovieInfo($imdb); - - if ($title === false) - { - $movie->fetchImdbProperties($imdb); - $movie->updateMovieInfo($imdb); - $title = $movie->getMovieInfo($imdb); - } - - $name = $title['title']." (".$title['year'].")"; - -// $name = matchnames($row['name'], $name); - - // echo "quality ".findquality ($nfo, $name)."\n"; - $name = findquality ($nfo, $name); - - $name = matchnames($row['name'], $name); - - echo "imdb $name\n"; - -// echo (strval($imdb) + 0) . " * * * " . (strval($title['imdbID']) + 0) ."\n"; - - if ((strval($imdb) + 0) == (strval($title['imdbID']) + 0)) - { - if (preg_match('/sport/iU', $title['genre'])) { - $ok = dodbupdate($row['ID'], 5060, $name, $imdb, 'imdb'); - } else if (preg_match('/docu/iU', $title['genre'])) { - $ok = dodbupdate($row['ID'], 5080, $name, $imdb, 'imdb'); - } else if (preg_match('/talk\-show/iU', $title['genre'])) { - $ok = dodbupdate($row['ID'], 5000, $name, $imdb, 'imdb'); - } else if (preg_match('/tv/iU', $title['genre']) || preg_match('/episode/iU', $title['genre']) || preg_match('/reality/iU', $title['genre'])) { - $ok = updateTV ($title['title']." (".$title['year'].")", $row['ID'], $row, 5000, $nfo); - } else { - $ok = dodbupdate($row['ID'], 2000, $name, $imdb, 'imdb'); - } - } - unset($movie); - } -// echo (bool) $ok."\n"; - return $ok; -} - -function matchaudiobook ($nfo, $id, $oldname, $row) -{ - global $db; - $ok = false; - - if (preg_match('/Sample Rate|MP3|speech|Encoded|ID3|(un)?abridged|Copyright|Ripped|khz|stero|mono/i', $nfo)) - { - if (preg_match('/mpeg|pixels|fps/i', $nfo)) - { - echo "not audio\n"; - return $ok; - } - $query = "SELECT * FROM releases INNER JOIN releasevideo ON releases.ID = releasevideo.releaseID where ( releases.passwordstatus >= 0 OR releases.haspreview >= 0 ) AND releases.ID = ".$id; - $rel = $db->query($query); - if (count($rel) > 0) - { - echo "not audio\n"; - return $ok; - } - unset ($rel); - - echo "audiobooks $id\n"; - $name = $oldname; - $author = ''; - $title = ''; - $bookID = 0; - $set = preg_split('/\btitle\:?(\.\.+?|\s\s+?|__+?)([^\r]*)\r/Ui', $nfo, 0, PREG_SPLIT_DELIM_CAPTURE); - - - if (isset($set[2])) - { - - $set[2] = trim(preg_replace('/[\|\:\-]| +/', ' ', $set[2])); - -// echo $set[2]."\n"; - $name = $set[2]; - $title = $name; - - $set = preg_split('/author\:?(\.\.+?|\s\s+?|__+?)([^\r]*)\r/Ui', $nfo, 0, PREG_SPLIT_DELIM_CAPTURE); - - if (isset($set[2])) - { - $set[2] = trim(preg_replace('/[\|\:\-]| +/', ' ', $set[2])); - -// echo $set[2]."\n"; - $name = $set[2]." - ".$name; - $author = $set[2]; - } - - $bookID = findbookid ($author, $title); -// -// $book = new Book(); -// $rel = $book->getBookInfoByName($author, $title); -// -// if ($rel === false) -// { -// $query = "Select * from `bookinfo` WHERE `title` LIKE '%".$title."%' AND ID in (SELECT ID FROM `bookinfo` WHERE `author` sounds LIKE '".$author."')"; -// $rel = $db->query($query); -// // echo "$query\n"; -// -// if (isset($rel[0]["ID"])) -// { -// // var_dump($rel); -// $bookID = $rel[0]["ID"]; -// } else { -// // echo "not found\n"; -// $bookID = $book->updateBookInfo($author, $title); -// // echo "$bookID\n"; -// } -// } else { -// $bookID = $rel['ID']; -// } - - $name = matchnames($oldname, $name); - if ($bookID > 0) - { - $ok = dodbupdate($id, 3030, $name, $bookID, 'book'); - } else { - $ok = dodbupdate($id, 3030, $name); - } - } else { - $ok = findmusicname($row, 3030); -// $ok = dodbupdate($id, 3030); - } - } -// unset($book); - return $ok; -} - -function matchmusic($nfo, $row) -{ - $artist = $album = ''; - - $artist = preg_split('/(?:a\s?r\s?t\s?i\s?s\s?t\b)+? *?(?!(?:[^ \.\:\}\]\*] ?){2,}?\b)(?:[\*\?\-\=\|\;\:\.\[\}\]\( \xb0-\x{3000}]+?)[ \.\>\:]([a-z0-9]?(?!:).+?(?\:]([a-z0-9]?(?!:).+?(?1 && $title[1] <50 && isset($artist[1]) && strlen($artist[1]) >1 && $artist[1] <50) - { - -// echo "\n * * * * * title= ".$title[1]."\t ".$row['name']."\n"; - if (isset($artist[1])) - { - $new = trim($artist[1]); - $artist1 = trim($artist[1]); - } - - - if (isset($title[1])) - { - if (strlen($new) > 1) - { - $new = $new . " -*- "; - } - $new = $new . trim($title[1]); - $album = trim($title[1]); - } - - $name = matchnames($row['name'], $new); - - $artist = matchnames($artist1, ''); - $album = matchnames($album, ''); - -// echo "$artist * * $album\n"; - } else { - - $name = domusicfiles ($row); - if ($name != "") - { - $result = $music->parseArtist($name); - $artist = $result['artist']; - $album = $result['album']; - } - } - -echo "3artist = $artist album = $album\n"; - - $album = stripname($album); - $artist = stripname($artist); - - - - $tmp = explode(",", $artist); - - if (count($tmp) > 1) - $artist = trim($tmp[1]." ".$tmp[0]); - -echo "4artist = $artist album = $album\n"; - - if ($artist != '' && $album != '') - $musicId = 0; - else { - $rel = $music->getMusicInfoByName($artist, $album); -// var_dump($rel); - $musicId = $rel['ID']; - } - - if ($musicId <= 1) - { - echo "amazon music2 "; - $musicId = $music->updateMusicInfo($artist, $album, 0); - - if ($musicId === false) - { -// var_dump($artist); -// var_dump($album); - $book = new Book(true); - $bookId = $book->updateBookInfo($artist, $album); - unset($book); - } -// var_dump($musicId); - - } - - if ($musicId > 0) - { - $ok = dodbupdate($row['ID'], 3010, $name, $musicId, 'music'); - } else if ($bookId > 0) { - $ok = dodbupdate($row['ID'], 3030, $name, $bookId, 'book'); - } - - if (!$ok) - { - $ok = findmusicname($row, 3010); - -// $name = matchnames($row['name'], domusicfiles($row)); -// $ok = dodbupdate($row['ID'], 3010, ''); - } - if (!$ok) - { - if (preg_match('/book/i', $row['gname'])) - $ok = dodbupdate($row['ID'], 3030, $name); - else - $ok = dodbupdate($row['ID'], 3010, $name); - } - unset($music); - return $ok; -} - -function matchmag($nfo, $row) -{ - $ok = false; - $set = preg_split('/(?:\btitle|\bname|release)\b(?:[\-\:\.\}\[\s\xb0-\x{3000}]+?)\B([a-z0-9\.\- \(\)]+?)/Uui', $nfo, 0, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY); - if (isset($set[1])) - { - $name = trim($set[1]); - if (preg_match('/(?:issue)\b(?:[\-\:\.\}\[\s\xb0-\x{3000}]+?)\B([a-z0-9\.\- \(\)\/]+?)/iuU', $nfo, $set)) - { - if (isset($set[1])) - { - $name = $name." ".trim($set[1]); - } - $name = matchnames($row['name'], $name); - $ok = dodbupdate($row['ID'], 7010, $name ); - } - } - return $ok; -} - -function dodbupdate($id, $cat, $name = '', $typeid = 0, $type='none', $debug = DEBUGGING) -{ - global $db; - - $query = "UPDATE `releases` SET `categoryID` = $cat"; - - if ($name != '') - $query = $query.", `searchname` = ".$db->escapeString($name); - switch ($type) { - case 'imdb': - if ($typeid != 0) - $query = $query.", `imdbID` = $typeid"; - break; - case 'book': - if ($typeid != 0) - $query = $query.", `bookinfoID` = $typeid"; - break; - case 'music': - if ($typeid != 0) - $query = $query.", `musicinfoID` = $typeid"; - break; - case 'anime': - if ($typeid != 0) - $query = $query.", `anidbID` = $typeid"; - break; - case 'tv': - if ($typeid != 0) - $query = $query.", `rageID` = $typeid"; - break; - default: - break; - } - - $query = $query." where `ID` = $id"; -echo $debug." ".$query."\n"; - if (!$debug) - { -echo "updating"; - if ($db->query($query) !== false) - return true; - } else { - return true; - } - return false; -} - -function findmovie($name) -{ - $imdb = 0; - - $j = 0; - - $name = stripname($name); - - $url = "http://www.omdbapi.com/?r=xml&s="; - $name1 = $name; - if (preg_match('/([^\[\r\]]+)[\[\{\(\_\. ]+?((?:19|20)\d{2})/U', $name, $title)) - { - $url = $url.urlencode($title[1])."&y=".$title[2]; - $name1 = $title[1]." ".$title[2]; - } - else - $url = $url.urlencode($name); - -echo "omdbapi: $url\n"; -echo cleanname($name1)."\n"; - - $data = getUrl($url); - -//echo "$data\n"; - $xmlObj = @simplexml_load_string(html_entity_decode($data)); - $arrXml = objectsIntoArray($xmlObj); - -// var_dump($arrXml); - - if (isset($arrXml["Movie"])) - { - - $tvrage = new TVRage(true); - - $name1 = ''; - - foreach ($arrXml["Movie"] as $ax) - { -// var_dump($ax); - - if (isset($ax["@attributes"])) - $a = $ax["@attributes"]; - else - $a = $ax; - if (isset($title[2]) && $a["Year"] == $title[2]) - { - $i = 0; - $a["Title"] = preg_replace('/&/', ' and ', $a["Title"]); - $name = preg_replace('/&/', ' and ', $name); - -//echo "matched ".$a["Title"]."\n"; - - $arr = preg_split('/[\:\:\.\, \-\_\(\)\[\]\{\}]/', $a["Title"], 0, PREG_SPLIT_NO_EMPTY); - foreach ($arr as $r) - { -echo preg_quote($r)."\n"; - $r = str_replace("/", " ", $r); - $r = str_replace("\\", " ", $r); - if (preg_match('/'.preg_quote($r).'/i', $name)) - $i++; - } - if (count($arr) == $i && $i > $j) - { - $name1 = $name; - $imdb = $a["imdbID"]; - $j = $i; - } -// echo "comp result ".count($arr)." ".$i." ".$name."\n"; -// echo $a["Title"]."\n"; - } - } - echo "$name1 $imdb\n"; - - unset($tvrage); - } - echo "findmovie = $imdb\n"; - - return array(strval($imdb), $j); -} - -function matchvideo($row, $nfo) -{ - global $db; - - $ok = false; - - $imdb = ''; - - $j = 0; - - $query = "SELECT releasevideo.releaseID FROM releasevideo WHERE releasevideo.releaseID = ".$row['ID']; - $rel = $db->queryOneRow($query); - - if ($rel === false) - { - $query = "SELECT releasefiles.`name`, releasefiles.releaseID, releasefiles.size FROM releasefiles WHERE releasefiles.releaseID = ".$row['ID']; - $res = $db->queryDirect($query); - - $cont = false; - while ($rel = $db->getAssocArray($res)) - { - if(preg_match('/\.(iso|mkv|mp4|iso|divx)$|\.([^\.]+)$/', $rel['name'], $ext)) - { - echo "ext = ".$ext[1]." ".$row['guid']."\n"; - var_dump($ext); - $cont = true; - } - } - if (!$cont) - return false; - } - $thename = $name = $row['name']; -echo "name1: $name\n"; - $rageID = lookupTV ($name, $nfo, $row, 5000); - - if ($rageID == 0) - { - $imdb = findmovie($name); - $imdb = $imdb[0]; - } - - if ($rageID == 0 && empty($imdb) ) - { - $set = preg_split('/(?:\btitle|\bname).+[\.\s]+?[^a-z0-9]*?([a-z0-9\-\.\_ ]+?)/iU', $nfo, 0, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY); -//var_dump($set); - if (isset($set[1])) - { -echo "name2: ".$set[1]."\n"; - $rageID = lookupTV ($set[1], $nfo, $row, 5000); - if ($rageID) - { - $thename = $set[1]; - } else - { - $imdb = findmovie($set[1]); - $imdb = $imdb[0]; - } - - } - - if ($rageID == 0 && empty($imdb) ) - { - $query = "SELECT releasefiles.releaseID, releasefiles.`name` FROM releasefiles INNER JOIN releases ON releasefiles.releaseID = releases.ID WHERE releases.ID = ".$row['ID']; - $rel = $db->query($query); - - $ok = false; - $j = 0; - - - if (count($rel) > 0) - { - foreach($rel as $r) - { - $name1 = preg_replace('/video[\_\. ]ts/iU', ' ', $r['name']); - - $name1 = preg_replace('/\\\\/', ' ', $name1); - - $name1 = preg_replace('/\.[a-z][a-z0-9]{2}$/iU', '', $name1); - - $name1 = preg_replace('/ +/', ' ', $name1); - - $name1 = preg_replace('/^ | $/', '', $name1); - - echo "file ".$name1."\n"; -echo "name3: $name1\n"; - $rageID = lookupTV ($name1, $nfo, $row, 5000); - - if ($rageID && $j == 0) - { - $thename = $name1; - break; - } else { - $tmp = findmovie($name1); -// var_dump($tmp); - if ($tmp[1] > $j) - { - echo "$rageID\n"; - $imdb = $tmp[0]; - $j = $tmp[1]; - $thename = $name1; - } - } - - } - } - } - } -echo "$j $rageID $imdb\n"; - - if ($imdb != '') - { - $imdb = preg_replace('/^tt/', '', $imdb); - $movie = new Movie(); - $tmp = $movie->getMovieInfo($imdb); - - if ($tmp === false) - { - $movie->fetchImdbProperties($imdb); - $movie->updateMovieInfo($imdb); - $tmp = $movie->getMovieInfo($imdb); - } - - - $thename = matchnames($row['name'], $thename); - $thename = matchnames($thename, $tmp['title']); - $thename = findquality ($nfo, $thename); - - unset($movie); - -echo "$thename\t"; -// var_dump($tmp); - - if (isset($tmp['ID'])) - { - if (preg_match('/sport/iU', $tmp['genre'])) { - $ok = dodbupdate($row['ID'], 5060, $thename, $imdb, 'imdb'); - } else if (preg_match('/docu/iU', $tmp['genre'])) { - $ok = dodbupdate($row['ID'], 5080, $thename, $imdb, 'imdb'); - } else if (preg_match('/talk\-show/iU', $tmp['genre'])) { - $ok = dodbupdate($row['ID'], 5000, $thename, $imdb, 'imdb'); - } else if (preg_match('/tv/iU', $tmp['genre']) || preg_match('/episode/iU', $tmp['genre']) || preg_match('/reality/iU', $tmp['genre'])) { - $ok = updateTV ($tmp['title']." (".$tmp['year'].")", $row['ID'], $row, 5000, $nfo); - } else { - $ok = dodbupdate($row['ID'], 2000, $thename, $imdb, 'imdb'); - } - } - - - } - - if ($rageID) - { - $tvrage = new TVRage(true); - $tmp = $tvrage->getByRageID($rageID); - $thename = matchnames($row['name'], $thename); - $thename = matchnames($thename, $tmp[0]['releasetitle']); - $thename = findquality ($nfo, $thename); - - $name = $tmp[0]['releasetitle']; - - // $tmp = $tvrage->getByRageID($rageID); - - unset($tvrage); -// var_dump($tmp); -echo "doing updates"; - if (isset($tmp[0])) - { - if (preg_match('/sports/i', $tmp[0]['genre'])) - $ok = dodbupdate($row['ID'], 5060, $thename, $rageID, 'tv'); - elseif (preg_match('/documen/i', $tmp[0]['genre'])) - $ok = dodbupdate($row['ID'], 5080, $thename, $rageID, 'tv'); - else - $ok = dodbupdate($row['ID'], 5000, $thename, $rageID, 'tv'); - } - } - - if ($rageID == 0 && empty($imdb) ) - { - $thename = matchnames($row['name'], $thename); - $thename = findquality ($nfo, $thename); - - if (preg_match('/sport/i', $row['gname'])) - $ok = dodbupdate($row['ID'], 5060, $thename); - elseif (preg_match('/docu/i', $row['gname'])) - $ok = dodbupdate($row['ID'], 5080, $thename); - elseif (preg_match('/tv/i', $row['gname'])) - $ok = dodbupdate($row['ID'], 5000, $thename); - elseif (preg_match('/mov/i', $row['gname'])) - $ok = dodbupdate($row['ID'], 2000, $thename); - else - $ok = dodbupdate($row['ID'], 5050, $thename); - } - - return $ok; -} - - -echo "starting\n"; -$db = new DB(); - -$res = $db->query("SET NAMES 'utf8'"); -$res = $db->query("SET CHARACTER SET 'utf8'"); - -//mysql_query("SET NAMES 'utf8'"); -//mysql_query("SET CHARACTER SET 'utf8'"); -mb_internal_encoding("UTF-8"); -mb_regex_encoding("UTF-8"); -mb_http_output("UTF-8"); -mb_language("uni"); - -$query = "SELECT ID FROM category WHERE parentID = 8000"; // OR parentID = 2000 OR parentID = 5000 - -$res = $db->query($query); - -$thecategory = $res[0]['ID']; - -unset($res[0]); - -foreach($res as $r) - $thecategory = $thecategory.", ".$r['ID']; - -if (isset($argv[1])) -{ - $query = "SELECT uncompress(releasenfo.nfo) AS nfo, releases.ID, releases.guid, releases.`name`, releases.searchname, groups.`name` AS gname FROM releasenfo INNER JOIN releases ON releasenfo.releaseID = releases.ID INNER JOIN groups ON releases.groupID = groups.ID WHERE releases.ID = ".$argv[1]; -} else { - $query = "SELECT uncompress(releasenfo.nfo) AS nfo, releases.ID, releases.guid, releases.`name`, releases.searchname, groups.`name` AS gname FROM releasenfo INNER JOIN releases ON releasenfo.releaseID = releases.ID INNER JOIN groups ON releases.groupID = groups.ID WHERE releases.categoryID IN ( $thecategory )"; -} -//$query = "SELECT uncompress(releasenfo.nfo) AS nfo, releases.ID, releases.guid, releases.`name`, releases.searchname, groups.`name` AS gname FROM releasenfo INNER JOIN releases ON releasenfo.releaseID = releases.ID INNER JOIN groups ON releases.groupID = groups.ID"; -//$query = "SELECT uncompress(releasenfo.nfo) AS nfo, releases.ID, releases.guid, releases.`name`, releases.searchname, groups.`name` AS gname FROM releasenfo INNER JOIN releases ON releasenfo.releaseID = releases.ID INNER JOIN groups ON releases.groupID = groups.ID WHERE releases.guid = '6dc77dc7fb48745ee76ec345c4fe789b'"; -// -//echo $query."\n"; - -$res = $db->queryDirect($query); - -echo "got matches\n"; - -while ($row = $db->getAssocArray($res)) -{ - $nfo = utf8_decode($row['nfo']); - if (strlen($nfo) > 0) - { -// trigger_error("doing nfo ".$row['ID']." ".$row['name']); - - $pattern = '/(imdb)\.[a-z0-9\.\_\-\/]+?(tt|\?)(\d+?)\/?|(tvrage)|(\bASIN)|(isbn)|(UPC\b)|(comic book)|(comix)|(tv series)|(\bos\b)|(documentaries)|(documentary)|(doku)|(macintosh)|(dmg)|(mac[ _\.\-]??os[ _\.\-]??x??)|(\bos\b\s??x??)|(\bosx\b)'; - $pattern = $pattern . '|(\bios\b)|(iphone)|(ipad)|(ipod)|(pdtv)|(hdtv)|(video streams)|(movie)|(audiobook)|(audible)|(recorded books)|(spoken book)|(speech)|(read by)\:?|(narrator)\:?|(narrated by)'; - $pattern = $pattern . '|(dvd)|(ntsc)|(m4v)|(mov\b)|(avi\b)|(xvid)|(divx)|(mkv)|(amazon\.)[a-z]{2,3}.*\/dp\/|(anidb.net).*aid=|(\blame\b)|(\btrack)|(t r a c k)|(music)|(44.1kHz)|type:(game)|(game) Type|(platform)|\b(win(?:dows|all|xp)\b)|(\bwin\b)'; - $pattern = $pattern . '|(m3u)|(flac\b)|(application)|(plugin)|(\bcrack)|(install)|(setup)|(magazin)|(x264)|(itunes\.apple\.com\/)|(sports)|(deportes)|(nhl)|(nfl)|(\bnba)|(ncaa)|(album)|(epub)|(mobi)/iU'; - - $matches = preg_split($pattern, $nfo, -1, PREG_SPLIT_NO_EMPTY|PREG_SPLIT_DELIM_CAPTURE); - - $matches = doarray($matches); - - if (count($matches) > 0) - { - // var_dump($matches); - } - - - foreach($matches as $m) - { - if (isset($m)) { - $case = preg_replace('/ /', '', $m); - } else { - $case = ''; - } - if ($row['name'] == '4d5bdbf0da623fb9cf849b8b745c60e9') - print_r($matches); - - if (($m == 'os' || $m == 'platform') && preg_match('/(?:\bos\b(?: type)??|platform)[ \.\:\}]+(\w+?).??(\w*?)/iU', $nfo, $set)) - { - - if (isset($set[1])) - { - // var_dump($set); - $case = strtolower($set[1]); - } - if (strlen($set[2]) && (stripos($set[2], 'mac') !== false || stripos($set[2], 'osx') !== false)) - { - $case = strtolower($set[2]); - } - } - - - echo "\n".$case." ".$row['guid']."\n"; - // echo $row['name']."\n"; - // echo $row['searchname']."\n"; - echo "$case ".$row['guid']."\n"; - - switch (strtolower($case)) - { - case 'itunes.apple.com/': - echo $row['guid']."\n"; - preg_match('/itunes\.apple\.com\/(.*)/iU', $nfo, $set); - echo 'itunes.apple.com'.$set[1]."\n"; - break; - - case 'imdb': - if (matchimdb($nfo, $row)) - break(2); - break; - - - case "asin": - case "isbn": - case "amazon.": - case "upc": - if ($case == 'asin' || $case == 'isbn') - { - preg_match('/(?:isbn|asin)[ \:]*? *?([a-zA-Z0-9\-\.]{8,20}?)/iU', $nfo, $set); - var_dump($set); - if (isset($set[1])) - { - $set[1] = preg_replace('/[\-\.]/', '', $set[1]); - echo "asin ".$set[1]."\n"; - if (strlen($set[1])>13) - break; - if (isset($set[1])) - { - $set[2] = $set[1]; - $set[1] = "com"; - } - } - } else if ($case == 'amazon.') { - preg_match('/amazon\.([a-z]*?\.?[a-z]{2,3}?)\/.*\/dp\/([a-zA-Z0-9]{8,10}?)/iU', $nfo, $set); - } else if ($case == 'upc') { - preg_match('/UPC\:?? *?([a-zA-Z0-9]*?)/iU', $nfo, $set); - if (isset($set[1])) - { - $set[2] = $set[1]; - $set[1] = "All"; - } - } else { - echo "* * * * * error in amazon"; - break; - } - - if (count($set) > 1) - { - if (doAmazon ($row['name'], $row['ID'], $nfo, $set[2], $set[1], $case, $nfo, $row)) - { - break(2); - } - } - break; - case 'comicbook': - case 'comix': - if (dodbupdate($row['ID'], 7030)) - break(2); - break; - case 'audiobook': - case 'audible': - case 'recordedbooks': - case 'spokenbook': - case 'readby': - case 'narratedby': - case 'narrator': - case 'speech': - if (matchaudiobook ($nfo, $row['ID'], $row['name'], $row)) - break(2); - break; - - case 't r a c k': - case 'track': - case 'lame': - case 'album': - case 'music': - case '44.1kHz': - case 'm3u': - case 'flac': - if (preg_match('/(a\s?r\s?t\s?i\s?s\s?t|l\s?a\s?b\s?e\s?l|mp3|e\s?n\s?c\s?o\s?d\s?e\s?r|rip|stereo|mono)/i', $nfo)) - { - if (!preg_match('/(\bavi\b|x\.?264|divx|mvk|xvid|install|Setup\.exe|unzip|unrar)/i', $nfo)) - { - if (matchmusic($nfo, $row)) - { - // echo "breaking 2\n"; - break(2); - } - } else { - // echo "$case ".$row['guid']."\n"; - if (findmusicname($row, 3010)) - break (2); - } - } - break; - - case 'magazin': - // echo "magazin\n"; - if (matchmag($nfo, $row)) - break(2); - break; - - case 'dmg': - case 'mac': - case 'macintosh': - case 'macos': - case 'macosx': - case 'osx': - if (doOS($nfo, $row['name'], 4030, $row['ID'])) - break(2); - break; - - case 'ios': - case 'iphone': - case 'ipad': - case 'ipod': - - if (doOS($nfo, $row['name'], 4060, $row['ID'])) - break(2); - break; - - case 'application': - case 'install': - case 'setup': - if (!preg_match('/(Setup(\.exe)?|unzip|unrar)/i', $nfo)) - continue; - if (preg_match('/(\bavi\b|x\.?264|divx|mvk|xvid|install)/i', $nfo)) - continue; - - case 'windows': - case 'win': - case 'winall': - case 'winxp': - case 'plugin': - case 'crack': - if (doOS($nfo, $row['name'], 4020, $row['ID'])) - break(2); - break; - - case 'android': - if (doOS($nfo, $row['name'], 4070, $row['ID'])) - break(2); - break; - - case 'game': - $set = preg_split('/\>(.*)\queryDirect($query); - -echo "doing part 2\n"; - -while ($row = $db->getAssocArray($res)) -{ -// trigger_error("doing part 2".$row['ID']); - $query = "SELECT releasevideo.releaseID FROM releasevideo WHERE releasevideo.releaseID = ".$row['ID']; - $rel = $db->queryOneRow($query); - - if ($rel !== false) - continue; - - echo "\n".$row['guid']."\n"; - - $query = 'SELECT releasenfo.releaseID, uncompress(releasenfo.nfo) AS nfo FROM releasenfo WHERE releasenfo.releaseID = '.$row['ID']; - $rel = $db->queryOneRow($query); - - $nfo = ''; - if ($rel !== false) - if ($rel['releaseID'] == $row['ID']) - $nfo = $rel['nfo']; - - matchmusic($nfo, $row); - //findmusicname($row, 3010); -} - -if (isset($argv[1])) -{ - $query = "SELECT releasefiles.`name` AS rname, releasefiles.size, releases.*, groups.`name` AS gname FROM releasefiles INNER JOIN releases ON releasefiles.releaseID = releases.ID INNER JOIN groups ON releases.groupID = groups.ID WHERE releases.ID = ".$argv[1]." ORDER BY releasefiles.releaseID, releasefiles.`name`"; -} else { - $query = "SELECT releasefiles.`name` AS rname, releasefiles.size, releases.*, groups.`name` AS gname FROM releasefiles INNER JOIN releases ON releasefiles.releaseID = releases.ID INNER JOIN groups ON releases.groupID = groups.ID WHERE releases.categoryID IN ( $thecategory ) ORDER BY releasefiles.releaseID, releasefiles.`name`"; -} - -$res = $db->queryDirect($query); - -echo "doing part 3\n"; - -while ($row = $db->getAssocArray($res)) -{ -// trigger_error("doing part 3".$row['ID']); - if(preg_match('/\.([^\.]{3,4})$/', $row['rname'], $ext)) - { - $ext[1] = strtolower($ext[1]); - - echo "ext = ".$ext[1]." ".$row['guid']."\n"; -// var_dump($ext); - switch ($ext[1]) - { - case 'epub': - case 'mobi': - $title = preg_split("/ \- /", $row['rname']); - $author = preg_replace('/(\.[^\.]+)/', '', $title[1]); - - $tmp = preg_replace('/'.$row['name'].'/', '', $title[0]); - $tmp = preg_split('/\\\\/', $tmp, 0, PREG_SPLIT_NO_EMPTY); - - - - echo "author: ".$author." title: ".$tmp[count($tmp)-1]."\n"; - - $bookId = findbookid ($author, $tmp[count($tmp)-1]); - - $title1 = $tmp[count($tmp)-1]; - - echo $bookId."\n"; - - if ($bookId == 0) - { - $bookId = findbookid ($tmp[count($tmp)-1], $author); - echo "inverse ".$bookId."\n"; - - $title1 = $author; - $author = $tmp[count($tmp)-1]; - - } - - $title1 = matchnames($row['name'], $author.' - '.$title1); - - if ($bookId != 0) - $ok = dodbupdate($row['ID'], 7020, $title1, $bookId, 'book'); - else - $ok = dodbupdate($row['ID'], 7020, $title1); - - - case 'avi': - case 'mkv': - case 'mp4': - case 'iso': - case 'wmv': - case 'mpg': - case 'mov': - case 'm4v': - $tmp = preg_replace("/([^\\\\]+?)\\\\(\\1)/", "\\2", $row['rname']); - $tmp = str_replace('/', ' ', $tmp); - $tmp = preg_replace("/".preg_quote($row['name'])."/", "", $tmp); - $tmp = preg_replace("/\\\\/", " ", $tmp); - $tmp = stripname($tmp); - - $tvrage = new TVRage(true); - $parsed = $tvrage->parseNameEpSeason($tmp); - - unset($tvrage); - echo "name = ".$tmp."\n"; - - $nfo = $tmp."\n"; - - var_dump($parsed); - - matchvideo($row, $nfo); - - break; - - - default: - break; - } - - } - -} - -echo "all done\n"; - -unset($res); -unset($row); -unset($matches); - -if (!isset($argv[1])) -{ - $movie = new Movie(); - $movie->processMovieReleases(); - $movie->updateUpcoming(); - - $music = new Music(true); - $music->processMusicReleases(); - - $book = new Book(true); - $book->processBookReleases(); - - $anidb = new AniDB(true); - $anidb->animetitlesUpdate(); - $anidb->processAnimeReleases(); - - $tvrage = new TVRage(true); - $tvrage->processTvReleases(true); - - $thetvdb = new TheTVDB(true); - $thetvdb->processReleases(); - - echo "cleaning 5000\n"; - - $query = "update releases set releases.categoryID= 5060 WHERE imdbID IN ( SELECT movieinfo.imdbID FROM movieinfo WHERE movieinfo.genre REGEXP 'sport' AND NOT movieinfo.genre REGEXP 'comedy' AND NOT movieinfo.genre REGEXP 'romance' AND NOT movieinfo.genre REGEXP 'drama' )"; - - $db->query($query); - - $query = "update releases set releases.categoryID= 5000 WHERE imdbID IN ( SELECT movieinfo.imdbID FROM movieinfo WHERE genre REGEXP 'tv|talk\-show|reality|episode' ) AND categoryID NOT IN ( SELECT ID FROM category WHERE parentID = 5000 )"; - - $db->query($query); - - $query = "UPDATE `releases` SET `categoryID`=2050 WHERE (`categoryID` in (SELECT ID FROM category WHERE parentID = 8000 and `imdbID` > 0) OR `categoryID` = 2000) AND size > 10500000000"; - - $db->query($query); - - $query = "UPDATE `releases` SET `categoryID`=2040 WHERE (`categoryID` in (SELECT ID FROM category WHERE parentID = 8000 and `imdbID` > 0) OR `categoryID` = 2000) AND size > 2500000000"; - - $db->query($query); - - $query = "UPDATE `releases` SET `categoryID`=2030 WHERE (`categoryID` in (SELECT ID FROM category WHERE parentID = 8000 and `imdbID` > 0) OR `categoryID` = 2000) AND size > 500000000"; - - $db->query($query); - - $query = "UPDATE `releases` SET `categoryID`=2020 WHERE (`categoryID` in (SELECT ID FROM category WHERE parentID = 8000 and `imdbID` > 0) OR `categoryID` = 2000)"; - - $db->query($query); - - $query = "UPDATE `releases` SET `categoryID`=2040 WHERE `categoryID` = 2050 AND size <10000000000"; - - $db->query($query); - - $query = "UPDATE `releases` SET `categoryID`=2030 WHERE `categoryID` = 2040 AND size < 2500000000"; - - $db->query($query); - - $query = "UPDATE `releases` SET `categoryID`=5040 WHERE (`categoryID` in (SELECT ID FROM category WHERE parentID = 8000 and `rageID` > 0) OR `categoryID` = 5000) AND size > 1500000000"; - - $db->query($query); - - $query = "UPDATE `releases` SET `categoryID`=5030 WHERE (`categoryID` in (SELECT ID FROM category WHERE parentID = 8000 and `rageID` > 0) OR `categoryID` = 5000) AND size > 10000000"; - - $db->query($query); - - $query = "UPDATE `releases` SET `categoryID`=5050 WHERE (`categoryID` in (SELECT ID FROM category WHERE parentID = 8000 and `rageID` > 0) OR `categoryID` = 5000)"; - - $db->query($query); - - $query = "UPDATE `releases` SET `categoryID`=5030 WHERE `categoryID` = 5040 AND size < 1500000000"; - - $db->query($query); - - $query = "UPDATE `releases` SET `categoryID`=5050 WHERE `categoryID` = 5030 AND size < 1000000"; - - $db->query($query); - - $query = "UPDATE releases SET categoryID = 5070 WHERE rageID IN ( SELECT tvrage.rageID FROM tvrage WHERE tvrage.genre REGEXP 'animat' )"; - - $db->query($query); - - $query = "update releases set releases.categoryID= 5080 WHERE imdbID IN ( SELECT movieinfo.imdbID FROM movieinfo WHERE genre REGEXP 'docum' )"; - - $db->query($query); - -} -//ALTER TABLE `movieinfo` CHANGE `genre` `genre` VARCHAR( 256 ) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL - -?> \ No newline at end of file + 1) + $author = trim($tmp[1]." ".$tmp[0]); + + $rel = $book->getBookInfoByName($author, $title); + + echo "book1 "; + var_dump($rel); + + if ($rel === false) + { + $query = "Select * from `bookinfo` WHERE `title` LIKE '%".$title."%' AND ID in (SELECT ID FROM `bookinfo` WHERE `author` sounds LIKE '".$author."')"; + $rel = $db->query($query); + + echo "book2 "; + var_dump($rel); + + if (isset($rel[0]["ID"])) + { + $bookID = $rel[0]["ID"]; + } else { + + $bookID = $book->updateBookInfo($author, $title); + } + } else { + $bookID = $rel['ID']; + } + unset($book); + echo "book ".$bookID."\n"; + return $bookID; +} + + +function findmusicname($row, $cat = 3010) +{ + global $db; + $ok = false; + + $query = "SELECT * FROM releases WHERE ( releases.passwordstatus < 0 AND releases.haspreview < 0 ) AND ID = ".$row['ID']; + $rel = $db->queryOneRow($query); + + if ($rel !== false) + return false; + + $query = "SELECT releasevideo.releaseID FROM releasevideo WHERE releasevideo.releaseID = ".$row['ID']; + $rel = $db->queryOneRow($query); + + if ($rel !== false) + return false; + + $query = "SELECT releasefiles.releaseID, releasefiles.`name` FROM releasefiles INNER JOIN releases ON releasefiles.releaseID = releases.ID WHERE releases.ID = ".$row['ID']." order by releasefiles.`name`"; + $rel = $db->query($query); + + $name = ''; + $ok = false; + + $m3u = ''; + $alt = ''; + $mp3 = false; + $mp3name = ''; + $files = 0; + $extras = 0; + $folder = ''; + $bookId = 0; + $musicId = 0; + + if (count($rel) > 0) + { + echo "findmusicname ".$row['ID']." ".count($rel)."\n"; + foreach($rel as $r) + { + $sub = $r['name']."\n"; + + $sub = preg_replace('/[\x01-\x1f]/', '', $sub); + + $sub = preg_replace('/(? 0.7) && $mp3)." ".$mp3." ".$m3u."\n"; + + if (($m3u != '' || (($files + $extras) / count($rel) > 0.7)) && $mp3) + { + $name = $m3u; + + if ($files == 1) + $name = $mp3name; + + if (empty($name)) + { + $name = matchnames($row['name'], $alt); + } + + echo $row['guid']." ".$name.' '.$mp3.' '.($files + $extras) / count($rel)."\n"; + } + + + // if (preg_match('/\.mp3|\.m3u|\.sfv|\.nfo|\.flac/|\.asf/', $r['name'])) + // echo "release file ".$r['name']."\n"; + + $name = preg_replace("/^\d+\-/i", '', $name); + $name = trim(preg_replace("/\\\\|^ +| +$/i", ' ', $name)); + +echo "file name $name\n"; + + } else { + $name = domusicfiles ($row); + } + +echo "found name $name\n"; + + if ($name != '') + { + $music = new Music(); + $result = $music->parseArtist($name); + $artist = $result['artist']; + $album = $result['album']; + + if (empty($album) && empty($artist)) + $album = $name; + +echo "1artist = $artist album = $album\n"; + + $album = stripname($album); + $artist = stripname($artist); + + $artist = preg_replace('/\d+/', '', $artist); + + $tmp = explode(",", $artist); + + if (count($tmp) > 1) + $artist = trim($tmp[1]." ".$tmp[0]); + + +echo "2artist = $artist album = $album\n"; + + $rel = $music->getMusicInfoByName($artist, $album); +// var_dump($rel); + $musicId = $rel['ID']; + + if ($musicId <= 1) + { + echo "amazon music1 "; + $musicId = $music->updateMusicInfo($artist, $album, 0); + + if ($musicId === false) + { +// $book = new Book(true); +// $bookId = $book->updateBookInfo($artist, $album); +// unset($book); + $bookId = findbookid ($artist, $album); + } +//var_dump($musicId); + } + +if (preg_match('/\.flac/', $mp3name)) + $cat = 3040; + +echo "music name: $name $musicId $bookId\n"; + if ($musicId > 1) + { + $ok = dodbupdate($row['ID'], $cat, $name, $musicId, 'music'); + } else if ($bookId > 0) { + $ok = dodbupdate($row['ID'], 3030, $name, $bookId, 'book'); + } else { + if (preg_match('/book/i', $row['gname'])) + $ok = dodbupdate($row['ID'], 3030, $name); + else + $ok = dodbupdate($row['ID'], $cat, $name); + } + + unset($music); + } + return $ok; +} + +function stripname($name) +{ + if (is_array($name)) + return $name; + + global $qualities; + + $quality = preg_replace('/(.+?)/iU', "/\b\\1\b.*?$/iU", $qualities); + +// var_dump($quality); + + $name1 = $name; + + do { + $original = $name1; +// echo "fm1: $name1\n"; + $name1 = preg_replace($quality, " ", $name1); + $name1 = preg_replace('/(as )?(requested|request|req):?/i', " ", $name1); + $name1 = preg_replace('/Thanks To Original Poster/i', " ", $name1); + $name1 = preg_replace('/\b[a-z]{1,2}[0-9]{1,2} /i', " ", $name1); + $name1 = preg_replace('/^\d+|\d+$/', '', $name1); + $name1 = preg_replace('/\battn:? [^ ]+\b/i', " ", $name1); + $name1 = preg_replace('/^National.?Geographic|^nat.?geo|^bbc/i', " ", $name1); + $name1 = preg_replace("/\.?(s\d+?e\d+?)\.?/iU", " \\1 ", $name1); + $name1 = preg_replace("/^(\[\d+\].\[.+\].(\[#?a.b.[^\]]+\])*?.)/iU", "", $name1); + $name1 = preg_replace("/\[(?![^\[]+\])|\((?![^\(]+\))|\{(?![^\{]+\})/iU", " ", $name1); + $name1 = preg_replace("/^\(?\?+?\)/iU", " ", $name1); + $name1 = preg_replace("/[\x01-\x1f\_\!\?\[\{\}\]\/\:\|]/iU", " ", $name1); + $name1 = preg_replace("/(?parseNameEpSeason($name); + + if (empty($showinfo['cleanname'])) + { + $showinfo['name'] = $name; + $showinfo['cleanname'] = $name; + } + +echo "clean ".$showinfo['cleanname']."\n"; + + $rageID = $tvrage->getByTitle($showinfo['cleanname']); + + } + +// echo "1 $name\n"; + + if ($rageID == false) + { + $rageID = $tvrage->parseRageIdFromNfo($nfo); + + $name1 = $tvrage->getRageInfoFromService($rageID); +// var_dump($name1); + if (isset($name1['name']) && $name1['name'] != '') + $name = $name1['name']; + else + { + if (!isset($showinfo['cleanname'])) + $showinfo = $tvrage->parseNameEpSeason($name); + $showInfo1 = array( + 'name' => '', + 'season' => '', + 'episode' => '', + 'seriesfull' => '', + 'airdate' => '', + 'country' => '', + 'year' => '', + 'cleanname' => '' + ); + foreach ($showInfo1 as $k => $v) + if (isset($showinfo[$k])) + $showInfo1[$k] = $showinfo[$k]; + $showinfo = $showInfo1; + echo "calling rage $name\n"; +// var_dump($showinfo); + try { + $tvrShow = $tvrage->getRageMatch($showinfo); +// var_dump($tvrShow); + if (isset($tvrShow["showid"])) + $rageID = $tvrShow["showid"]; +// echo "$rageID \n"; + } catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; + } + } + if (isset($tvrShow) && $rageID > 0) + $tvrage->updateRageInfo($rageID, $showinfo, $tvrShow, null); + } + +// echo "2 $name\n"; + + if ($rageID == false) + { + $query = "SELECT * FROM releases WHERE ( releases.passwordstatus < 0 AND releases.haspreview < 0 ) AND ID = ".$row['ID']; + $rel = $db->queryOneRow($query); + + if ($rel !== false) + return false; + + $query = "SELECT releasevideo.releaseID FROM releasevideo WHERE releasevideo.releaseID = ".$row['ID']; + $rel = $db->queryOneRow($query); + + if ($rel === false) + return false; + + $query = "SELECT releasefiles.releaseID, releasefiles.`name` FROM releasefiles INNER JOIN releases ON releasefiles.releaseID = releases.ID WHERE releases.ID = ".$row['ID']; + $rel = $db->query($query); + + foreach($rel as $r) + { + $name1 = preg_replace('/(?parseNameEpSeason($name1); + +// var_dump($parsed); + + $rageID = $tvrage->getByTitle($parsed['cleanname']); + + if ($rageID == false) + { + if ($parsed) + $name1 = $parsed['cleanname']; + $sql = sprintf("SELECT rageID from tvrage where (releasetitle = %s or releasetitle = %s)", $db->escapeString($name1), $db->escapeString(str_replace(' and ', ' & ', $name1))); + + $sql = str_replace(" = '", " like '%", $sql); + $sql = str_replace("' or", "%' or", $sql); + $sql = str_replace("')", "%')", $sql); + +// echo "$sql\n"; + + $res = $db->queryOneRow($sql); + if ($res) + $rageID = $res["rageID"]; + } + } + if ($rageID != 0 && $name1 != '') + $name = $name1; + } + + $tmp = $tvrage->getByRageID($rageID); + +// echo "ltvrageid = $rageID\n"; +// var_dump($tmp); + + if (!isset($tmp[0])) + { + + $name = preg_replace('/[\_\.]|bbc|nat.?geo|national.?geographic/i', " ", $name1); +// $name = preg_replace('/(19|20)\d{2}.*$/i', " ", $name); + $name = preg_replace('/\d{1,3} ?of ?\d{1,3}.*$/i', " ", $name); + $name = preg_replace('/^[\]\}\)]|[\[\{\(]/i', "", $name); + $name = trim($name); + +echo "name == $name\n"; + $showinfo = $tvrage->parseNameEpSeason($name); + if (!isset($showinfo['cleanname'])) + $showinfo = array( + 'name' => $name, + 'season' => '', + 'episode' => '', + 'seriesfull' => '', + 'airdate' => '', + 'country' => '', + 'year' => '', + 'cleanname' => $name + ); + + + + try { + $tvrShow = $tvrage->getRageMatch($showinfo); + if (isset($tvrShow["showid"])) + $rageID = $tvrShow["showid"]; + } catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; + } +// var_dump($tvrShow); + if ($tvrShow === false) + { + $name1 = preg_replace('/(\D+?)( s?\d{1,3}?(?!\d).*?)/iU', '\1', $name); + $showinfo = $tvrage->parseNameEpSeason($name1); + if (!isset($showinfo['cleanname'])) + $showinfo = array( + 'name' => $name1, + 'season' => '', + 'episode' => '', + 'seriesfull' => '', + 'airdate' => '', + 'country' => '', + 'year' => '', + 'cleanname' => $name1 + ); +echo "$name1\n"; + $tvrShow = $tvrage->getRageMatch($showinfo); +// var_dump($tvrShow); + if ($tvrShow !== false) + { + if (isset($tvrShow["showid"])) + $rageID = $tvrShow["showid"]; + } + } + + if (($tvrShow !== false && is_array($tvrShow) && $tvrShow['title'] == $name) || $rageID) + { + $showinfo['name'] = $tvrShow["title"]; + $showinfo['cleanname'] = $tvrShow["title"]; + if ($rageID != 0) + $tvrage->updateRageInfo($rageID, $showinfo, $tvrShow, NULL); + } + $tmp = $tvrage->getByRageID($rageID); + } + + if (isset($tmp[0])) + { +// echo "rageID = $rageID\n"; +// echo "title = ".$tmp[0]['releasetitle']."\n"; +// var_dump($tmp); + + $show = $tvrage->parseNameEpSeason($tmp[0]["releasetitle"]." ".$row['searchname']); +// var_dump($tvrage->getEpisodeInfo($rageID, $show['season'], $show['episode'])); + + $name = matchnames($row['name'], $tmp[0]['releasetitle']." ".$show['seriesfull']); + + $name = findquality ($nfo, $name); + + if (dodbupdate($row['ID'], $cat, $name, $rageID, 'tv')) + { + if (is_array($show) && $show['name'] != '') + { + // $tvrage->updateEpInfo($show, $row['ID']); + } + $ok = $rageID; + } + } + + unset($tvrage); + return $ok; +} + +function cleanname($name) +{ + global $qualities; + + $quality = preg_replace('/(.+?)/iU', "/\.*?(\b\\1\b)\.*?/iU", $qualities); + + do { + $original = $name; +// echo "CN: $name\n"; + $name = preg_replace($quality, " \\1 ", $name); + $name = preg_replace("/\.?(s\d+?e\d+?)\.?/iU", " \\1 ", $name); + $name = preg_replace("/yenc/iU", " ", $name); + $name = preg_replace("/^(\[\d+\].\[.+\].(\[#?a.b.[^\]]+\])*?.)/iU", "", $name); + $name = preg_replace("/\[(?![^\[]+\])|\((?![^\(]+\))|\{(?![^\{]+\})/iU", " ", $name); + $name = preg_replace("/^\(?\?+?\)/iU", " ", $name); + $name = preg_replace("/[\x01-\x1f\_\!\?\[\{\}\]\/\:\|]/iU", " ", $name); + $name = preg_replace("/(?getByRageID($rageID); + unset($tvrage); + + $name1 = $name1[0]["releasetitle"]; + + $name = matchnames($row['name'], $name1); + + echo "doing tv1 ".$name." ".$row['guid']."\n"; + + $ok = dodbupdate($id, $cat, $name, $rageID, 'tv'); + + } else { + +//echo "$name $name1\n"; + + $name = matchnames($row['name'], $name1); + + echo "doing tv2 ".$name." ".$row['guid']."\n"; + +// $matches = preg_split('/(\btitle\:|\bname=)[ \.\_]*?(.*)\r/iU', $nfo, 0, PREG_SPLIT_DELIM_CAPTURE); + +// echo $matches[1]."\n"; + + if (empty($name)) + { + $ok = dodbupdate($id, $cat, ''); + } else { + $ok = dodbupdate($id, $cat, $name); + } + } + return $ok; +} + +function doAmazon ($name, $id, $nfo = "", $q, $region = 'com', $case = false, $nfo ='', $row = '') +{ + global $db; + $s = new Sites(); + $site = $s->get(); + $amazon = new AmazonProductAPI($site->amazonpubkey, $site->amazonprivkey, $site->amazonassociatetag); + $ok = false; + + + try { + switch ($case) + { + case 'upc': + $amaz = $amazon->getItemByUpc(trim($q), $region); + break; + case 'asin': + $amaz = $amazon->getItemByAsin(trim($q), $region); + break; + case 'isbn': + $amaz = $amazon->searchProducts(trim($q), '', "ISBN"); + break; + } + } catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; + unset($s); + unset($amaz); + unset($amazon); + return $ok; + } + + if (!isset($amaz->Items->Item)) + return $ok; + + $type = $amaz->Items->Item->ItemAttributes->ProductGroup; + + switch ($type) + { + case 'Book': + case 'eBooks': + $new = (string) $amaz->Items->Item->ItemAttributes->Author; + $new = $new . " - ". (string) $amaz->Items->Item->ItemAttributes->Title; + $name = matchnames($name, $new); + + $query = "SELECT ID FROM `bookinfo` WHERE `asin` = '".(string) $amaz->Items->Item->ASIN."'"; + $rel = $db->query($query); + if (count($rel) == 0) + { + $book = new Book(); + $item = array(); + $item["asin"] = (string) $amaz->Items->Item->ASIN; + $item["url"] = (string) $amaz->Items->Item->DetailPageURL; + $item["coverurl"] = (string) $amaz->Items->Item->LargeImage->URL; + if ($item['coverurl'] != "") + $item['cover'] = 1; + else + $item['cover'] = 0; + $item["author"] = (string) $amaz->Items->Item->ItemAttributes->Author; + $item["dewey"] = (string) $amaz->Items->Item->ItemAttributes->DeweyDecimalNumber; + $item["ean"] = (string) $amaz->Items->Item->ItemAttributes->EAN; + $item["isbn"] = (string) $amaz->Items->Item->ItemAttributes->ISBN; + $item["publisher"] = (string) $amaz->Items->Item->ItemAttributes->Publisher; + $item["publishdate"] = (string) $amaz->Items->Item->ItemAttributes->PublicationDate; + $item["pages"] = (string) $amaz->Items->Item->ItemAttributes->NumberOfPages; + $item["title"] = (string) $amaz->Items->Item->ItemAttributes->Title; + $item["review"] = ""; + if (isset($amaz->Items->Item->EditorialReviews)) + $item["review"] = trim(strip_tags((string) $amaz->Items->Item->EditorialReviews->EditorialReview->Content)); + + $bookId = $book->addUpdateBookInfo($item['title'], $item['asin'], $item['url'], + $item['author'], $item['publisher'], $item['publishdate'], $item['review'], + $item['cover'], $item['dewey'], $item['ean'], $item['isbn'], $item['pages'] ); + unset($book); + } else { + $bookId = $rel[0]['ID']; + } + + + $query = "SELECT * FROM releases INNER JOIN releaseaudio ON releases.ID = releaseaudio.releaseID WHERE releases.ID = $id"; + $rel = $db->query($query); + if (count($rel) == 0) + { + $ok = dodbupdate($id, 7020, $name, $bookId, 'book'); + } else { + $ok = dodbupdate($id, 3030, $name, $bookId, 'book'); + } + unset($rel); + break; + + case 'Digital Music Track': + case 'Digital Music Album': + case 'Music': + $new = (string) $amaz->Items->Item->ItemAttributes->Artist; + if ($new != '') + $new = $new . " - "; + $new = $new .(string) $amaz->Items->Item->ItemAttributes->Title; + $name = matchnames($name, $new); + + $query = "SELECT * FROM `bookinfo` WHERE `asin` = '".(string) $amaz->Items->Item->ASIN."'"; + +// echo "$query\n"; + $rel = $db->query($query); + if (count($rel) == 0) + { + $mus = array(); + $mus['coverurl'] = (string) $amaz->Items->Item->LargeImage->URL; + if ($mus['coverurl'] != "") + $mus['cover'] = 1; + else + $mus['cover'] = 0; + + $mus['title'] = (string) $amaz->Items->Item->ItemAttributes->Title; + + $mus['asin'] = (string) $amaz->Items->Item->ASIN; + + $mus['url'] = (string) $amaz->Items->Item->DetailPageURL; + + $mus['salesrank'] = (string) $amaz->Items->Item->SalesRank; + if (empty($mus['salesrank'])) + $mus['salesrank'] = 'null'; + + $mus['artist'] = (string) $amaz->Items->Item->ItemAttributes->Artist; + + $mus['publisher'] = (string) $amaz->Items->Item->ItemAttributes->Publisher; + + $mus['releasedate'] = $db->escapeString((string) $amaz->Items->Item->ItemAttributes->ReleaseDate); + if ($mus['releasedate'] == "''") + $mus['releasedate'] = 'null'; + + $mus['review'] = ''; + if (isset($amaz->Items->Item->EditorialReviews)) + $mus['review'] = trim(strip_tags((string) $amaz->Items->Item->EditorialReviews->EditorialReview->Content)); + + $mus['year'] = ($mus['releasedate'] != 'null' ? substr($mus['releasedate'], 1, 4) : date("Y")); + + $mus['tracks'] = ''; + if (isset($amaz->Items->Item->Tracks)) + { + $tmpTracks = (array) $amaz->Items->Item->Tracks->Disc; + $tracks = $tmpTracks['Track']; + $mus['tracks'] = (is_array($tracks) && !empty($tracks)) ? implode('|', $tracks) : ''; + } + + $music = new Music(); + $musicId = $music->addUpdateMusicInfo($mus['title'], $mus['asin'], $mus['url'], + $mus['salesrank'], $mus['artist'], $mus['publisher'], $mus['releasedate'], $mus['review'], + $mus['year'],'', $mus['tracks'], $mus['cover'] ); + + unset($music); + } else { + $musicId = $rel[0]['ID']; + } + + $ok = dodbupdate($id, 3010, $name, $musicId, 'music'); + break; + + case 'Movies': + case 'DVD': + $new = (string) $amaz->Items->Item->ItemAttributes->Title; + $new = $new . " (" . substr((string) $amaz->Items->Item->ItemAttributes->ReleaseDate, 0, 4) . ")"; + $name = matchnames($name, $new); + + $ok = matchimdb ($nfo, $row); + + if (!$ok) + { + $name = findquality ($nfo, $name); + $ok = dodbupdate($id, 2000, $name); + } + break; + + default: + echo "* * * * * * uncatched amazon category $type ".$name; + break; + } +//echo $query."\n"; + + unset($s); + unset($amaz); + unset($amazon); + return $ok; +} + +function doarray($matches) +{ + $r = array(); + + foreach ($matches as $m) + { + if (strlen($m) < 50) + { + $str = preg_replace("/\s/iU", "", $m); + + $m = strtolower($str); + + if ($m == 'audiobook') { + $r[-1] = $m; + } else if ($m == 'anidb.net') { + $r[-2] = $m; + } else if ($m == 'upc') { + $r[-3] = $m; + } else if ($m == 'amazon.') { + $r[-4] = $m; + } else if ($m == 'asin') { + $r[-5] = $m; + } else if ($m == 'imdb') { + $r[-6] = $m; + } else if ($m == 'os') { + $r[-7] = $m; + } else if ($m == 'mac' || $m == 'macintosh' || $m == 'dmg' || $m == 'macos' || $m == 'macosx' || $m == 'osx') { + $r[-8] = $m; + } else if ($m == 'itunes.apple.com/') { + $r[-9] = $m; + } else if (preg_match('/sports|deportes|nhl|nfl|\bnba/i', $m)) { + $r[1000] = $m; + } else if (preg_match('/avi|xvid|divx|mkv/i', $m)) { + $r[1001] = $m; + } else if (preg_match('/\.(?:rar|001)/i', $m)) { + $r[1002] = $m; + } else { + $r[] = $m; + } + } + } + + ksort($r); + return $r; +} + +function doOS ($nfo, $name, $cat, $id) +{ + global $db; + + $ok = false; + + $pattern = '/(.*v(?:er)?[\.\s]*?\d+\.\d(?:\.\d+)??[^\v]*?)|(?getNZBPath($row['guid']); + $m3u = ''; + $alt = ''; + $mp3 = false; + $mp3name = ''; + $files = 0; + $extras = 0; + + echo "doing music ".$row['guid']."\n"; + + if ($nzbinfo->loadFromFile($file)) + { + $name = $row['name']; + + $name = preg_replace("/\//",' ', $name); + +// echo "$name\n"; + + $name = preg_quote($name); + + + echo "$name\n"; + + + foreach($nzbinfo->nzb as $nzbsubject) + { + + $sub = $nzbsubject['subject']."\n"; + + $sub = preg_replace("/$name/i",'', $sub); + +// echo "doing music file = $sub\n"; + + if (preg_match('/\.(vol\d{1,3}?\+\d{1,3}?|par2|nfo\b|sfv|par\b|p\d{1,3}?|sv\b)/iU', $sub)) + { + $extras++; + $alt = preg_replace('/(\.vol\d{1,3}?\+\d{1,3}?|\.par2|\.[a-z][a-z0-9]{2})+?".+?/iU', '', $sub); + } + + if (preg_match('/\.mp3|\.flac/', $sub, $matches)) + { + $mp3name = preg_replace('/(\.mp3".+?)/iU', '.mp3', $sub); + $mp3name = preg_replace('/(\.flac".+?)/iU', '.flac', $sub); + $mp3name = preg_replace('/(?iU)^[^\"]+\"(0\d+?-?(00)??)??/iU', '', $mp3name); + + $mp3 = true; + $files++; + } + + if (preg_match('/\.m3u|\"00+[ \-\_\.]+?|\.nfo\b|\.sfv/iU', $sub, $matches)) + { + if (preg_match('/\.url|playlist/iU', $sub)) + { + continue; + } + $sub = preg_replace('/(\.vol\d{1,3}?\+\d{1,3}?|\.par2|\.[a-z][a-z0-9]{2})+?".+?/iU', '', $sub); + + $m3u = preg_replace('/(?iU)^[^\"]+\"(0\d+?-?(00)??)??/iU', '', $sub); + } + + } + } + $name = ''; + + if ( count($nzbinfo->nzb) > 0) + { + + echo (($m3u != '' || ($files + $extras) / count($nzbinfo->nzb) > 0.7) && $mp3)." ".$mp3." ".$m3u."\n"; + + if (($m3u != '' || (($files + $extras) / count($nzbinfo->nzb) > 0.7)) && $mp3) + { + $name = $m3u; + + if ($files == 1) + $name = $mp3name; + + if (empty($name)) + { + $name = matchnames($row['name'], $alt); + } + + echo $row['guid']." ".$name.' '.$mp3.' '.($files + $extras) / count($nzbinfo->nzb)."\n"; + + } + + echo (($m3u != '' || ($files + $extras) / count($nzbinfo->nzb) > 0.7) && $mp3)." ".$mp3." ".$m3u."\n"; + + } + +echo "music files $name\n"; + $name = cleanname($name); +echo "cleaned name $name\n"; + unset($file); + + unset($nzbinfo); + unset($nzb); + + return $name; +} + +function findquality ($nfo, $name) +{ + global $qualities; + $qual = array(); +// echo "$name\n"; + foreach ($qualities as $quality) + { + if (preg_match("/(?$quality) + { + if (preg_match("/$quality/iU", $name)) + { + unset($qual[$key]); + } + } + + $n = ''; + if (count($qual) > 0) + { + foreach ($qual as $quality) + { + $n = $n ." ".$quality; + } + } + + return trim($name .' '.$n); +} + +function matchanime ($nfo, $id, $name) +{ + $ok = false; + $anime = ''; + + if (preg_match('/anidb.net.*aid=(\d+?)/iU', $nfo, $set)) + { + $anidb = new AniDB(); + if ($anidb->getAnimeInfo($set[1]) === false) + { + $anidb->addTitle($anidb->AniDBAPI($set[1])); + } + $anime = $anidb->getAnimeInfo($set[1]); + + if ($anime !== false) + { + + $anime = matchnames($name, $anime['title']); + + $ok = dodbupdate($id, 5070, $anime, $set[1], 'anime'); + } + unset($anidb); + + } + return $ok; +} + +function matchimdb ($nfo, $row) +{ + $ok = false; + + preg_match('/imdb\.[a-z0-9\.\_\-\/]+?(?:tt|\?)(\d+?)\/?/iU', $nfo, $set); + +// echo "imdb name= ".$row['name']."\n"; + + if (isset($set[1])) + { + $imdb = $set[1] + 0; + + $movie = new Movie(); + + $title = $movie->getMovieInfo($imdb); + + if ($title === false) + { + $movie->fetchImdbProperties($imdb); + $movie->updateMovieInfo($imdb); + $title = $movie->getMovieInfo($imdb); + } + + $name = $title['title']." (".$title['year'].")"; + +// $name = matchnames($row['name'], $name); + + // echo "quality ".findquality ($nfo, $name)."\n"; + $name = findquality ($nfo, $name); + + $name = matchnames($row['name'], $name); + + echo "imdb $name\n"; + +// echo (strval($imdb) + 0) . " * * * " . (strval($title['imdbID']) + 0) ."\n"; + + if ((strval($imdb) + 0) == (strval($title['imdbID']) + 0)) + { + if (preg_match('/sport/iU', $title['genre'])) { + $ok = dodbupdate($row['ID'], 5060, $name, $imdb, 'imdb'); + } else if (preg_match('/docu/iU', $title['genre'])) { + $ok = dodbupdate($row['ID'], 5080, $name, $imdb, 'imdb'); + } else if (preg_match('/talk\-show/iU', $title['genre'])) { + $ok = dodbupdate($row['ID'], 5000, $name, $imdb, 'imdb'); + } else if (preg_match('/tv/iU', $title['genre']) || preg_match('/episode/iU', $title['genre']) || preg_match('/reality/iU', $title['genre'])) { + $ok = updateTV ($title['title']." (".$title['year'].")", $row['ID'], $row, 5000, $nfo); + } else { + $ok = dodbupdate($row['ID'], 2000, $name, $imdb, 'imdb'); + } + } + unset($movie); + } +// echo (bool) $ok."\n"; + return $ok; +} + +function matchaudiobook ($nfo, $id, $oldname, $row) +{ + global $db; + $ok = false; + + if (preg_match('/Sample Rate|MP3|speech|Encoded|ID3|(un)?abridged|Copyright|Ripped|khz|stero|mono/i', $nfo)) + { + if (preg_match('/mpeg|pixels|fps/i', $nfo)) + { + echo "not audio\n"; + return $ok; + } + $query = "SELECT * FROM releases INNER JOIN releasevideo ON releases.ID = releasevideo.releaseID where ( releases.passwordstatus >= 0 OR releases.haspreview >= 0 ) AND releases.ID = ".$id; + $rel = $db->query($query); + if (count($rel) > 0) + { + echo "not audio\n"; + return $ok; + } + unset ($rel); + + echo "audiobooks $id\n"; + $name = $oldname; + $author = ''; + $title = ''; + $bookID = 0; + $set = preg_split('/\btitle\:?(\.\.+?|\s\s+?|__+?)([^\r]*)\r/Ui', $nfo, 0, PREG_SPLIT_DELIM_CAPTURE); + + + if (isset($set[2])) + { + + $set[2] = trim(preg_replace('/[\|\:\-]| +/', ' ', $set[2])); + +// echo $set[2]."\n"; + $name = $set[2]; + $title = $name; + + $set = preg_split('/author\:?(\.\.+?|\s\s+?|__+?)([^\r]*)\r/Ui', $nfo, 0, PREG_SPLIT_DELIM_CAPTURE); + + if (isset($set[2])) + { + $set[2] = trim(preg_replace('/[\|\:\-]| +/', ' ', $set[2])); + +// echo $set[2]."\n"; + $name = $set[2]." - ".$name; + $author = $set[2]; + } + + $bookID = findbookid ($author, $title); +// +// $book = new Book(); +// $rel = $book->getBookInfoByName($author, $title); +// +// if ($rel === false) +// { +// $query = "Select * from `bookinfo` WHERE `title` LIKE '%".$title."%' AND ID in (SELECT ID FROM `bookinfo` WHERE `author` sounds LIKE '".$author."')"; +// $rel = $db->query($query); +// // echo "$query\n"; +// +// if (isset($rel[0]["ID"])) +// { +// // var_dump($rel); +// $bookID = $rel[0]["ID"]; +// } else { +// // echo "not found\n"; +// $bookID = $book->updateBookInfo($author, $title); +// // echo "$bookID\n"; +// } +// } else { +// $bookID = $rel['ID']; +// } + + $name = matchnames($oldname, $name); + if ($bookID > 0) + { + $ok = dodbupdate($id, 3030, $name, $bookID, 'book'); + } else { + $ok = dodbupdate($id, 3030, $name); + } + } else { + $ok = findmusicname($row, 3030); +// $ok = dodbupdate($id, 3030); + } + } +// unset($book); + return $ok; +} + +function matchmusic($nfo, $row) +{ + $artist = $album = $title = ''; + + $artist = preg_split('/(?:a\s?r\s?t\s?i\s?s\s?t\b)+? *?(?!(?:[^ \.\:\}\]\*] ?){2,}?\b)(?:[\*\?\-\=\|\;\:\.\[\}\]\( \xb0-\x{3000}]+?)[ \.\>\:]([a-z0-9]?(?!:).+?(?\:]([a-z0-9]?(?!:).+?(?1 && $title[1] <50 && isset($artist[1]) && strlen($artist[1]) >1 && $artist[1] <50) + { + +// echo "\n * * * * * title= ".$title[1]."\t ".$row['name']."\n"; + if (isset($artist[1])) + { + $new = trim($artist[1]); + $artist1 = trim($artist[1]); + } + + + if (isset($title[1])) + { + if (strlen($new) > 1) + { + $new = $new . " -*- "; + } + $new = $new . trim($title[1]); + $album = trim($title[1]); + } + + $name = matchnames($row['name'], $new); + + $artist = matchnames($artist1, ''); + $album = matchnames($album, ''); + +// echo "$artist * * $album\n"; + } else { + + $name = domusicfiles ($row); + if ($name != "") + { + $result = $music->parseArtist($name); + $artist = $result['artist']; + $album = $result['album']; + } + } + +echo "3artist = $artist album = $album\n"; + + $album = stripname($album); + $artist = stripname($artist); + +if (is_array($artist)) + var_dump($artist); + + $tmp = explode(",", $artist); + + if (count($tmp) > 1) + $artist = trim($tmp[1]." ".$tmp[0]); + +echo "4artist = $artist album = $album\n"; + + if ($artist != '' && $album != '') + $musicId = 0; + else { + $rel = $music->getMusicInfoByName($artist, $album); +// var_dump($rel); + $musicId = $rel['ID']; + } + + if ($musicId <= 1) + { + echo "amazon music2 "; + $musicId = $music->updateMusicInfo($artist, $album, 0); + + if ($musicId === false) + { +// var_dump($artist); +// var_dump($album); + $book = new Book(true); + $bookId = $book->updateBookInfo($artist, $album); + unset($book); + } +// var_dump($musicId); + + } + + if ($musicId > 0) + { + $ok = dodbupdate($row['ID'], 3010, $name, $musicId, 'music'); + } else if ($bookId > 0) { + $ok = dodbupdate($row['ID'], 3030, $name, $bookId, 'book'); + } + + if (!$ok) + { + $ok = findmusicname($row, 3010); + +// $name = matchnames($row['name'], domusicfiles($row)); +// $ok = dodbupdate($row['ID'], 3010, ''); + } + if (!$ok) + { + if (preg_match('/book/i', $row['gname'])) + $ok = dodbupdate($row['ID'], 3030, $name); + else + $ok = dodbupdate($row['ID'], 3010, $name); + } + unset($music); + return $ok; +} + +function matchmag($nfo, $row) +{ + $ok = false; + $set = preg_split('/(?:\btitle|\bname|release)\b(?:[\-\:\.\}\[\s\xb0-\x{3000}]+?)\B([a-z0-9\.\- \(\)]+?)/Uui', $nfo, 0, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY); + if (isset($set[1])) + { + $name = trim($set[1]); + if (preg_match('/(?:issue)\b(?:[\-\:\.\}\[\s\xb0-\x{3000}]+?)\B([a-z0-9\.\- \(\)\/]+?)/iuU', $nfo, $set)) + { + if (isset($set[1])) + { + $name = $name." ".trim($set[1]); + } + $name = matchnames($row['name'], $name); + $ok = dodbupdate($row['ID'], 7010, $name ); + } + } + return $ok; +} + +function dodbupdate($id, $cat, $name = '', $typeid = 0, $type='none', $debug = DEBUGGING) +{ + global $db; + + $query = "UPDATE `releases` SET `categoryID` = $cat"; + + if ($name != '') + $query = $query.", `searchname` = ".$db->escapeString($name); + switch ($type) { + case 'imdb': + if ($typeid != 0) + $query = $query.", `imdbID` = $typeid"; + break; + case 'book': + if ($typeid != 0) + $query = $query.", `bookinfoID` = $typeid"; + break; + case 'music': + if ($typeid != 0) + $query = $query.", `musicinfoID` = $typeid"; + break; + case 'anime': + if ($typeid != 0) + $query = $query.", `anidbID` = $typeid"; + break; + case 'tv': + if ($typeid != 0) + $query = $query.", `rageID` = $typeid"; + break; + default: + break; + } + + $query = $query." where `ID` = $id"; +echo $debug." ".$query."\n"; + if (!$debug) + { +echo "updating"; + if ($db->query($query) !== false) + return true; + } else { + return true; + } + return false; +} + +function findmovie($name) +{ + $imdb = 0; + + $j = 0; + + $name = stripname($name); + + $url = "http://www.omdbapi.com/?r=xml&s="; + $name1 = $name; + if (preg_match('/([^\[\r\]]+)[\[\{\(\_\. ]+?((?:19|20)\d{2})/U', $name, $title)) + { + $url = $url.urlencode($title[1])."&y=".$title[2]; + $name1 = $title[1]." ".$title[2]; + } + else + $url = $url.urlencode($name); + +echo "omdbapi: $url\n"; +echo cleanname($name1)."\n"; + + $data = getUrl($url); + +//echo "$data\n"; + $xmlObj = @simplexml_load_string(html_entity_decode($data)); + $arrXml = objectsIntoArray($xmlObj); + +// var_dump($arrXml); + + if (isset($arrXml["Movie"])) + { + + $tvrage = new TVRage(true); + + $name1 = ''; + + foreach ($arrXml["Movie"] as $ax) + { +// var_dump($ax); + + if (isset($ax["@attributes"])) + $a = $ax["@attributes"]; + else + $a = $ax; + if (isset($title[2]) && $a["Year"] == $title[2]) + { + $i = 0; + $a["Title"] = preg_replace('/&/', ' and ', $a["Title"]); + $name = preg_replace('/&/', ' and ', $name); + +//echo "matched ".$a["Title"]."\n"; + + $arr = preg_split('/[\:\:\.\, \-\_\(\)\[\]\{\}]/', $a["Title"], 0, PREG_SPLIT_NO_EMPTY); + foreach ($arr as $r) + { +echo preg_quote($r)."\n"; + $r = str_replace("/", " ", $r); + $r = str_replace("\\", " ", $r); + if (preg_match('/'.preg_quote($r).'/i', $name)) + $i++; + } + if (count($arr) == $i && $i > $j) + { + $name1 = $name; + $imdb = $a["imdbID"]; + $j = $i; + } +// echo "comp result ".count($arr)." ".$i." ".$name."\n"; +// echo $a["Title"]."\n"; + } + } + echo "$name1 $imdb\n"; + + unset($tvrage); + } + echo "findmovie = $imdb\n"; + + return array(strval($imdb), $j); +} + +function matchvideo($row, $nfo) +{ + global $db; + + $ok = false; + + $imdb = ''; + + $j = 0; + + $query = "SELECT releasevideo.releaseID FROM releasevideo WHERE releasevideo.releaseID = ".$row['ID']; + $rel = $db->queryOneRow($query); + + if ($rel === false) + { + $query = "SELECT releasefiles.`name`, releasefiles.releaseID, releasefiles.size FROM releasefiles WHERE releasefiles.releaseID = ".$row['ID']; + $res = $db->queryDirect($query); + + $cont = false; + while ($rel = $db->getAssocArray($res)) + { + if(preg_match('/\.(iso|mkv|mp4|iso|divx)$|\.([^\.]+)$/', $rel['name'], $ext)) + { + echo "ext = ".$ext[1]." ".$row['guid']."\n"; + var_dump($ext); + $cont = true; + } + } + if (!$cont) + return false; + } + $thename = $name = $row['name']; +echo "name1: $name\n"; + $rageID = lookupTV ($name, $nfo, $row, 5000); + + if ($rageID == 0) + { + $imdb = findmovie($name); + $imdb = $imdb[0]; + } + + if ($rageID == 0 && empty($imdb) ) + { + $set = preg_split('/(?:\btitle|\bname).+[\.\s]+?[^a-z0-9]*?([a-z0-9\-\.\_ ]+?)/iU', $nfo, 0, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY); +//var_dump($set); + if (isset($set[1])) + { +echo "name2: ".$set[1]."\n"; + $rageID = lookupTV ($set[1], $nfo, $row, 5000); + if ($rageID) + { + $thename = $set[1]; + } else + { + $imdb = findmovie($set[1]); + $imdb = $imdb[0]; + } + + } + + if ($rageID == 0 && empty($imdb) ) + { + $query = "SELECT releasefiles.releaseID, releasefiles.`name` FROM releasefiles INNER JOIN releases ON releasefiles.releaseID = releases.ID WHERE releases.ID = ".$row['ID']; + $rel = $db->query($query); + + $ok = false; + $j = 0; + + + if (count($rel) > 0) + { + foreach($rel as $r) + { + $name1 = preg_replace('/video[\_\. ]ts/iU', ' ', $r['name']); + + $name1 = preg_replace('/\\\\/', ' ', $name1); + + $name1 = preg_replace('/\.[a-z][a-z0-9]{2}$/iU', '', $name1); + + $name1 = preg_replace('/ +/', ' ', $name1); + + $name1 = preg_replace('/^ | $/', '', $name1); + + echo "file ".$name1."\n"; +echo "name3: $name1\n"; + $rageID = lookupTV ($name1, $nfo, $row, 5000); + + if ($rageID && $j == 0) + { + $thename = $name1; + break; + } else { + $tmp = findmovie($name1); +// var_dump($tmp); + if ($tmp[1] > $j) + { + echo "$rageID\n"; + $imdb = $tmp[0]; + $j = $tmp[1]; + $thename = $name1; + } + } + + } + } + } + } +echo "$j $rageID $imdb\n"; + + if ($imdb != '') + { + $imdb = preg_replace('/^tt/', '', $imdb); + $movie = new Movie(); + $tmp = $movie->getMovieInfo($imdb); + + if ($tmp === false) + { + $movie->fetchImdbProperties($imdb); + $movie->updateMovieInfo($imdb); + $tmp = $movie->getMovieInfo($imdb); + } + + + $thename = matchnames($row['name'], $thename); + $thename = matchnames($thename, $tmp['title']); + $thename = findquality ($nfo, $thename); + + unset($movie); + +echo "$thename\t"; +// var_dump($tmp); + + if (isset($tmp['ID'])) + { + if (preg_match('/sport/iU', $tmp['genre'])) { + $ok = dodbupdate($row['ID'], 5060, $thename, $imdb, 'imdb'); + } else if (preg_match('/docu/iU', $tmp['genre'])) { + $ok = dodbupdate($row['ID'], 5080, $thename, $imdb, 'imdb'); + } else if (preg_match('/talk\-show/iU', $tmp['genre'])) { + $ok = dodbupdate($row['ID'], 5000, $thename, $imdb, 'imdb'); + } else if (preg_match('/tv/iU', $tmp['genre']) || preg_match('/episode/iU', $tmp['genre']) || preg_match('/reality/iU', $tmp['genre'])) { + $ok = updateTV ($tmp['title']." (".$tmp['year'].")", $row['ID'], $row, 5000, $nfo); + } else { + $ok = dodbupdate($row['ID'], 2000, $thename, $imdb, 'imdb'); + } + } + + + } + + if ($rageID) + { + $tvrage = new TVRage(true); + $tmp = $tvrage->getByRageID($rageID); + $thename = matchnames($row['name'], $thename); + $thename = matchnames($thename, $tmp[0]['releasetitle']); + $thename = findquality ($nfo, $thename); + + $name = $tmp[0]['releasetitle']; + + // $tmp = $tvrage->getByRageID($rageID); + + unset($tvrage); +// var_dump($tmp); +echo "doing updates"; + if (isset($tmp[0])) + { + if (preg_match('/sports/i', $tmp[0]['genre'])) + $ok = dodbupdate($row['ID'], 5060, $thename, $rageID, 'tv'); + elseif (preg_match('/documen/i', $tmp[0]['genre'])) + $ok = dodbupdate($row['ID'], 5080, $thename, $rageID, 'tv'); + else + $ok = dodbupdate($row['ID'], 5000, $thename, $rageID, 'tv'); + } + } + + if ($rageID == 0 && empty($imdb) ) + { + $thename = matchnames($row['name'], $thename); + $thename = findquality ($nfo, $thename); + + if (preg_match('/sport/i', $row['gname'])) + $ok = dodbupdate($row['ID'], 5060, $thename); + elseif (preg_match('/docu/i', $row['gname'])) + $ok = dodbupdate($row['ID'], 5080, $thename); + elseif (preg_match('/tv/i', $row['gname'])) + $ok = dodbupdate($row['ID'], 5000, $thename); + elseif (preg_match('/mov/i', $row['gname'])) + $ok = dodbupdate($row['ID'], 2000, $thename); + else + $ok = dodbupdate($row['ID'], 2020, $thename); + } + + return $ok; +} + + +echo "starting\n"; +$db = new DB(); + +$res = $db->query("SET NAMES 'utf8'"); +$res = $db->query("SET CHARACTER SET 'utf8'"); + +//mysql_query("SET NAMES 'utf8'"); +//mysql_query("SET CHARACTER SET 'utf8'"); +mb_internal_encoding("UTF-8"); +mb_regex_encoding("UTF-8"); +mb_http_output("UTF-8"); +mb_language("uni"); + +$query = "SELECT ID FROM category WHERE parentID = 8000"; // OR parentID = 2000 OR parentID = 5000 + +$res = $db->query($query); + +$thecategory = $res[0]['ID']; + +unset($res[0]); + +foreach($res as $r) + $thecategory = $thecategory.", ".$r['ID']; + +if (isset($argv[1])) +{ + $query = "SELECT uncompress(releasenfo.nfo) AS nfo, releases.ID, releases.guid, releases.`name`, releases.searchname, groups.`name` AS gname FROM releasenfo INNER JOIN releases ON releasenfo.releaseID = releases.ID INNER JOIN groups ON releases.groupID = groups.ID WHERE releases.ID = ".$argv[1]; +} else { + $query = "SELECT uncompress(releasenfo.nfo) AS nfo, releases.ID, releases.guid, releases.`name`, releases.searchname, groups.`name` AS gname FROM releasenfo INNER JOIN releases ON releasenfo.releaseID = releases.ID INNER JOIN groups ON releases.groupID = groups.ID WHERE releases.categoryID IN ( $thecategory )"; +} +//$query = "SELECT uncompress(releasenfo.nfo) AS nfo, releases.ID, releases.guid, releases.`name`, releases.searchname, groups.`name` AS gname FROM releasenfo INNER JOIN releases ON releasenfo.releaseID = releases.ID INNER JOIN groups ON releases.groupID = groups.ID"; +//$query = "SELECT uncompress(releasenfo.nfo) AS nfo, releases.ID, releases.guid, releases.`name`, releases.searchname, groups.`name` AS gname FROM releasenfo INNER JOIN releases ON releasenfo.releaseID = releases.ID INNER JOIN groups ON releases.groupID = groups.ID WHERE releases.guid = '6dc77dc7fb48745ee76ec345c4fe789b'"; +// +//echo $query."\n"; + +$res = $db->queryDirect($query); + +echo "got matches\n"; + +while ($row = $db->getAssocArray($res)) +{ + $nfo = utf8_decode($row['nfo']); + + if (strlen($nfo) > 0) + { +// trigger_error("doing nfo ".$row['ID']." ".$row['name']); + + $pattern = '/.+(\.rar|\.001) [0-9a-f]{6,10}?|(imdb)\.[a-z0-9\.\_\-\/]+?(tt|\?)(\d+?)\/?|(tvrage)|(\bASIN)|(isbn)|(UPC\b)|(comic book)|(comix)|(tv series)|(\bos\b)|(documentaries)|(documentary)|(doku)|(macintosh)|(dmg)|(mac[ _\.\-]??os[ _\.\-]??x??)|(\bos\b\s??x??)|(\bosx\b)'; + $pattern = $pattern . '|(\bios\b)|(iphone)|(ipad)|(ipod)|(pdtv)|(hdtv)|(video streams)|(movie)|(audiobook)|(audible)|(recorded books)|(spoken book)|(speech)|(read by)\:?|(narrator)\:?|(narrated by)'; + $pattern = $pattern . '|(dvd)|(ntsc)|(m4v)|(mov\b)|(avi\b)|(xvid)|(divx)|(mkv)|(amazon\.)[a-z]{2,3}.*\/dp\/|(anidb.net).*aid=|(\blame\b)|(\btrack)|(t r a c k)|(music)|(44.1kHz)|type:(game)|(game) Type|(platform)|\b(win(?:dows|all|xp)\b)|(\bwin\b)'; + $pattern = $pattern . '|(m3u)|(flac\b)|(application)|(plugin)|(\bcrack)|(install)|(setup)|(magazin)|(x264)|(itunes\.apple\.com\/)|(sports)|(deportes)|(nhl)|(nfl)|(\bnba)|(ncaa)|(album)|(epub)|(mobi)|format\W+(pdf)/iU'; + + $matches = preg_split($pattern, $nfo, -1, PREG_SPLIT_NO_EMPTY|PREG_SPLIT_DELIM_CAPTURE); + + $matches = doarray($matches); + + if (count($matches) > 0) + { + // var_dump($matches); + } + + foreach($matches as $m) + { + if (isset($m)) { + $case = preg_replace('/ /', '', $m); + } else { + $case = ''; + } + if ($row['name'] == '4d5bdbf0da623fb9cf849b8b745c60e9') + print_r($matches); + + if (($m == 'os' || $m == 'platform') && preg_match('/(?:\bos\b(?: type)??|platform)[ \.\:\}]+(\w+?).??(\w*?)/iU', $nfo, $set)) + { + + if (isset($set[1])) + { + // var_dump($set); + $case = strtolower($set[1]); + } + if (strlen($set[2]) && (stripos($set[2], 'mac') !== false || stripos($set[2], 'osx') !== false)) + { + $case = strtolower($set[2]); + } + } + + + echo "\n".$case." ".$row['guid']."\n"; + // echo $row['name']."\n"; + // echo $row['searchname']."\n"; + echo "$case ".$row['guid']."\n"; + + switch (strtolower($case)) + { + case 'itunes.apple.com/': + echo $row['guid']."\n"; + preg_match('/itunes\.apple\.com\/(.*)/iU', $nfo, $set); + echo 'itunes.apple.com'.$set[1]."\n"; + break; + + case 'imdb': + if (matchimdb($nfo, $row)) + break(2); + break; + + + case "asin": + case "isbn": + case "amazon.": + case "upc": + if ($case == 'asin' || $case == 'isbn') + { + preg_match('/(?:isbn|asin)[ \:\.]*? *?([a-zA-Z0-9\-\.]{8,20}?)/iU', $nfo, $set); + var_dump($set); + if (isset($set[1])) + { + $set[1] = preg_replace('/[\-\.]/', '', $set[1]); + echo "asin ".$set[1]."\n"; + if (strlen($set[1])>13) + break; + if (isset($set[1])) + { + $set[2] = $set[1]; + $set[1] = "com"; + } + } + } else if ($case == 'amazon.') { + preg_match('/amazon\.([a-z]*?\.?[a-z]{2,3}?)\/.*\/dp\/([a-zA-Z0-9]{8,10}?)/iU', $nfo, $set); + } else if ($case == 'upc') { + preg_match('/UPC\:?? *?([a-zA-Z0-9]*?)/iU', $nfo, $set); + if (isset($set[1])) + { + $set[2] = $set[1]; + $set[1] = "All"; + } + } else { + echo "* * * * * error in amazon"; + break; + } + + if (count($set) > 1) + { + if (doAmazon ($row['name'], $row['ID'], $nfo, $set[2], $set[1], $case, $nfo, $row)) + { + break(2); + } + } + break; + case 'comicbook': + case 'comix': + if (dodbupdate($row['ID'], 7030)) + break(2); + break; + case 'epub': + case 'mobi': + case 'pdf': + echo "ebooks\n"; + $name = ''; + if (preg_match('/(?:\btitle\b)+?(?! *[^ \.\:\}\]]{2,}?\b)(?:[\|\;\:\.\[\}\]\( \xb0-\x{3000}]+?)[ \.]([a-z0-9](?!:)(?:.(?!\s\s+))+?[^\s]+?)/Uuim', $nfo, $title)) + $name = $title[1]; + if (dodbupdate($row['ID'], 7020, $name)) + break(2); + + break; + case 'audiobook': + case 'audible': + case 'recordedbooks': + case 'spokenbook': + case 'readby': + case 'narratedby': + case 'narrator': + case 'speech': + if (matchaudiobook ($nfo, $row['ID'], $row['name'], $row)) + break(2); + break; + + case 't r a c k': + case 'track': + case 'lame': + case 'album': + case 'music': + case '44.1kHz': + case 'm3u': + case 'flac': + if (preg_match('/(a\s?r\s?t\s?i\s?s\s?t|l\s?a\s?b\s?e\s?l|mp3|e\s?n\s?c\s?o\s?d\s?e\s?r|rip|stereo|mono)/i', $nfo)) + { + if (!preg_match('/(\bavi\b|x\.?264|divx|mvk|xvid|install|Setup\.exe|unzip|unrar)/i', $nfo)) + { + if (matchmusic($nfo, $row)) + { + // echo "breaking 2\n"; + break(2); + } + } else { + // echo "$case ".$row['guid']."\n"; + if (findmusicname($row, 3010)) + break (2); + } + } + break; + + case 'magazin': + // echo "magazin\n"; + if (matchmag($nfo, $row)) + break(2); + break; + + case 'dmg': + case 'mac': + case 'macintosh': + case 'macos': + case 'macosx': + case 'osx': + if (doOS($nfo, $row['name'], 4030, $row['ID'])) + break(2); + break; + + case 'ios': + case 'iphone': + case 'ipad': + case 'ipod': + + if (doOS($nfo, $row['name'], 4060, $row['ID'])) + break(2); + break; + + case 'application': + case 'install': + case 'setup': + if (!preg_match('/(Setup(\.exe)?|unzip|unrar)/i', $nfo)) + continue; + if (preg_match('/(\bavi\b|x\.?264|divx|mvk|xvid|install)/i', $nfo)) + continue; + + case 'windows': + case 'win': + case 'winall': + case 'winxp': + case 'plugin': + case 'crack': + case 'linux': + if (doOS($nfo, $row['name'], 4020, $row['ID'])) + break(2); + break; + + case 'android': + if (doOS($nfo, $row['name'], 4070, $row['ID'])) + break(2); + break; + + case 'game': + $set = preg_split('/\>(.*)\queryDirect($query); + +echo "doing part 2\n"; + +while ($row = $db->getAssocArray($res)) +{ +// trigger_error("doing part 2".$row['ID']); + $query = "SELECT releasevideo.releaseID FROM releasevideo WHERE releasevideo.releaseID = ".$row['ID']; + $rel = $db->queryOneRow($query); + + if ($rel !== false) + continue; + + echo "\n".$row['guid']."\n"; + + $query = 'SELECT releasenfo.releaseID, uncompress(releasenfo.nfo) AS nfo FROM releasenfo WHERE releasenfo.releaseID = '.$row['ID']; + $rel = $db->queryOneRow($query); + + $nfo = ''; + if ($rel !== false) + if ($rel['releaseID'] == $row['ID']) + $nfo = $rel['nfo']; + + matchmusic($nfo, $row); + //findmusicname($row, 3010); +} + +if (isset($argv[1])) +{ + $query = "SELECT releasefiles.`name` AS rname, releasefiles.size, releases.*, groups.`name` AS gname FROM releasefiles INNER JOIN releases ON releasefiles.releaseID = releases.ID INNER JOIN groups ON releases.groupID = groups.ID WHERE releases.ID = ".$argv[1]." ORDER BY releasefiles.releaseID, releasefiles.`name`"; +} else { + $query = "SELECT releasefiles.`name` AS rname, releasefiles.size, releases.*, groups.`name` AS gname FROM releasefiles INNER JOIN releases ON releasefiles.releaseID = releases.ID INNER JOIN groups ON releases.groupID = groups.ID WHERE releases.categoryID IN ( $thecategory ) ORDER BY releasefiles.releaseID, releasefiles.`name`"; +} + +$res = $db->queryDirect($query); + +echo "doing part 3\n"; + +while ($row = $db->getAssocArray($res)) +{ +// trigger_error("doing part 3".$row['ID']); + if(preg_match('/\.([^\.]{3,4})$/', $row['rname'], $ext)) + { + $ext[1] = strtolower($ext[1]); + + echo "ext = ".$ext[1]." ".$row['guid']."\n"; +// var_dump($ext); + switch ($ext[1]) + { + case 'epub': + case 'mobi': + $title = preg_split("/ \- /", $row['rname']); + $author = preg_replace('/(\.[^\.]+)/', '', $title[1]); + + $tmp = preg_replace('/'.$row['name'].'/', '', $title[0]); + $tmp = preg_split('/\\\\/', $tmp, 0, PREG_SPLIT_NO_EMPTY); + + + + echo "author: ".$author." title: ".$tmp[count($tmp)-1]."\n"; + + $bookId = findbookid ($author, $tmp[count($tmp)-1]); + + $title1 = $tmp[count($tmp)-1]; + + echo $bookId."\n"; + + if ($bookId == 0) + { + $bookId = findbookid ($tmp[count($tmp)-1], $author); + echo "inverse ".$bookId."\n"; + + $title1 = $author; + $author = $tmp[count($tmp)-1]; + + } + + $title1 = matchnames($row['name'], $author.' - '.$title1); + + if ($bookId != 0) + $ok = dodbupdate($row['ID'], 7020, $title1, $bookId, 'book'); + else + $ok = dodbupdate($row['ID'], 7020, $title1); + + + case 'avi': + case 'mkv': + case 'mp4': + case 'iso': + case 'wmv': + case 'mpg': + case 'mov': + case 'm4v': + $tmp = str_replace('/', ' ', $row['rname']); + $tmp = preg_replace("/([^\\\\]+?)\\\\(\\1)/", "\\2", $tmp ); + $tmp = preg_replace("/".preg_quote(str_replace('/', ' ', $row['name']))."/", "", $tmp); + $tmp = preg_replace("/\\\\/", " ", $tmp); + $tmp = stripname($tmp); + + $tvrage = new TVRage(true); + $parsed = $tvrage->parseNameEpSeason($tmp); + + unset($tvrage); + echo "name = ".$tmp."\n"; + + $nfo = $tmp."\n"; + + var_dump($parsed); + + matchvideo($row, $nfo); + + break; + + + default: + break; + } + + } + +} + +echo "all done\n"; + +unset($res); +unset($row); +unset($matches); + +if (!isset($argv[1])) +{ + $movie = new Movie(); + $movie->processMovieReleases(); + $movie->updateUpcoming(); + + $music = new Music(true); + $music->processMusicReleases(); + + $book = new Book(true); + $book->processBookReleases(); + + $anidb = new AniDB(true); + $anidb->animetitlesUpdate(); + $anidb->processAnimeReleases(); + + $tvrage = new TVRage(true); + $tvrage->processTvReleases(true); + + $thetvdb = new TheTVDB(true); + $thetvdb->processReleases(); + + echo "cleaning 5000\n"; + + $query = "update releases set releases.categoryID= 5060 WHERE imdbID IN ( SELECT movieinfo.imdbID FROM movieinfo WHERE movieinfo.genre REGEXP 'sport' AND NOT movieinfo.genre REGEXP 'comedy' AND NOT movieinfo.genre REGEXP 'romance' AND NOT movieinfo.genre REGEXP 'drama' )"; + + $db->query($query); + + $query = "update releases set releases.categoryID= 5000 WHERE imdbID IN ( SELECT movieinfo.imdbID FROM movieinfo WHERE genre REGEXP 'tv|talk\-show|reality|episode' ) AND categoryID NOT IN ( SELECT ID FROM category WHERE parentID = 5000 )"; + + $db->query($query); + + $query = "UPDATE `releases` SET `categoryID`=2050 WHERE (`categoryID` in (SELECT ID FROM category WHERE parentID = 8000 and `imdbID` > 0) OR `categoryID` = 2000) AND size > 10500000000"; + + $db->query($query); + + $query = "UPDATE `releases` SET `categoryID`=2040 WHERE (`categoryID` in (SELECT ID FROM category WHERE parentID = 8000 and `imdbID` > 0) OR `categoryID` = 2000) AND size > 2500000000"; + + $db->query($query); + + $query = "UPDATE `releases` SET `categoryID`=2030 WHERE (`categoryID` in (SELECT ID FROM category WHERE parentID = 8000 and `imdbID` > 0) OR `categoryID` = 2000) AND size > 500000000"; + + $db->query($query); + + $query = "UPDATE `releases` SET `categoryID`=2020 WHERE (`categoryID` in (SELECT ID FROM category WHERE parentID = 8000 and `imdbID` > 0) OR `categoryID` = 2000)"; + + $db->query($query); + + $query = "UPDATE `releases` SET `categoryID`=2040 WHERE `categoryID` = 2050 AND size <10000000000"; + + $db->query($query); + + $query = "UPDATE `releases` SET `categoryID`=2030 WHERE `categoryID` = 2040 AND size < 2500000000"; + + $db->query($query); + + $query = "UPDATE `releases` SET `categoryID`=5040 WHERE (`categoryID` in (SELECT ID FROM category WHERE parentID = 8000 and `rageID` > 0) OR `categoryID` = 5000) AND size > 1500000000"; + + $db->query($query); + + $query = "UPDATE `releases` SET `categoryID`=5030 WHERE (`categoryID` in (SELECT ID FROM category WHERE parentID = 8000 and `rageID` > 0) OR `categoryID` = 5000) AND size > 10000000"; + + $db->query($query); + + $query = "UPDATE `releases` SET `categoryID`=5050 WHERE (`categoryID` in (SELECT ID FROM category WHERE parentID = 8000 and `rageID` > 0) OR `categoryID` = 5000)"; + + $db->query($query); + + $query = "UPDATE `releases` SET `categoryID`=5030 WHERE `categoryID` = 5040 AND size < 1500000000"; + + $db->query($query); + + $query = "UPDATE `releases` SET `categoryID`=5050 WHERE `categoryID` = 5030 AND size < 1000000"; + + $db->query($query); + + $query = "UPDATE releases SET categoryID = 5070 WHERE rageID IN ( SELECT tvrage.rageID FROM tvrage WHERE tvrage.genre REGEXP 'animat' )"; + + $db->query($query); + + $query = "update releases set releases.categoryID= 5080 WHERE imdbID IN ( SELECT movieinfo.imdbID FROM movieinfo WHERE genre REGEXP 'docum' )"; + + $db->query($query); + +} +//ALTER TABLE `movieinfo` CHANGE `genre` `genre` VARCHAR( 256 ) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL + +?> diff --git a/ugo/misc_sorter_threaded.php b/ugo/misc_sorter_threaded.php index f1e5645be..b6f8c9bb0 100644 --- a/ugo/misc_sorter_threaded.php +++ b/ugo/misc_sorter_threaded.php @@ -1,138 +1,140 @@ -query($query); - -$thecategory = $res[0]['ID']; - -unset($res[0]); - -foreach($res as $r) - $thecategory = $thecategory.", ".$r['ID']; - -$query = "SELECT releases.ID, releases.`name` FROM releases WHERE releases.categoryID IN ( $thecategory )"; - -$theList = $db->query($query); -unset($db); - -$theCount = count($theList); - -$ps = new PowerProcess(); -$ps->RegisterCallback('psUpdateComplete'); -$ps->maxChildren = 24; -$ps->tickCount = 10000; // value in usecs. change this to 1000000 (one second) to reduce cpu use -$ps->threadTimeLimit = 0; // Disable child timeout - -$tim = microtime(true) - $time; -echo "time = ".$tim."\n"; - - -echo "\nToday will be going over $theCount releases\n"; -echo str_pad($theCount, 7, " ", STR_PAD_LEFT)."\t"; - -while ($ps->RunControlCode()) -{ - // Start the parent loop - $listcount = count($theList); - if ($listcount) - { - // We still have groups to process - if ($ps->SpawnReady()) - { - // Spawn another thread - $ps->threadData = array_pop($theList); -// echo "[Thread-MASTER] Spawning new thread. Still have " . count($theList) ." posts to sort after this\n"; - $ps->spawnThread(); - } - else - { - // There are no more slots available to run - //$ps->tick(); - //echo ".\n"; - } - } - else - { - // No more groups to process - echo "\nNo more to process - Initiating shutdown\n"; - $ps->threadTimeLimit = 200; - do { - $ps->tick(); - } while ($ps->myThreads); - $ps->Shutdown(); - echo "\nShutdown complete\n"; - $tim = microtime(true) - $time; - echo "final processing time = ".$tim."\n"; - - } -} -$tim = microtime(true) - $time; -//echo "time = ".$tim."\n"; -unset($theList); - -if ($ps->RunThreadCode()) -{ - $post = $ps->threadData; - - $thread = sprintf("%05d",$ps->GetPID()); - -// echo "[Thread-{$thread}] Begining sorting for {$post['name']}\n"; - - $param = $post['ID']; - - $dir = dirname(__FILE__); - $file = 'misc_sorter3.php'; - - $output = shell_exec("php {$dir}/{$file} {$param}"); - - $count = $theCount - $listcount; - $countpct = $count / $theCount; - - if ($listcount % 100 == 0 && $listcount > 0) - { - $tim = microtime(true) - $time; - echo "\t\tt = ".str_pad(number_format($tim, 1), 8, " ", STR_PAD_LEFT); - $tim = ((1 + 0.3 * (1 - $countpct)) * ($listcount * $tim) / $count) + time(); -// $tim = number_format(($listcount * $tim) / 60 / $count, 1); - if ($countpct > 0.1 || $count > 1500) - echo "\t".date('H:i:s', $tim); -// echo "\t".$tim."m to go" ; - echo "\n".str_pad($listcount, 7, " ", STR_PAD_LEFT)."\t"; - - } - if ($listcount % 5 == 0) - echo " ."; - - -// echo "[Thread-{$thread}] Completed update for {$post['name']}\n"; - $tim = microtime(true) - $time; -// echo "time = ".$tim."\n"; -} - -// Exit to call back to parent - Let know that child has completed -exit(0); - -// Create callback function -function psUpdateComplete() -{ - echo "[Thread-MASTER] Threaded sorting process complete\n"; -} - -?> +query($query); + +$thecategory = $res[0]['ID']; + +unset($res[0]); + +foreach($res as $r) + $thecategory = $thecategory.", ".$r['ID']; + +$query = "SELECT releases.ID, releases.`name` FROM releases WHERE releases.categoryID IN ( $thecategory )"; + +$theList = $db->query($query); +unset($db); + +$theCount = count($theList); + +$ps = new PowerProcess(); +$ps->RegisterCallback('psUpdateComplete'); +$ps->maxChildren = 24; +$ps->tickCount = 10000; // value in usecs. change this to 1000000 (one second) to reduce cpu use +$ps->threadTimeLimit = 0; // Disable child timeout + +$tim = microtime(true) - $time; +echo "time = ".$tim."\n"; + + +echo "\nToday will be going over $theCount releases\n"; +echo str_pad($theCount, 7, " ", STR_PAD_LEFT)."\t"; + +while ($ps->RunControlCode()) +{ + // Start the parent loop + $listcount = count($theList); + if ($listcount) + { + // We still have groups to process + if ($ps->SpawnReady()) + { + // Spawn another thread + $ps->threadData = array_pop($theList); +// echo "[Thread-MASTER] Spawning new thread. Still have " . count($theList) ." posts to sort after this\n"; + $ps->spawnThread(); + } + else + { + // There are no more slots available to run + //$ps->tick(); + //echo ".\n"; + } + } + else + { + // No more groups to process + echo "\nNo more to process - Initiating shutdown\n"; + $ps->threadTimeLimit = 200; + do { + $ps->tick(); + } while ($ps->myThreads); + $ps->Shutdown(); + echo "\nShutdown complete\n"; + $tim = microtime(true) - $time; + echo "final processing time = ".$tim."\n"; + + } +} +$tim = microtime(true) - $time; +//echo "time = ".$tim."\n"; +unset($theList); + +if ($ps->RunThreadCode()) +{ + $post = $ps->threadData; + + $thread = sprintf("%05d",$ps->GetPID()); + +// echo "[Thread-{$thread}] Begining assembly processing for post {$post['ID']}\n"; + + $param = $post['ID']; + + $dir = dirname(__FILE__); + $file = 'misc_sorter3.php'; + + $output = shell_exec("php {$dir}/{$file} {$param}"); + + $count = $theCount - $listcount; + $countpct = $count / $theCount; + $cleanpct = str_pad(number_format(($countpct * 100), 1), 7, " ", STR_PAD_LEFT); + + if ($listcount % 250 == 0 && $listcount > 0) + { + $tim = microtime(true) - $time; + echo "\t\t".$cleanpct."% = ".str_pad(number_format($tim, 1), 8, " ", STR_PAD_LEFT); + $tim = ($listcount * $tim) / $count + time(); +// $tim = number_format(($listcount * $tim) / 60 / $count, 1); + if ($countpct > .95 || ($count > 1000 && ($listcount+250) % 1000 == 0)) + echo "\t".date('M jS Y H:i:s', $tim); +// echo "\t".$tim."m to go" ; + echo "\n".str_pad($listcount, 7, " ", STR_PAD_LEFT)."\t"; + + } elseif ($listcount % 10 == 0) + echo "."; + + +// echo "[Thread-{$thread}] Completed update for post {$post['ID']}\n"; + $tim = microtime(true) - $time; +// echo "time = ".$tim."\n"; +} + +// Exit to call back to parent - Let know that child has completed +exit(0); + +// Create callback function +function psUpdateComplete() +{ + echo "[Thread-MASTER] Threaded sorting process complete\n"; +} + +?> +