Problem : If $$I_{m,n}=\int x^m \mathrm{cosec}^n x\; dx,$$ show that $$(n-1)(n-2)I_{m,n}=(n-2)^2I_{m,n-2}+m(m-1)I_{m-2,n-2}-x^{m-1}\mathrm{cosec}^{n-1}x\left\{m\sin x+(n-2)x\cos x \right\}.$$
By integration by parts,
$$I_{m,n}=\dfrac{x^{m+1}}{m+1}\mathrm{cosec}^n x+\int n\mathrm{cosec}^{n-1} x\; \mathrm{cosec}x\; \cot x\; \dfrac{x^{m+1}}{m+1}\, dx.$$
It seems that this is not the right way to prove the required result.
I developed it like that.
First, by parts we obtain \begin{eqnarray} \mathcal I_{m,n}&=&\int x^m(\csc x)^ndx=\\ &=&-\int x^m(\csc x)^{n-2}d\cot x=\\ &=&-x^m(\csc x)^{n-2}\cot x + \int\cot x\left[mx^{m-1}(\csc x)^{n-2}+\right.\\ & &-\left.(n-2)x^m(\csc x)^{n-2}\cot x\right]dx=\\ &=&-x^m(\csc x)^{n-2}\cot x + m\int x^{m-1}(\csc x)^{n-2}\cot xdx+\\ & & -(n-2)\int x^m(\csc x)^{n-2}(\cot x)^2 dx=\\ &=&-x^m(\csc x)^{n-2}\cot x + m\int x^{m-1}(\csc x)^{n-2}\cot xdx+\\ & & -(n-2)\int x^m(\csc x)^{n-2}\left[(\csc x)^2-1\right] dx=\\ &=&-x^m(\csc x)^{n-2}\cot x + m\int x^{m-1}(\csc x)^{n-2}\cot xdx+\\ & &-(n-2)\mathcal I_{n,m}+(n-2)\mathcal I_{n-2,m}. \end{eqnarray} Thus \begin{eqnarray} (n-1)\mathcal I_{m,n} &=&-x^m(\csc x)^{n-2}\cot x + m\int x^{m-1}(\csc x)^{n-2}\cot xdx+\\ & &+(n-2)\mathcal I_{m,n-2}\tag{1}\label{1}. \end{eqnarray} We can now further develop by parts the second term in the RHS of \eqref{1}, as follows. \begin{eqnarray} (n-1)\mathcal I_{m,n} &=&-x^m(\csc x)^{n-2}\cot x - \frac{m}{n-2}\int x^{m-1}d(\csc x)^{n-2}+\\ & &+(n-2)\mathcal I_{m,n-2}=\\ &=&-x^m(\csc x)^{n-2}\cot x - \frac{m}{n-2}x^{m-1}(\csc x)^{n-2}+\\ & &+\frac{m(m-1)}{n-2}\underbrace{\int x^{m-2}(\csc x)^{n-2}dx}_{\mathcal I_{m-2,n-2}} + (n-2)\mathcal I_{m,n-2}. \end{eqnarray} Multiplying through by $n-2$ gives the desired result, that is \begin{eqnarray} \color{blue}{(n-2)(n-1)\mathcal I_{n,m}} &\color{blue}{=}&\color{blue}{-(n-2)x^m(\csc x)^{n-2}\cot x - mx^{m-1}(\csc x)^{n-2}+}\\ & &\color{blue}{+m(m-1)\mathcal I_{m-2,n-2} + (n-2)^2\mathcal I_{m,n-2}}. \end{eqnarray}