Let $\displaystyle I=\int_{-\infty}^{\infty}\operatorname{sinc}^{2}\left(\frac{x}{4}\right)g(x)\frac{\sin^{2}\left(N\pi x\right)}{\sin^{2}\left(\pi x\right)}$. For this solution, we will assume that $g(x) = \displaystyle \frac{1+\cos\left(\frac{\pi x}{2}\right)}{2}$, $\operatorname{sinc}(x) = \displaystyle \frac{\sin\left(\pi x\right)}{\pi x}$ is the normalized sinc function, and $N \in \mathbb{Z}$. Notice how $\sin^{2}\left(N\pi x\right)=\sin^{2}\left(\left|N\right|\pi x\right)$. For simplicity's sake, let $|N| = K$.
We can use the fact that $\displaystyle \Re\left(\frac{1-e^{2K\pi ix}}{2}\right) = \sin^2(K\pi x)$. Rewriting $I$ gives
$$I = \frac{2}{\pi^{2}}\operatorname{PV}\Re\int_{-\infty}^{\infty}\frac{1-e^{2K\pi ix}}{x^{2}\left(\exp\left(-\frac{i\pi}{2}x\right)+\exp\left(\frac{i\pi}{2}x\right)\right)^{2}}dx$$
(where we somewhat abuse the Cauchy Principal Value definition since $\operatorname{PV}$ mainly concerns one singularity).
Let $f(z) = \displaystyle \frac{1-e^{2K\pi iz}}{z^{2}\left(\exp\left(-\frac{i\pi}{2}z\right)+\exp\left(\frac{i\pi}{2}z\right)\right)^{2}}$. There are second-order poles at $z=0$ and $z=2n+1$ for any $n \in \mathbb{Z}$ that I colored in blue in the picture down below.

Let $\Gamma$ be the huge semicircle of radius $R$ where $R$ is a large even integer so that it's bounded away from the small semicircle. Let $\gamma_{2n+1}$ represent the sequence of small semicircles enclosing their respective poles and let $\gamma_{0}$ be the small semicircle enclosing the pole at the origin. Each semicircle has a sufficiently small radius $\epsilon$ such that the semicircles don't intersect each other.
Using Cauchy's Residue Theorem, we get
$$
\begin{align}
0 &=\sum\int_{\text{orange}} f(z)dz + \sum_{n=-R/2}^{R/2-1}\int_{\gamma_{2n+1}}f(z)dz + \int_{\gamma_0}f(z)dz + \int_{\Gamma}f(z)dz \\
\end{align}
$$
where $\displaystyle \sum \int_{\text{orange}} f(z)dz$ is the sum of the integrals over the orange line segments. Applying $\displaystyle \frac{2}{\pi^2}\Re\operatorname{PV}\lim_{R \to \infty}\lim_{\epsilon \to 0^+}$ to the equation above and doing some algebra, we get
$$I = \frac{2}{\pi}\Re i \sum_{n \in \mathbb{Z}} \operatorname{Res}(f(z), z = 2n+1) + \frac{2}{\pi} \Re i \operatorname{Res}(f(z), z=0) + 0$$
where we can prove that $\displaystyle \lim_{R \to \infty}\int_{\Gamma}f(z)dz = 0$ using the Estimation Lemma.
The first expression is
$$
\begin{align}
I_1 &:= \frac{2}{\pi}\Re i \sum_{n \in \mathbb{Z}} \operatorname{Res}\left(\frac{1-e^{2K\pi iz}}{z^{2}\left(\exp\left(-\frac{i\pi}{2}z\right)+\exp\left(\frac{i\pi}{2}z\right)\right)^{2}}, z = 2n+1\right) \\
&= \frac{2}{\pi}\Re i \sum_{n \in \mathbb{Z}} \frac{1}{(2-1)!}\lim_{z \to 2n+1} \frac{d^{2-1}}{dz^{2-1}}\frac{\left(z-\left(2n+1\right)\right)^{2}\left(1-e^{2K\pi iz}\right)}{z^{2}\left(\exp\left(-\frac{i\pi z}{2}\right)+\exp\left(\frac{i\pi z}{2}\right)\right)^{2}} \\
&= \frac{2}{\pi}\Re i \sum_{n \in \mathbb{Z}} \left(-\frac{2Ki}{\pi\left(2n+1\right)^{2}}\right) \\
&= \frac{4K}{\pi^2}\sum_{n \in \mathbb{Z}} \frac{1}{(2n+1)^2} \\
&= \frac{4K}{\pi^2} \cdot \frac{\pi^2}{4} \\
&= K.
\end{align}
$$
Similarly, you can apply the same kind of process to prove $\displaystyle \frac{2}{\pi} \Re i \operatorname{Res}(f(z), z=0) = K$.
We add those two results together and get $I = 2K = 2|N|$.
scipy.integrate.quad, but thesin(x)^-2behavior makes those problematic. – Dominik Stańczak May 08 '23 at 06:14