Data with O2 (and pretty much all networks) is based on the amount of data downloaded, not by the amount of time you're connected. So you could leave the phone connected in a data session 24/7 if you wanted, you'll still only pay for the amount you download.
When you open Safari and browse to a website, it will download the data needed to display that page and you pay for that data. Once the page is loaded there is nothing left to download to display the page, so you're not paying for anything. If it takes 10 seconds or 10 minutes to download, the amount of data is the same so the cost is the same
With YouTube, it's the same theory. You pay for the data you download, which will of course vary from one film to the next depending on content and duration (the longer the film, the more content there is to download).
Same applies to anything else you use that needs to download data