Method to solve this integral with algebraic and trigonometric terms

I have the definite integral $\displaystyle\int_{0}^{\pi }\frac{x^2 \cos(x)}{(1+ \sin(x))^2}\,dx.$
Since there are both algebraic and trigonometric functions in the numerator, I don't know what substitution to make. Can someone tell the method of solving the above integral (and not the complete solution). I don't want the antiderivative, only the definite integral.

Note: The answer is $\pi(2-\pi).$

Hint. By integration by parts, $$\int_{0}^{\pi }\frac{x^2 \cos(x)}{(1+\sin(x))^2}dx=-\left[\frac{x^2}{1+\sin (x)}\right]_0^{\pi}+2\int_{0}^{\pi }\frac{x }{1+\sin (x)}dx.$$ For the second integral use the symmetry $\sin(\pi-x)=\sin(x)$ and then let $t=\tan\left(\frac{x}{2}\right)$.
• If you don't want to use integration by parts, first perform the change of variable $y=\pi-x$. $\cos(\pi-x)=-\cos x$. – FDP Jun 20 '18 at 19:28
• Are there some non-trivial consequences in terms of the Fourier series of $x^2$ and $\frac{\cos x}{(1+\sin x)^2}$? – Jack D'Aurizio Jun 20 '18 at 19:33