Making WordPress.org

Changeset 12043


Ignore:
Timestamp:
09/02/2022 05:03:46 AM (2 years ago)
Author:
dd32
Message:

WordPress.TV: Don't link to the mp4 formats which have no audio, expose the original uploaded file, and add these to the WordPress.tv/api/videos.json API.

Fixes #6000

Location:
sites/trunk/wordpress.tv/public_html/wp-content/themes/wptv2
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.tv/public_html/wp-content/themes/wptv2/plugins/wordpresstv-rest/wordpresstv-rest.php

    r9762 r12043  
    9797                        'producer'    => array(),
    9898                        'video'       => array(
    99                             'mp4' => array(),
    100                             'ogg' => array(),
    101                         )
     99                            'mp4'      => array(),
     100                            'ogg'      => array(),
     101                            'original' => false,
     102                        ),
     103                        'subtitles'   => array(),
    102104                    );
    103105
     
    145147                        if ( $post_videos ) {
    146148                            $post_video = video_get_info_by_guid( $post_videos[0] );
    147 
    148                             // Ogg
     149                            $api_data   = video_get_single_response( $post_video );
     150
     151                            // Original uploaded file, may vary in format.
     152                            $video['video']['original'] = $api_data['original'];
     153
     154                            // Ogg - No longer generated as of May 2021
    149155                            if ( $link = video_highest_resolution_ogg( $post_video ) ) {
    150156                                $video['video']['ogg']['low'] = $link;
    151157                            }
    152158
    153                             // MP4
     159                            // MP4 - Audio no longer available in all formats
    154160                            $mp4_formats = array( 'low' => 'fmt_std', 'med' => 'fmt_dvd', 'high' => 'fmt_hd' );
    155161                            foreach ( $mp4_formats as $mp4_field => $mp4_format ) {
    156                                 if ( $link = video_url_by_format( $post_video, $mp4_format ) ) {
    157                                     $video['video']['mp4'][ $mp4_field ] = $link;
     162                                // Check if HLS transcoded, no audio, no need to link to it.
     163                                if ( ! empty( $api_data['files'][ str_replace( 'fmt_', '', $mp4_format ) ]['hls'] ) ) {
     164                                    continue;
    158165                                }
     166
     167                                $video['video']['mp4'][ $mp4_field ] = video_url_by_format( $post_video, $mp4_format );
    159168                            }
    160169                        }
     170
     171                        // Expose the subtitles
     172                        $video['subtitles'] = (array) $api_data['subtitles'];
    161173                    }
    162174
  • sites/trunk/wordpress.tv/public_html/wp-content/themes/wptv2/sidebar-single.php

    r8230 r12043  
    2626                    $videos = array_keys( find_all_videopress_shortcodes( $originalcontent ) );
    2727                    if ( ! empty( $videos ) ) {
    28                         $video = video_get_info_by_guid( $videos[0] );
    29                         $formats = array( 'fmt_std' => 'Low', 'fmt_dvd' => 'Med', 'fmt_hd' => 'High', 'fmt1_ogg' => 'Low' );
     28                        $video     = video_get_info_by_guid( $videos[0] );
     29                        $api_data  = video_get_single_response( $video );
     30                        $formats   = array( 'fmt_std' => 'Low', 'fmt_dvd' => 'Med', 'fmt_hd' => 'High', 'fmt1_ogg' => 'Low' );
    3031                        $mp4_links = array();
    31                         $ogg_link = NULL;
     32                        $ogg_link  = false;
     33
    3234                        foreach ( $formats as $format => $name ) {
    3335                            if ( 'fmt1_ogg' == $format ) {
    3436                                $link = video_highest_resolution_ogg( $video );
    3537                            } else {
     38
     39                                // Check if HLS transcoded, no audio, no need to link to it.
     40                                if ( ! empty( $api_data['files'][ str_replace( 'fmt_', '', $format ) ]['hls'] ) ) {
     41                                    continue;
     42                                }
     43
    3644                                $link = video_url_by_format( $video, $format );
    3745                            }
     
    4654                                $mp4_links[] = "<a href='$link'>$name</a>";
    4755                            }
     56                        }
     57
     58                        if ( ! empty( $api_data['original'] ) ) {
     59                            $mp4_links[] = "<a href='{$api_data['original']}'>Original</a>";
    4860                        }
    4961
Note: See TracChangeset for help on using the changeset viewer.