Hey dude, you playing Rebellion I guess. What race do you play with?
Playing TEC is easiest to beat Pirates with, since if you build 2 Novalith Cannons, you can bombard enemy pirate base(s) from afar (each deals 3500 damage to planet infrastructure, Pirate Base has 6000, so you'll need 2 to bring one down, fired so they hit almost at once).
The AI at Hard ain't that hard to beat, just spam Long Range Frigates (LRM from TEC, Illuminators at Advent and Assailants for Vasari) at start because the AI is dumb enough to charge your army, and attack their cap ships, you should be able to bring them down fast. Try a fleet diversification:
<> TEC - go directly to 2 Military and LRFs for a short while, start with Akkan and Colonize, also with a Colonize Frigate (Protev) to go Colonize worlds in 2 directions (the cap ship can handle militia on it's own). At level 2 try building some Gardas also, then you can go to Carriers, etc. or try a 5 Military push for Kodiaks, and also some Hoshiko support (Demolition Bots rocks). Or up your Economy fast for better economy mid-game and late-game and simply build ships, TEC has the cheapest ships
Also... try preserving your Credits like 2 minutes or at least 1 before the Pirate raid, so that you have some to spend on any other AI; and dun donate them all, just do 250x at times, so that you have slightly more than the AI, you'll need some time to practice your reflexes but I guess you can handle this, if I can, so can you 
In rebellion, if you play as the TEC rebel, you can become allied with the Pirates and the militia, and so they won't attack you, plus you can use Pirate reinforcements with the Broadcast Centre.
<> Advent... they are harder to play with. Try to get Illuminators up fast, and also, what helps you most is the Defense section of Researches. 5 Turrets are what you need against the first Pirate attacks, befre 5 Turrets can handle the first 2-3 waves. Remember that Pirates attack the planets that are closest to their base, so use this to defend yourself. Repair Platform is something highly required for Advent at start, then try doing the Synergy upgrade for the Turrets
it rocks, especially on Diplomacy where Turrets were upgraded in a patch to 40 damage (in rebellion they have 20 again), since Pirates will first dash in your defenses. Mines aren't that useful since they will go through all of them, and since Advent have homing mines, they will go after their target and generally stack all on few targets.
<> Vasari... their ships are tanky, so expand and build many of them.
Always start with the colonizer, might help you a lot in colonizing worlds fast and up-ing your Economy better in time, you can wait a bit, do the Research for the 2nd Cap ship and build it, so you will have 2 caps in like 5 minutes, which could be a better start.
Starbases are something really good against Pirates, especially Advent ones with Meteoroid Control that lashes out and swipes fleets, combined with Mass Disorientation to prevent opposing ships' running away. The SB should be like at least 2 levels in Defence and Attack to have chances.
In Rebellion, the TEC Loyalist can build a secondary Starbase per planet, which will cost you a bit more, but since it is a Tier 8 Defense upgrade (chain researches that start from Tier 6, and continue through 7 to 8), you will probably have a good economy by the time you research it. Also the TEC Loyalist can research the Novalith Cannon at Tier 6 Military with no other Research prerequisites, and also has a same Tier Research after this one that lowers Novalith Cannon's build cost by 25% and reduces it's Logistic Slot by 3).
TEC Rebel AI that has Researched Truce Amongst Rogues and allied itself with the Pirates will also pay pirates to attack you, so beware, cause the AI will probably send you a lot of pirates at you (a lot of xp for your Capital Ships and Titans that is, should you manage to cope with them all).
Best way to defeat Pirates is to rip the AI's head fast
Offense makes best Difense