#!/bin/bash

grabber_primary_options () {
	theme_name=dvd
	Link_or_Application=Link
	SOURCE_type=bookmarks
	SOURCE_filter=imdb.com/title/
	check=no
}

grabber_secondary_options () {
	avatar_name=$index.$avatar_title
	avatar_filename=$(echo "$URL" | cut -d\/ -f5)
	icon_NAME=$avatar_filename
	Launcher="avatar-factory -al $grabber_name --URL \"$URL\" --avatar \"$folder2save/$avatar_filename.desktop\" --name \"$avatar_title\" --title \"$avatar_title\" --icon \"$icons_PATH/$icon_NAME.png\" --DND"
}

get_grabber_picture () {

	if [[ $check != no || ! -f $icons_PATH/$icon_NAME-NO-COVER.png ]]; then
		web=$(wget -U firefox -qO - "$URL")
		grabber_picture=$(echo "$web" | grep -A1 -i '<div class="photo">' | sed -e 1d -e 's|.*src="||' -e 's/".*//')

		if [[ -z $grabber_picture ]]; then
			photo_url=$(echo "$web" | grep -m 1 '<div class="media_strip_thumb">' | sed -e 's|.*href="||' -e 's/".*//')
			grabber_picture=$(wget -U firefox -qO - "http://www.imdb.com$photo_url" | grep -A1 '<table id="principal">' | sed -e 1d -e 's|.*src="||' -e 's/".*//')
		fi
	fi


    #blank cover:
	if [[ -n $grabber_picture ]]; then
		if [[ -f $icons_PATH/$icon_NAME-NO-COVER.png ]]; then
			force_avatar_build=yes
		fi
	else
		if [[ -f $icons_PATH/$icon_NAME-NO-COVER.png ]]; then
			grabber_picture=
			temporary_icon=yes
		else
			grabber_picture=$avatar_factory_PATH/imdb-nocover.gif
		fi

		icon_NAME=$icon_NAME-NO-COVER
	fi
}
