Fullscreen/yt-core

View on GitHub
docs/videos.html

Summary

Maintainability
Test Coverage
---
title:  "Yt::Video"
h2: "Videos"
---

<p>
  <code>Yt::Video</code> represents a <a href="https://developers.google.com/youtube/v3/docs/videos">YouTube video</a>.
  Initialize using its YouTube ID:
</p>

<dl>
  <dd><a class="anchor" id="new"></a><div class="highlight"><pre>
{% include doc.html instance="Video#initialize" %}{% include example.html object='video = <span class="no">Yt</span><span class="o">::</span><span class="no">Video</span>' method='new' params=' <span class="ss">id:</span> <span class="s1">"gknzFj_0vvY"</span>' %}
{% include example.html result='#&lt;Yt::Video @id=gknzFj_0vvY&gt;' %}
{% include doc.html instance="Video#canonical_url" %}{% include example.html object='video' method='canonical_url' %}
{% include example.html result='"https://www.youtube.com/watch?v=gknzFj_0vvY"' %}</pre>
  </div></dd>
</dl>

<hr />
<h4>Authentication</h4>

<p>
  Most methods of <code>Yt::Video</code> <strong>retrieve public data</strong> from YouTube (e.g.: fetch a video’s title).<br />
  To use these methods (marked with <span class="label label-success">&nbsp;</span> below), you only need to <a href="{{ site.baseurl }}/#api_key">generate an API key</a> and configure:
</p>

{% highlight ruby %}
Yt.configuration.api_key = "<your api key>"                        ## use your API key

video = Yt::Video.new id: 'gknzFj_0vvY'                            ## use any video ID
video.title # => "First public video"
{% endhighlight %}

<hr />
<h4>List of <code>Yt::Video</code> data methods</h4>
<dl>
  {% include dt.html title="Video’s snippet" label="success" auth="any authentication works" %}
  <dd><a class="anchor" id="snippet"></a><div class="highlight"><pre>
{% include doc.html instance="Video#id" %}{% include example.html object='video' method='id' result='"gknzFj_0vvY"' %}
{% include doc.html instance="Video#title" %}{% include example.html object='video' method='title' result='"First public video"' %}
{% include doc.html instance="Video#description" %}{% include example.html object='video' method='description' result='"A YouTube video to test the yt gem."' %}
{% include doc.html instance="Video#published_at" %}{% include example.html object='video' method='published_at' result='2016-10-20 02:19:05 UTC' %}
{% include doc.html instance="Video#thumbnail_url" %}{% include example.html object='video' method='thumbnail_url' result='"https://i.ytimg.com/vi/gknzFj_0vvY/default.jpg"' %}
{% include doc.html instance="Video#channel_id" %}{% include example.html object='video' method='channel_id' result='"UCwCnUcLcb9-eSrHa_RQGkQQ"' %}
{% include doc.html instance="Video#channel_title" %}{% include example.html object='video' method='channel_title' result='"Yt Test"' %}
{% include doc.html instance="Video#tags" %}{% include example.html object='video' method='tags' result='["yt", "test", "tag"]' %}
{% include doc.html instance="Video#category_id" %}{% include example.html object='video' method='category_id' result='22' %}
{% include doc.html instance="Video#category_title" %}{% include example.html object='video' method='category_title' result='"People & Blogs"' %}
{% include doc.html instance="Video#live_broadcast_content" %}{% include example.html object='video' method='live_broadcast_content' result='"none"' %}</pre>
  </div></dd>

  {% include dt.html title="Video’s status" label="success" auth="any authentication works" %}
  <dd><a class="anchor" id="status"></a><div class="highlight"><pre>
{% include doc.html instance="Video#privacy_status" %}{% include example.html object='video' method='privacy_status' result='"public"' %}
{% include doc.html instance="Video#upload_status" %}{% include example.html object='video' method='upload_status' result='"processed"' %}
{% include doc.html instance="Video#license" %}{% include example.html object='video' method='license' result='"creative_common"' %}
{% include doc.html instance="Video#embeddable" %}{% include example.html object='video' method='embeddable' result='true' %}
{% include doc.html instance="Video#public_stats_viewable" %}{% include example.html object='video' method='public_stats_viewable' result='false' %}</pre>
  </div></dd>

  {% include dt.html title="Video’s statistics" label="success" auth="any authentication works" %}
  <dd><a class="anchor" id="statistics"></a><div class="highlight"><pre>
{% include doc.html instance="Video#view_count" %}{% include example.html object='video' method='view_count' result='123' %}
{% include doc.html instance="Video#like_count" %}{% include example.html object='video' method='like_count' result='93' %}
{% include doc.html instance="Video#dislike_count" %}{% include example.html object='video' method='dislike_count' result='42' %}
{% include doc.html instance="Video#comment_count" %}{% include example.html object='video' method='comment_count' result='62' %}</pre>
  </div></dd>

  {% include dt.html title="Video’s content details" label="success" auth="any authentication works" %}
  <dd><a class="anchor" id="content_details"></a><div class="highlight"><pre>
{% include doc.html instance="Video#duration" %}{% include example.html object='video' method='duration' result='"PT2S"' %}
{% include doc.html instance="Video#seconds" %}{% include example.html object='video' method='seconds' result='2' %}
{% include doc.html instance="Video#length" %}{% include example.html object='video' method='length' result='"00:00:02"' %}
{% include doc.html instance="Video#dimension" %}{% include example.html object='video' method='dimension' result='"2d"' %}
{% include doc.html instance="Video#definition" %}{% include example.html object='video' method='definition' result='"sd"' %}
{% include doc.html instance="Video#caption" %}{% include example.html object='video' method='caption' result='false' %}
{% include doc.html instance="Video#licensed_content" %}{% include example.html object='video' method='licensed_content' result='false' %}
{% include doc.html instance="Video#projection" %}{% include example.html object='video' method='projection' result='"rectangular"' %}</pre>
  </div></dd>

</dl>
<p>
  To limit the number of HTTP requests, use <code>select</code> to specify which <a href="https://developers.google.com/youtube/v3/docs/videos/list#part">parts</a> of the video’s data to load:
</p>
<dl>
  <dd><a class="anchor" id="select"></a><div class="highlight"><pre>
{% include example.html object='slow = video' result='without select: 2 HTTP requests' %}
{% include example.html object='slow' method='title' result='one HTTP request to fetch the video’s snippet' %}
{% include example.html object='slow' method='privacy_status' result='=> another HTTP request to fetch the video’s status' %}

{% include doc.html instance="Video#select" %}{% include example.html object='fast = video' method='select' params=' <span class="ss">:snippet</span><span class="p">,</span> <span class="ss">:status</span>' result='with select: 1 HTTP request' %}
{% include example.html object='fast' method='title' result='one HTTP request to fetch both the video’s snippet and status' %}
{% include example.html object='fast' method='privacy_status' result='=> no extra HTTP requests' %}</pre>
  </div></dd>
</dl>

<dl>
  {% include dt.html title="Video’s channel" label="success" auth="any authentication works" %}
  <dd><a class="anchor" id="channel"></a><div class="highlight"><pre>
{% include doc.html instance="Video#channel" %}{% include example.html object='video' method='channel' %}
{% include example.html result='#&lt;Yt::Channel @id=UCwCnUcLcb9-eSrHa_RQGkQQ&gt;' %}</pre>
  </div></dd>
</dl>


<dl>
  {% include dt.html title="Video’s comment threads" label="success" auth="any authentication works" %}
  <dd><a class="anchor" id="threads"></a><div class="highlight"><pre>
{% include doc.html instance="Video#threads" %}{% include example.html object='video' method='threads' %}
{% include example.html result='#&lt;Yt::Relation [#&lt;Yt::Thread @id=z119d45&gt;, #&lt;Yt::Thread @id=z120d734&gt;, ...]&gt;' %}</pre>
  </div></dd>
</dl>
<p>
  Before iterating through threads, use <code>select</code> to specify which <a href="https://developers.google.com/youtube/v3/docs/commentThreads/list#part">parts</a> to load:
</p>
<dl>
  <dd><a class="anchor" id="select"></a><div class="highlight"><pre>
{% include doc.html instance="Relation#select" %}{% include example.html object='threads = video.threads' method='select' params=' <span class="ss">:id</span>, <span class="ss">:snippet</span>' %}
{% include example.html object='threads' method='map <span class="ss">&amp;:id</span>' result='["z119d45", ...]' %}
{% include example.html object='threads' method='map <span class="ss">&amp;:top_level_comment</span>' result='[#&lt;Yt::Comment @id=z119d45&gt;, ...]' %}</pre>
  </div></dd>
</dl>
<p>
  You can also use <code>limit</code> to only fetch a certain number of threads:
</p>
<dl>
  <dd><a class="anchor" id="limit"></a><div class="highlight"><pre>
{% include doc.html instance="Relation#limit" %}{% include example.html object='threads = video.threads' method='limit' params=' <span class="mi">2</span>' %}
{% include example.html object='threads' method='map <span class="ss">&amp;:id</span>' result='["z119d45", "z120d734"]' %}</pre>
  </div></dd>
</dl>
<p>
  You can also use <code>size</code> to quickly obtain the estimated number of threads:
</p>
<dl>
  <dd><a class="anchor" id="size"></a><div class="highlight"><pre>
{% include doc.html instance="Relation#size" %}{% include example.html object='video.threads' method='size' result='63' %}</pre>
  </div></dd>
</dl>