On a little semicircle $\;C_\epsilon\;$ (upper) of radius $\;\epsilon>0\;$ about zero, you indeed have to take the limit $\;\epsilon\to0\;$ and then you get by the corollary to the lemma here , that
$$\lim_{\epsilon\to0}\int_{C_\epsilon}\frac{(z+1)^2}{z(z^2+4)^2}dz=\pi i\,\text{Res}\,(f)_{z=0}=\frac{\pi i}{16}$$
The rest is standard: the upper semicircle of radius $\;R>>0\;$ so that you only need the poles with positive imaginary part, take residues, limits and etc.
Added on request: The actual "problem" is to deal with the integral on the arc $\;\gamma_R:=\{z=Re^{it}\;/\;0<t<\pi\}\;$ , but either the L-M (Estimmation Lemma) or Jordan's Lemma solve that and this part of the integral, in this case, tends to zero when $\;R\to\infty\;$.
Also, the residue at $\;z=2i\;$, which is a double pole (observe that we don't care about the other pole $\;z=-2i\;$, as we are on the upper semiplane) is
$$\text{res}\,(f)_{z=2i}=\lim_{z\to 2i}\left((z-2i)^2\frac{(z+1)^2}{z(z^2+4)^2}\right)'=\lim_{z\to2i}\left(\frac{(z+1)^2}{z(z+2i)^2}\right)'$$$${}$$
$$=\lim_{z\to2i}\frac{2z(z+1)(z+2i)-(z+1)^2\left((z+2i)+2z\right)}{z^2(z+2i)^3}=\frac{4i(1+2i)\cdot4i-(1+2i)^2(4i+4i)}{(-4)(-64i)}=$$$${}$$
$$=\frac{-16-32i-(-3+4i)\cdot8i}{256i}=\frac{-16-32i+24i+32}{256i}=-\frac1{32}-\frac i{16}$$
so we get, calling $\;C\;$ the whole simple, closed contour:
$$-\frac1{32}-\frac i{16}=\oint_{C}f(z)dz=\int_{-R}^{-\epsilon}f(x)dx-\int_{\gamma_\epsilon}f(z)dz+\int_\epsilon^Rf(x)dx+\int_{\gamma_R}f(z)dz$$
Observe the minus sign before the integral around zero because when we go from $\;-R\to R\;$ that half semicircle's integration is done in the negative direction! Well, now just take the double limit and use Cauchy's Theorem:
$$\lim_{R\to\infty,\,\epsilon\to0}\left(-\frac1{32}-\frac i{16}\right)=\frac1{2\pi i}\lim_{R\to\infty,\,\epsilon\to0}\int_Cf(z)dz=\frac1{2\pi i}\left(\int_{-\infty}^\infty f(x)dx-\frac{\pi i}{16}\right)\implies$$$${}$$
$$\implies\int_{-\infty}^\infty\frac{(x+1)^2}{x(x^2+4)^2}dx=\frac\pi8 $$