trending.class.php 830 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. namespace Vioscope;
  3. if ( ! class_exists( '\Vioscope\Trending' ) ) :
  4. class Trending {
  5. // YT video id
  6. private $data;
  7. // Processed data
  8. public $info;
  9. public $page; // TODO: implement.
  10. public $region = 'US';
  11. public $total_page; // TODO: implement.
  12. function __construct( $fetch = false ) {
  13. if ( $fetch == true ) {
  14. $this->region = 'US';
  15. return $this->fetch_data( null, 1 );
  16. }
  17. }
  18. public function fetch_data( $region = null, $page = null ) {
  19. if ( ! $region ) {
  20. $region = $this->region;
  21. } else {
  22. $this->region = $region;
  23. }
  24. if ( ! $page ) {
  25. $page = $this->page;
  26. } else {
  27. $this->page = $page;
  28. }
  29. $html = get_url_contents( "https://www.youtube.com/feed/trending?gl={$this->region}&hl=en" );
  30. $this->data = get_initial_data( $html );
  31. return extract_items( $this->data );
  32. }
  33. }
  34. endif;