[App] SamyGO Movie Thumbnails

Here are software that related with Samsung B series TVs. Like hex editors, new version of BusyBox or internal software, app programs that will run in your TV hardware.:!:This forum is NOT FOR USER QUESTIONS or Problems.

User avatar
juusso
SamyGO Moderator
Posts: 10125
Joined: Sun Mar 07, 2010 6:20 pm

Re: [App] SamyGO Movie Thumbnails

Post by juusso » Wed Mar 02, 2011 3:23 pm

arokun,

Your script isn`t working because of @CRLF symbols at the end of row in config.ini and telnet.sh file (windows editor?)
After editing everything works fine.
telnet.sh:

Code: Select all

#!/bin/sh
#!SamyGO Movie Thumbnails v2.6
# Generates Samsung B series TV movie thumbnails from movie covers in disk, IMDB and/or Google.
# Configuration is done modifying config.ini
# Tested on Samsung B650 with T-CHL7DEUC_002005 firmware
#
# For each movie in a USB disk unit (dtv/usb/*) with a jpg at the same folder with  
# identical or similar name(without particles # after a "." like "AC3", "English...." 
# or supressing the episode "xepisode number episode title"),
# or supressing the part number "[Part..." ..
# generates a thumbnail (.jpg with same name as movie and extension = movie size mod 2^32 /1000)
# in folder /mtd_contents/Vn n=0,1.... To determine n checks wich of those folders exists and 
# already have a thumbnail of a movie contained in the USB disk unit. 
# If there is not .jpg in USB disk, then tries to find it in IMDB and Google using wget
#
# Author: Olivia D. 
# Game packing & icon: moras86 and erdem_ua
# Code for thumbnails downloading from imdb: ubuntulife.wordpress.com
# Code for thumbnails downloading from google images: krazyworks.com
#=======================================================================================================
# LOAD INI FILE WITH PARAMETERS
ScriptPath="${0%/*}"
if [ "${ScriptPath##*.}" == "sh" ]; then ScriptPath="."; fi
source "$ScriptPath/config.ini"
#=======================================================================================================
# Redirect output to Thumbnails.log
rm "$ScriptPath"/Thumbnails.log 2> /dev/null
exec > "$ScriptPath"/Thumbnails.log 2>&1
# Check if LAN connection is on. If not, do not try to get thumbnails from internet
LANOFF=`ifconfig | grep "packets:0 "`
if [ ! "$LANOFF" == "" ] 
then
	echo "** LAN not available -> will not try to download thumbnails from Internet"
	SearchIMDB=false
	SearchGoogle=false
fi
#
# Get the first unit that is connected (Source of thumbnails to be generated) = first file in /dtv/usb that
# is not log or netlog files
for a in `ls /dtv/usb | grep -v "log" ` 
do
	if [ "$SourceDiskConfig" = "" ]
	then
		SourceDisk="/dtv/usb/$a"
		ReturnAfter=0		
	else
		SourceDisk="/dtv/usb/$SourceDiskConfig"
		ReturnAfter=1
	fi	
	
	echo "Generate thumbnails for devices $SourceDisk"
	echo ""

	if [ "$SourceFolderConfig" = "" ]
	then
		Source="$SourceDisk"
	else
		Source="$SourceDisk/$SourceFolderConfig"
	fi
	
	echo "Source:$Source" 
	echo ""
	
	if [ ! -d $Source ] 
	then
		echo "Incorrectly set parameters."
		echo "Please edit config.ini"
		break
	fi


	# If V is not informed
	if [ "$VConfig" = "" ]; 
	then
		V=""
		for i in "$Source"*  "$Source"*/* , "$Source"*/*/* , "$Source"*/*/*/* , "$Source"*/*/*/*/* , "$Source"*/*/*/*/*/*
		do
			case ${i##*.} in 
				avi | AVI | mkv | MKV | asf | ASF | wmv | WMV | mp4 | MP4 | "3gp" | "3GP" | vro | VRO | vob | VOB | mpg | MPG |  mpeg | MPEG | ts | TS )	
				FirstFile="${i#$Source*}"
				FirstFile=${FirstFile%.*}
				echo $FirstFile
				for j in `ls -1 /mtd_contents/ | grep "V"` #for each V folder in mtd_contents...
				do
					echo "/mtd_contents/$j/$SourceFolderConfig$FirstFile".*
					x=`ls "/mtd_contents/$j/$SourceFolderConfig$FirstFile".* 2> /dev/null ` 
					if [ ! "$x" = "" ]
					then
						V="$j"
						echo "Found >>>>> V = $j"
						break
					fi
				done
				if [ ! "$V" = "" ]
				then
					break
				fi
			;;
			esac
		done

		if [ "$V" = "" ]
		then
			echo "Not found thumbnail to identify V folder"
			echo "Please edit config.ini"
			exit 0
		fi
	else
		V=$VConfig
	fi
	
	
	Destination="/mtd_contents/$V/$SourceFolderConfig"
	echo "Destination:$Destination" 
	echo ""
	
	# Clean thumbnails at destination if that option is true
	if [ "$SubstituteThumbnails" == true ] ;
	then
		echo "Removing old thumbnails in $Destination ......" 
		rm -R "$Destination"
	fi
	
	#
	# For all the subdirectories of the USB disk unit in different depths create thumbanils of the movies found there
	echo "Generating new thumbnails in $Destination ......"
	echo ""
	let "N=0"
	for i in "$Source"*  "$Source"*/* , "$Source"*/*/* , "$Source"*/*/*/* , "$Source"*/*/*/*/* , "$Source"*/*/*/*/*/*
	do
		Extension=${i##*.} #removes longest match of a *. at the begining
		case "$Extension" in
			avi | AVI | mkv | MKV | asf | ASF | wmv | WMV | mp4 | MP4 | "3gp" | "3GP" | vro | VRO | vob | VOB | mpg | MPG |  mpeg | MPEG | ts | TS )
				MovieDir=${i%/*} #removes shortest match of /* at the end .
				SourceLength=${#Source}
				SourceLength=`expr $SourceLength + 1`
				ThumbnailDir="$Destination"`expr substr "$MovieDir" $SourceLength 100`
				Filename=${i%.*} # removes shortest match of .* at the end - supress extension
				Filename=${Filename##*/} # removes longest match of */ at the begining - supress all paths
				
				# CALCULATION OF MOVIESIZE MOD 2^32 / 100  (2^32 = 4294967296)
				# Because Bash works with signed integers of 32 bits, the maximum number is +2147483647 (2^32/2-1)
				# then the calculation is performed separating both numbers in thousands and units
				Str=`ls -l "$i"`
				MovieSize=`echo $Str | cut -d" " -f5` # Movie size is the 5th field separated by " " 
				MovieSizeLength_3=${#MovieSize}
				let "MovieSizeLength_3=$MovieSizeLength_3-3"
				MovieSizeThousands=`expr substr "$MovieSize" 1 $MovieSizeLength_3`
				MovieSizeUnits=`expr "$MovieSize" : '.*\([0-9][0-9][0-9]\)'` # 3 last digits
				while [ "$MovieSizeThousands" -gt "4294967" -o "$MovieSizeThousands" -eq "4294967" -a "$MovieSizeUnits" -ge "296" ]
				do
					MovieSizeThousands=`expr $MovieSizeThousands - 4294967`
					if [ "$MovieSizeUnits" -ge "296" ]
					then
						MovieSizeUnits=`expr $MovieSizeUnits - 296`
					else
						MovieSizeUnits=`expr 1000 + $MovieSizeUnits - 296`
						MovieSizeThousands=`expr $MovieSizeThousands - 1`
					fi
				done
				ThumbnailExt="$MovieSizeThousands"
			if [ $MovieSizeThousands -le "300000" ]; then break; fi
				#
				# Only generate new thumbnail if SubstituteThumbnails=True or there was not a thumbnail for that movie
				if [ "$SubstituteThumbnails" == true -o ! -e "$ThumbnailDir/$Filename.$ThumbnailExt" ]
				then
					#
					# COPY JPG AT DESTINATION if the Source contains a jpg named like the movie at the same folder...
					#first jpg in same folder ended with .jpg or "."something.jpg
					JpgFile=`ls "$MovieDir/${Filename%%.*}".*jpg 2> /dev/null | head -n 1` 
					# if not found try to find a jpg supressing the part number or episode number: 
					# multipart movie: movie [xxxx... -> movie.jpg 
					if [ "$JpgFile" = "" ]; then JpgFile=`ls "$MovieDir/${Filename%%" "\[*}".*jpg 2> /dev/null | head -n 1` ; fi
					# serie nseasonxnepisode -> serie nseason.jpg 
					if [ "$JpgFile" = "" ]; then JpgFile=`ls "$MovieDir/${Filename%%x[0-9]*}".*jpg 2> /dev/null | head -n 1` ; fi
					if [ ! "$JpgFile" = "" ] #if found a jpg with similar name of the movie in USB Disk...
					then
						## Create directory if it does not exists
						if [ ! -d "$ThumbnailDir" ]; then mkdir -p "$ThumbnailDir" ; fi
						cp "$JpgFile" "$ThumbnailDir/$Filename.$ThumbnailExt"
						let "N=N+1"
						echo "  Generated thumbnail $N from disk:$ThumbnailDir/$Filename.$ThumbnailExt"
					else
						SearchName=${Filename%%.*} #remove anything that is at the right of a "."
						SearchName=${SearchName%%" "\[*} #remove anything that is at the right of a "["
						SearchName=${SearchName%%x[0-9]*} #remove anything that is at the right of a "xDIGIT"
						#Try to find a movie thumbnail in IMDB
						if [ "$SearchIMDB"  == true ]
						then
							"$ScriptPath"/wget "http://www.imdb.com/find?s=all&q=${SearchName}" -O "$ScriptPath"/index.txt -q
							IDTITLE=`cat "$ScriptPath"/index.txt  | grep "href=\"/title/tt" | head -n 1 | cut -d"\"" -f4 | cut -d"/" -f3`
							IMAGE=""
							if [ ! "$IDTITLE"  == "" ] 
							then
								"$ScriptPath"/wget "http://www.imdb.com/title/$IDTITLE/" -O "$ScriptPath"/index.txt -q
								IMAGE=`cat "$ScriptPath"/index.txt|sed 's/img src="/\nX/g' |sed 's/.jpg/.jpg\n/g' | grep "Xhttp://ia.media-imdb.com/"`
								IMAGE=${IMAGE#*X}
							fi
							if [ ! "$IMAGE"  == "" ] 
							then
								if [ ! -d "$ThumbnailDir" ]; then mkdir -p "$ThumbnailDir" ; fi
								"$ScriptPath"/wget "$IMAGE" -O "$ThumbnailDir/$Filename.$ThumbnailExt" -q
								let "N=N+1"
								echo "  Generated thumbnail $N from IMDB:$ThumbnailDir$Filename.$ThumbnailExt"
							fi
						fi
						if [ "$SearchGoogle" == true -a "$IMAGE"  == "" ]
						then
							#Try to find a movie thumbnail in Google Images
							URL="http://images.google.com/images?q=${SearchName}+"DVD"&hl=en&lr=&safe=off&sa=G"
							"$ScriptPath"/wget -U Mozilla -O "$ScriptPath/index.txt" "$URL" -e robots=off -q
							URL=`cat "$ScriptPath/index.txt" | sed 's/src=/\n/g' | sed 's/.jpg/.jpg\n/g' | grep gstatic | head -n 1`
							if [ ! "$URL"  == "" ]
							then
								if [ ! -d "$ThumbnailDir" ]; then mkdir -p "$ThumbnailDir" ; fi							
								"$ScriptPath"/wget -U Mozilla "$URL" -O "$ThumbnailDir/$Filename.$ThumbnailExt"  -e robots=off -q
								let "N=N+1"
								echo "  Generated thumbnail $N from Google:$ThumbnailDir$Filename.$ThumbnailExt"
							fi
						fi
						
						# if nothing found in disk or Internet
						if [ "$IMAGE"  == "" -a "$URL"  == "" ]; then echo "** Not found:$MovieDir/$Filename.jpg"; fi
					fi
				fi
			;;
		esac
	done
	echo ""
	echo "**Generated: $N thumbnails in $Destination from $Source, IMDB and Google Images"
	echo ""
	
	if [ $ReturnAfter -eq 1 ]; then exit 0; fi

done
exit 0
config.ini

Code: Select all

# PARAMETERS
# If true => subsitutes previous thumbnails; false=keeps previous thumnails
SubstituteThumbnails=true

# Disk that contains the movies. If blank=explore all devices.
# For example: SourceDiskConfig="sdg1"
SourceDiskConfig="sda1"

# Folder of USB disk that contains the movies. If blank=explore whole disk
# Add to a path without "/dtv/usb/" and DEVICES and a slash at the end.
SourceFolderConfig="" 

# Folder of mtd_contents where the thumbnails of this USB disk are. If blank, explore all
# For example: VConfig="V6" 
VConfig="" 

# If true => searches in IMDB if there is no moviename.jpg in USB disk
SearchIMDB=true

# If true => searches in Google if there is no moviename.jpg in USB disk
SearchGoogle=true
LE40B653T5W,UE40D6750,UE65Q8C
Have questions? Read SamyGO Wiki, Search on forum first!
FFB (v0.8), FFB for CI+ . Get root on: C series, D series, E series, F series, H series. rooting K series, exeDSP/exeTV patches[C/D/E/F/H]

DO NOT EVER INSTALL FIRMWARE UPGRADE

User avatar
juusso
SamyGO Moderator
Posts: 10125
Joined: Sun Mar 07, 2010 6:20 pm

Re: [App] SamyGO Movie Thumbnails

Post by juusso » Wed Mar 02, 2011 5:36 pm

Sure your problem is windows related. Under windows use Notepad++
choose ANSI encoding.
LE40B653T5W,UE40D6750,UE65Q8C
Have questions? Read SamyGO Wiki, Search on forum first!
FFB (v0.8), FFB for CI+ . Get root on: C series, D series, E series, F series, H series. rooting K series, exeDSP/exeTV patches[C/D/E/F/H]

DO NOT EVER INSTALL FIRMWARE UPGRADE

User avatar
juusso
SamyGO Moderator
Posts: 10125
Joined: Sun Mar 07, 2010 6:20 pm

Re: [App] SamyGO Movie Thumbnails

Post by juusso » Thu Mar 03, 2011 10:16 pm

run script manually in debug mode:

Code: Select all

sh -x /mtd_tlib/GGame/../telnet.sh
give us output.
LE40B653T5W,UE40D6750,UE65Q8C
Have questions? Read SamyGO Wiki, Search on forum first!
FFB (v0.8), FFB for CI+ . Get root on: C series, D series, E series, F series, H series. rooting K series, exeDSP/exeTV patches[C/D/E/F/H]

DO NOT EVER INSTALL FIRMWARE UPGRADE

Post Reply

Return to “[B] Software”