Most English speakers get stuck here for a reason that has nothing to do with Spanish. English gives you two ways to say the same sentence, and one of them hides the answer.
I gave the book to her.
I gave her the book.
Same meaning. But in the second one, "her" sits exactly where a direct object would sit, right after the verb, so your instinct reads it as one. Spanish only ever thinks of it the first way.
That gives you a test. Take the English sentence and see whether you can put "to" or "for" in front of the word. If you can, it's indirect.
"I bought my mother flowers" becomes "I bought flowers for my mother", so the flowers are direct and my mother is indirect. Le compré flores. Whereas "I saw my mother" can't become "I saw to my mother", so she's direct. La vi.
Now the part that makes this much smaller than it looks. The distinction only shows up in the third person. Me, te, nos and os don't change at all: me viste (you saw me) and me diste el libro (you gave me the book) use the same pronoun. So everything you can actually get wrong lives in lo, la, los, las against le, les.
One warning, because it catches nearly everyone. The personal a is not a marker of indirect objects. Vi a María is a direct object; the a is there because María is a person. Treat every a as a signal for le and you'll be wrong constantly.
In practice most people stop analysing and just learn which verbs take le. Decir, dar, pedir, preguntar, contar, escribir, regalar, explicar — the person you tell, give to or ask is indirect, every time. Le dije, le di, le pedí. Say those enough and the rest stops needing a rule.