A U.S. federal judge has ordered Google Inc. to hand over to media giant Viacom the records of every video that users have watched on the video-sharing site YouTube, records that include users' names and IP addresses.

Viacom is suing Google for not doing enough to keep its copyrighted videos from television shows such as The Daily Show with Jon Stewart and The Colbert Report off the popular website YouTube.

Viacom, which owns several U.S. television networks including MTV, VH1, Nickelodeon, Comedy Central and Spike TV, alleged in $1-billion US lawsuit launched in March 2007 that almost 160,000 unauthorized clips of its programming are available on YouTube. Those clips have been viewed more than 1.5 billion times, Viacom charged.

The company argued it needed access to the information on user viewing habits to prove that copyright-infringing material is more popular than user-generated videos on YouTube, which would strengthen its case against Google.

In a ruling issued on Tuesday, Louis Stanton, a judge with the U.S. District Court for the southern district of New York, agreed with Viacom and ordered Google to turn over the information.

Google argued user data should not be handed over because of privacy concerns, but Stanton dismissed those concerns as "speculative."

San Francisco-based privacy advocacy group The Electronic Frontier Foundation said the ruling was "a setback to privacy rights, and will allow Viacom to see what you are watching on YouTube.

"We urge Viacom to back off this overbroad request and Google to take all steps necessary to challenge this order and protect the rights of its users," wrote EFF's senior staff attorney Kurt Opsahl on Wednesday.

Viacom also asked for the underlying code Google and YouTube use to search for keywords and video in order to demonstrate what Google could be doing to block infringing videos. They also wanted access to Google's advertising database scheme in the hopes of proving that infringing videos are driving advertising revenue.

But the court denied these requests, arguing the code and ad data was too valuable to Google.

"YouTube and Google should not be made to place this vital asset in hazard merely to allay speculation," said Stanton. "A plausible showing that YouTube and Google’s denials are false, and that the search function can and has been used to discriminate in favour of infringing content, should be required before disclosure of so valuable and vulnerable an asset is compelled."

At issue in the case is whether Google has fulfilled its requirements under the 1998 Digital Millennium Copyright Act.

The DMCA gives websites protection against infringement claims provided copyrighted material is removed upon notification. Viacom has argued Google could do a better job of blocking the infringing material but doesn't do so because infringing material makes up a significant portion of the website's traffic.