Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP]Odczyt tagów filmu z YouTube
northwest
post
Post #1





Grupa: Zarejestrowani
Postów: 788
Pomógł: 1
Dołączył: 17.09.2004

Ostrzeżenie: (10%)
X----


Witam (IMG:style_emoticons/default/smile.gif)
Potrzebuję zrobić odczyt długości kliku bezpośrednio z youtube. Znalazłem takie rozwiązanie:
  1. $xml = simplexml_load_file('http://gdata.youtube.com/feeds/api/videos/G-hW-0MP5lI');
  2. echo"<pre>";
  3. print_r($xml);
  4. echo"</pre>";


Ale podaje niestety wszystko prócz czasu trwania... Wiecie może jak odczytać ten czas?

Northwest
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 5)
Sephirus
post
Post #2





Grupa: Zarejestrowani
Postów: 1 527
Pomógł: 438
Dołączył: 28.06.2011
Skąd: Warszawa

Ostrzeżenie: (0%)
-----


Na samej stronie z wideo masz gdzieś tag:

  1. <meta itemprop="duration" content="PT3M32S">


Gdzie PT3M32S to zapis Interwału czasowego (IMG:style_emoticons/default/smile.gif)

P T 3m 32S - chyba nie musze tłumaczyć (IMG:style_emoticons/default/wink.gif)
Go to the top of the page
+Quote Post
northwest
post
Post #3





Grupa: Zarejestrowani
Postów: 788
Pomógł: 1
Dołączył: 17.09.2004

Ostrzeżenie: (10%)
X----


aha,superek (IMG:style_emoticons/default/smile.gif) Dziękuje:) a masz może jakiś pomysł jak można to prosto i szybko wyciągnąć - w sensie w php??(IMG:style_emoticons/default/smile.gif)
Go to the top of the page
+Quote Post
Sephirus
post
Post #4





Grupa: Zarejestrowani
Postów: 1 527
Pomógł: 438
Dołączył: 28.06.2011
Skąd: Warszawa

Ostrzeżenie: (0%)
-----


  1.  
  2. $site = file_get_contents('adres_strony_YT');
  3. preg_match('/<meta\s*itemprop="duration"\s*content="([^"]+)">/si',$site,$match);
  4.  
  5. $di = new DateInterval($match[1]);
  6.  
  7. echo 'Kawalek trwa: '.$di->h.' godzin '.$di->i.' minut '.$di->s.' sekund';
  8.  
Go to the top of the page
+Quote Post
northwest
post
Post #5





Grupa: Zarejestrowani
Postów: 788
Pomógł: 1
Dołączył: 17.09.2004

Ostrzeżenie: (10%)
X----


Fatal error: Class 'DateInterval' not found in /cms/web/filmy.php on line 59 - taki błąd mi to zwraca (IMG:style_emoticons/default/sad.gif)
Go to the top of the page
+Quote Post
Sephirus
post
Post #6





Grupa: Zarejestrowani
Postów: 1 527
Pomógł: 438
Dołączył: 28.06.2011
Skąd: Warszawa

Ostrzeżenie: (0%)
-----


To wymaga PHP 5.3 + z tego co pamiętam...


Inaczej można to zastąpić jakimś preg_matchem

np:

  1. $site = file_get_contents('adres_strony_YT');
  2. preg_match('/<meta\s*itemprop="duration"\s*content="([^"]+)">/si',$site,$match);
  3.  
  4. preg_match('/([0-9]+)H/si',$match[1],$matchH);
  5. preg_match('/([0-9]+)M/si',$match[1],$matchM);
  6. preg_match('/([0-9]+)S/si',$match[1],$matchS);
  7.  
  8. echo 'Kawalek trwa: '.$matchH[1].' godzin '.$matchM[1].' minut '.$matchS[1].' sekund';
  9.  


Ten post edytował Sephirus 4.06.2012, 14:21:55
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 22.08.2025 - 14:49