Adventurer, Orientalist, spy: the remarkable story of Spanish explorer Ali Bey al-Abbassi is to be told on the silver screen for the first time, two centuries after his death.

Born in Catalonia in 1767, Domingo Badia y Leblich posed as an exiled Arab prince and became one of the first Europeans to set foot in Mecca.

Yet despite mixing with the Spanish royal family, Napoleon's top officials and some of the most notable European intellectuals of his age, he has been all but forgotten since he died in 1818.

"It's surprising that no film has yet been made on Ali Bey," Moroccan filmmaker Souheil Ben Barka said during a break on set.

The Spaniard "was a seducer. No one could resist him," he said.

With a budget of $17 million (15 million euros), the veteran director's dramatisation of the explorer's life is set for release in five languages and 40 countries in late 2018.

After learning Arabic and serving in the Spanish army, Ali Bey was charged by Spain's King Charles IV with overthrowing the Sultan of Morocco.

On the suggestion of Napoleon's great diplomat and foreign minister Talleyrand, he posed as an exiled Abbasid prince, born in Syria, raised in Europe, his father persecuted by the Ottomans.

The explorer spent two years in Morocco, but he was exposed and had to flee. He set out across North Africa, posing as a Muslim on pilgrimage.

After meeting Romantic-era French writer Chateaubriand in Cairo, in 1807 he reached Mecca, some half a century before British explorer Richard Burton's famous journey there.

'Courageous, enterprising, cunning'

Ali Bey spent time in the Holy Land and Constantinople before heading back to Spain, where he worked for Napoleon.

But he was seen as a traitor and forced to take refuge in France.

He published a French memoir of his travels before setting off for Mecca again, apparently as a spy working for French King Louis XVIII.

He only made it as far as Syria, where he died suddenly in 1818.

Historian Christian Feucher said dysentery was probably to blame, with a remedy based on roasted rhubarb prescribed by a French doctor in Damascus having little effect.

But others believe he was poisoned by his mistress, Lady Hester Stanhope, a British aristocrat who had converted to Islam.

"She could not cope with learning that her hero was a spy, not a descendant of the caliph and the prophet as he claimed to be," said Ben Barka.

There is little doubt, however, that Ali Bey was "courageous, enterprising, cunning and adventurous", Feucher wrote in a 2012 book on the explorer.

"He captivated the great scholars of the time in Paris and London," Feucher told AFP.

Yet despite his extraordinary life and mysterious death, Ali Bey has received little recognition apart from a street in Barcelona bearing his name.

Ben Barka hopes to change that with his film starring Spanish actor Rodolfo Sancho.

Writing the screenplay for his film took more than three years, he said.

Shooting started in Italy in February, but much of the film was shot in May in Morocco -- in the desert dunes of Merzouga, the Roman ruins of Volubilis and the sumptuous houses of Rabat and Casablanca.

Director of seven feature-length dramas, Ben Barka has already been contacted by producers hoping to adapt the drama for television.