How should I repair the cracks in my ceiling before painting?
You have two main issues: 1) crack length of room, and 2) top coat and brown coat separating from scratch coat. 

1) When we see cracks running in the middle of a room, it’s usually from undersized ceiling framing. Lumber bends most at the center of a span. If the lumber is undersized, it will deflect excessively and thus cause a crack in brittle materials like: plaster, ceramic tile, etc. You’ll probably need to sister an additional joist next to the existing joists.)

Before you fix the crack and paint, I’d suggest you verify the ceiling framing is adequate. (There are span tables on the internet that can tell you what size lumber should be used to carry the existing plaster plus any additional plaster (or gypsum board) repairs...or you can ask on this forum giving span, spacing of existing joists, any loads above ceiling, etc.)

2) Plaster is generally a 3 step process. Each layer requires the new layer to bond to the previous layer. Looking at the missing piece, it appears the plaster separating is about 3/8” to 1/2” thick. That means the brown coat (about 3/8” thick) and finish coat (about 1/8” thick) is separating from the scratch coat. 

There is no easy way to repair this problem without removing the brown coat and finish coat. (You can’t just nail it back up because it’ll continue cracking and separating and it will be very uneven.)

Often people choose to remove the worst areas and then install gypsum board over the entire ceiling. However, that adds a great deal of load, but you may need to reinforce the existing ceiling joists anyway.