YoutubePuppeteer

youtube_puppeteer.YouTubePuppeteer

class external_media_tests.media_utils.youtube_puppeteer.YouTubePuppeteer(marionette, url, **kwargs)[source]

Bases: external_media_tests.media_utils.video_puppeteer.VideoPuppeteer

Wrapper around a YouTube #movie_player element.

Partial reference: https://developers.google.com/youtube/js_api_reference. This reference is useful for site-specific features such as interacting with ads, or accessing YouTube’s debug data.

ad_ended
Returns:True if the current ad has ended.
ad_format

When ad is not playing, ad_format is False.

Returns:integer representing ad format, or False
ad_inactive
Returns:True if the current ad is inactive.
ad_playing
Returns:True if an ad is playing.
ad_skippable
Returns:True if the current ad is skippable.
ad_state

Get state of current ad.

Returns:Returns one of the constants listed in https://developers.google.com/youtube/js_api_reference#Playback_status for an ad.
attempt_ad_skip()[source]

Attempt to skip ad by clicking on skip-add button.

Returns:True if clicking of ad-skip button occurred.
breaks_count
Returns:Number of upcoming ad breaks.
deactivate_autoplay()[source]

Attempt to turn off autoplay.

Returns:True if successful.
execute_yt_script(script)[source]

Execute JS script in ‘content’ context with access to video element and YouTube #movie_player element.

Parameters:script – script to be executed.
Returns:value returned by script
movie_id
Returns:The string that is the YouTube identifier.
movie_title
Returns:The title of the movie.
playback_quality

Please see https://developers.google.com/youtube/js_api_reference#Playback_quality for valid values.

Returns:A string with a valid value returned via YouTube.
player_buffering
Returns:True if the video is currently buffering.
player_cued
Returns:True if the video is cued.
player_current_time
Returns:Current time in seconds via YouTube API.
player_duration
Returns:Duration in seconds via YouTube API.
player_ended
Returns:True if the video playback has ended.
player_measure_progress()[source]
Returns:Playback progress in seconds via YouTube API.
player_pause()[source]

Pause via YouTube API.

player_paused
Returns:True if the video is paused.
player_play()[source]

Play via YouTube API.

player_playing
Returns:True if the video is playing.
player_remaining_time
Returns:Remaining time in seconds via YouTube API.
player_stalled
Returns:True if playback is not making progress for 4-9 seconds. This excludes ad breaks. Note that the player might just be busy with buffering due to a slow network.
player_state
Returns:The YouTube state of the video. See https://developers.google.com/youtube/js_api_reference#getPlayerState for valid values.
player_unstarted

This and the following properties are based on the player.getPlayerState() call (https://developers.google.com/youtube/js_api_reference#Playback_status)

Returns:True if the video has not yet started.
player_url
Returns:The YouTube URL for the currently playing video.
process_ad()[source]

Try to skip this ad. If not, wait for this ad to finish.

search_ad_duration()[source]
Returns:ad duration in seconds, if currently displayed in player

youtube_puppeteer.playback_started

external_media_tests.media_utils.youtube_puppeteer.playback_started(yt)[source]

Check whether playback has started.

Parameters:yt – YouTubePuppeteer

youtube_puppeteer.playback_done

external_media_tests.media_utils.youtube_puppeteer.playback_done(yt)[source]

Check whether playback is done, skipping ads if possible.

Parameters:yt – YouTubePuppeteer

youtbue_puppeteer.wait_for_almost_done

external_media_tests.media_utils.youtube_puppeteer.wait_for_almost_done(yt, final_piece=120)[source]

Allow the given video to play until only final_piece seconds remain, skipping ads mid-way as much as possible. final_piece should be short enough to not be interrupted by an ad.

Depending on the length of the video, check the ad status every 10-30 seconds, skip an active ad if possible.

Parameters:yt – YouTubePuppeteer