Youtube APIを扱うことができる Rubygemの Yt。
最近またYoutube熱が再発して、いじるのを再開しました。
Yt::Models::Videoに情報がいろいろと入って返ってくると思うんだけど、実際Videoの情報ってどこまで取れているのかわからなかったのでドキュメントとか見てみたのですがどうもわからず。
ちなみにドキュメントはこちら。
Class: Yt::Models::Video — Documentation for yt (0.14.0)
Youtubeの公式リファレンスを見ろみたいなことが書いてあったので見てみると以下のページの情報が取れているらしい。
Videos | YouTube Data API | Google Developers
まぁ大体取れている値と同じ名前のメソッドで呼び出せると思うのだけどどうにも呼び出せないものとかあったのでirbで確認してみた。
結果から先に書くと、Yt::Models::Videoで使えるメソッド一覧は以下。
[:!, :!=, :!~, :<=>, :==, :===, :=~, :__id__, :__send__, :`, :aborted?, :acts_like?, :actual_end_time, :actual_start_time, :ad_formats, :ad_impressions, :advertising_options_set, :advertising_options_sets, :age_restricted?, :annotation_click_through_rate, :annotation_clicks, :annotation_close_rate, :annotations, :as_json, :auth, :average_view_duration, :average_view_percentage, :belongs_to_closed_account?, :belongs_to_suspended_account?, :blank?, :byebug, :captioned?, :capture, :card_click_rate, :card_clicks, :card_impressions, :card_teaser_click_rate, :card_teaser_clicks, :card_teaser_impressions, :category_id, :category_title, :channel_id, :channel_title, :channel_url, :claim, :claimed?, :class, :class_eval, :clone, :comment_count, :comment_threads, :comments, :concern, :concurrent_viewers, :container, :content_detail, :content_details, :debugger, :deep_dup, :define_singleton_method, :delete, :deleted?, :description, :dislike, :dislike_count, :dislikes, :display, :dup, :duplicable?, :duplicate?, :duration, :embed_html, :embeddable?, :empty?, :enable_warnings, :enum_for, :eql?, :equal?, :estimated_minutes_watched, :estimated_revenue, :exists?, :extend, :failed?, :favorite_count, :file_detail, :file_details, :file_size, :file_type, :freeze, :frozen?, :gem, :has_failed_conversion?, :has_public_stats_viewable?, :hash, :hd?, :html_safe?, :id, :ids, :in?, :inappropriate?, :infringes_copyright?, :infringes_trademark?, :inspect, :instance_eval, :instance_exec, :instance_of?, :instance_values, :instance_variable_defined?, :instance_variable_get, :instance_variable_names, :instance_variable_set, :instance_variables, :invalid?, :is_a?, :itself, :kind, :kind_of?, :license, :licensed?, :licensed_as_creative_commons?, :licensed_as_standard_youtube?, :like, :like_count, :liked?, :likes, :live_broadcast_content, :live_streaming_detail, :live_streaming_details, :load_dependency, :method, :methods, :monetized_playbacks, :nil?, :object_id, :playback_based_cpm, :player, :players, :presence, :presence_in, :present?, :pretty_inspect, :pretty_print, :pretty_print_cycle, :pretty_print_inspect, :pretty_print_instance_variables, :privacy_status, :private?, :private_methods, :processed?, :protected_methods, :psych_to_yaml, :public?, :public_method, :public_methods, :public_send, :published_at, :quietly, :rating, :ratings, :rejected?, :remove_instance_variable, :reports, :reports_params, :require_dependency, :require_or_load, :respond_to?, :resumable_sessions, :scheduled?, :scheduled_at, :scheduled_end_time, :scheduled_start_time, :send, :shares, :silence, :silence_stderr, :silence_stream, :silence_warnings, :singleton_class, :singleton_method, :singleton_methods, :snippet, :snippets, :statistics_set, :statistics_sets, :status, :statuses, :stereoscopic?, :subscribers_gained, :subscribers_lost, :suppress, :suppress_warnings, :tags, :taint, :tainted?, :tap, :thumbnail_url, :title, :to_enum, :to_json, :to_json_with_active_support_encoder, :to_json_without_active_support_encoder, :to_param, :to_query, :to_s, :to_yaml, :to_yaml_properties, :too_long?, :too_small?, :trust, :try, :try!, :uniques, :unlike, :unlisted?, :unloadable, :untaint, :untrust, :untrusted?, :update, :upload_content_type, :upload_params, :upload_path, :upload_thumbnail, :uploading?, :username, :uses_unsupported_codec?, :video_categories, :video_category, :videos_added_to_playlists, :videos_removed_from_playlists, :view_count, :viewer_percentage, :views, :violates_terms_of_use?, :with_options, :with_warnings]
yt以外のメソッドもたくさん含んでいると思うけど一気に見れて見やすい。
それでは確認方法
irbで確認していきました。アウトプットがなんぼかあるけど必要なコマンドラインだけピックアップしています。
$ rails c Loading development environment (Rails 4.2.5) 2.3.4 :001 > 2.3.4 :002 > 2.3.4 :003 > 2.3.4 :004 > 2.3.4 :006 > require 'yt' => false 2.3.4 :007 > Yt.configure do |config| 2.3.4 :008 > config.api_key = "[API Key]" 2.3.4 :009?> end => "[API Key]" 2.3.4 :010 > videos = Yt::Collections::Videos.new => #<Yt::Collections::Videos:0x000000052cdbc0 @parent=nil, @auth=nil> 2.3.4 :011 > videos.where(chart: 'mostPopular', part: 'contentDetails', regionCode: 'JP') => #<Yt::Collections::Videos:0x000000052cdbc0 @parent=nil, @auth=nil, @published_before=nil, @halt_list=false, @items=[], @where_params={:chart=>"mostPopular", :part=>"contentDetails", :regionCode=>"JP"}> 2.3.4 :012 > videos.first => #<Yt::Models::Video:0x000000052352f8 @id="2WqpVuFkRtU", @auth=nil, @content_detail=#<Yt::Models::ContentDetail:0x000000052352a8 @data={"duration"=>"PT9M8S", "dimension"=>"2d", "definition"=>"hd", "caption"=>"false", "licensedContent"=>true, "projection"=>"rectangular"}>> 2.3.4 :013 > videos.first.class => Yt::Models::Video 2.3.4 :014 > videos.class => Yt::Collections::Videos 2.3.4 :015 > videos.methods => [:where, ・・・・・ :instance_exec, :__id__] 2.3.4 :017 > 2.3.4 :018 > 2.3.4 :019 > 2.3.4 :020 > 2.3.4 :021 > videos.first.methods => [:exists?, :channel_id, ・・・・(省略) :instance_eval, :instance_exec, :__id__] 2.3.4 :022 > 2.3.4 :023 > 2.3.4 :024 > 2.3.4 :025 > 2.3.4 :027 > require 'pp' => false 2.3.4 :028 > pp videos.first.methods.sort [:!, :!=, ・・・・(省略) :with_warnings] => [:!, :!=, :!~, :<=>, :==, :===, :=~, ・・・・(省略) :with_options, :with_warnings] 2.3.4 :029 >
methodsもさることながら、.classでclassの確認とかすごくデバッグがはかどる。
参考にしたサイト
すごく参考にさせてもらった。「こういう風にデバッグやってるよー」っていうのが書いてあって、irbの使い方もさることながら考え方もすごく参考になった。
ありがとうございます。
yt関連のその他ドキュメントも自分がよく見るから張っておきます。
Yt · The reliable YouTube API Ruby client · Yt::Channel
Channels: list | YouTube Data API | Google Developers
GitHub - Fullscreen/yt: The reliable YouTube API Ruby client
それではまたー。