How to prove $\int_0^\pi\biggl |\sum_{i=0}^k \frac{a_i\sin(i+\frac{1}{2})x}{2\sin \frac{1}{2}x}\biggr| \, dx \le c(k+1)$ for some constant $c$? Let $|a_i|\le1$, prove that $$\int_0^\pi \biggl|\sum_{i=0}^k \frac{a_i\sin(i+\frac{1}{2})x}{2\sin \frac{1}{2}x}\biggr|\,dx \le c(k+1)$$ for some constant $c$.
I tried to solve the question as follows
$$\int_0^\pi \biggl|\sum_{i=0}^k \frac{a_i\sin(i+\frac{1}{2})x}{2\sin \frac{1}{2}x}\biggr| \, dx \le 
\int_0^\pi \sum_{i=0}^k \biggl| \frac{a_i\sin(i+\frac{1}{2})x}{2\sin \frac{1}{2}x}\biggr|\,dx \\=
\sum_{i=0}^k|a_{i}|\int_0^\pi \biggl| \frac{\sin(i+\frac{1}{2})x}{2\sin \frac{1}{2}x}\biggr|\,dx \le
\sum_{i=0}^k\int_0^\pi \biggl| \frac{\sin(i+\frac{1}{2})x}{2\sin \frac{1}{2}x}\biggr| \, dx.$$
Then it looks like a classic equality about Lebesgue constant,
$$\frac{1}{\pi}\int_{-\pi}^\pi \biggl| \frac{\sin(i+\frac{1}{2})x}{2\sin \frac{1}{2}x}\biggr|\,dx=\frac{4}{\pi^2}\log i+O(1).$$
However, it didn't work. The above process of estimation doesn't seem to be careful enough.
How to make more careful and effective estimates to solve the question?
Thank you so much!

On the other forum, I found the answer to this question.The website link is here, https://www.zhihu.com/question/410940277/answer/1400850373.
I copied the proof roughly here.
$$\int_0^\pi \biggl|\sum_{i=0}^k \frac{a_i\sin(i+\frac{1}{2})x}{2\sin \frac{1}{2}x}\biggr| \, dx = \int_0^\frac{\pi}{k+1} \biggl|\sum_{i=0}^k \frac{a_i\sin(i+\frac{1}{2})x}{2\sin \frac{1}{2}x}\biggr| \, dx+\int_\frac{\pi}{k+1}^\pi \biggl|\sum_{i=0}^k \frac{a_i\sin(i+\frac{1}{2})x}{2\sin \frac{1}{2}x}\biggr| \, dx$$
It is easy to get that $$\frac{\sin(i+\frac{1}{2})x}{2\sin \frac{1}{2}x} \le i+\frac12.$$
Then $$\int_0^\frac{\pi}{k+1} \biggl|\sum_{i=0}^k \frac{a_i\sin(i+\frac{1}{2})x}{2\sin \frac{1}{2}x}\biggr| \, dx \le \frac{\pi}{k+1}\sum_{i=0}^{k}|a_i|\biggl(i+\frac12\biggr) \le \frac\pi2(k+1).$$
According to Cauchy-Schwarz inequality,we have
$$\int_\frac{\pi}{k+1}^\pi \biggl|\sum_{i=0}^k \frac{a_i\sin(i+\frac{1}{2})x}{2\sin \frac{1}{2}x}\biggr| \, dx \le \sqrt{\int_\frac{\pi}{k+1}^\pi \biggl(\frac{1}{2\sin \frac{1}{2}x}\biggr)^2 \, dx}\sqrt{\int_\frac{\pi}{k+1}^\pi \biggl(\sum_{i=0}^k a_i\sin(i+\frac{1}{2})x\biggr)^2 \, dx}.$$
After calculation,we get that $$\int_\frac{\pi}{k+1}^\pi \biggl(\frac{1}{2\sin \frac{1}{2}x}\biggr)^2 \, dx \lt 2k+2,$$
and $$\int_\frac{\pi}{k+1}^\pi \biggl(\sum_{i=0}^k a_i\sin(i+\frac{1}{2})x\biggr)^2 \, dx \le \int_{-\pi}^\pi \biggl(\sum_{i=0}^k a_i\sin(i+\frac{1}{2})x\biggr)^2 \, dx=\pi\sum_{i=0}^{k}a_i^2 \le \pi(k+1).$$
Therefore, $$\int_\frac{\pi}{k+1}^\pi \biggl|\sum_{i=0}^k \frac{a_i\sin(i+\frac{1}{2})x}{2\sin \frac{1}{2}x}\biggr| \, dx \le \sqrt{2\pi}(k+1).$$
In brief, we come to the conclusion $$\int_0^\pi \biggl|\sum_{i=0}^k \frac{a_i\sin(i+\frac{1}{2})x}{2\sin \frac{1}{2}x}\biggr| \, dx \le (\frac\pi2+\sqrt{2\pi})(k+1).$$
