5
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

NicoBoxでラジオを聴くためにrubyでやったこと

5
Last updated at Posted at 2015-07-29

NicoBoxが神アプリだった件

タイトル通り非常に使えるアプリNicoBoxですが、2015/07/30記述時点では不満点もありました

  • プレイリストの追加が面倒
  • 動画を検索した後のソートが再生数順(らしい)固定

とにかくバックグラウンドで連続再生したい

いろいろ模索しているとマイリストのインポートあるじゃないですか
しかしここでも問題は発生しました
マイリストに登録された最新のものから順に連続再生されるようにインポートされるのです
なんで逆にしなかったんや
ってことでマイリストをこの仕様に合わせて作ります

Gemfile

Gemfile
  source 'https://rubygems.org'

  gem 'niconico'

ライブラリは以下をありがたく利用させてもらいました
sorah/niconico

さっそくインスコ

bundle install --path vendor/bundle --jobs=4

実際に書いたコード

require 'bundler'
Bundler.setup(:default)
require 'niconico'

nico = Niconico.new($email, $password)
nico.login

videos = nico.mylist(45903772) # 公開されているマイリスト番号

filtered_videos = videos.select do |v|
  # 反省会は要らない
  !v.title.match(/反省会/) && v.title.match(/RADIO GREE NIGHT/)
end

nico_api = nico.nico_api

filtered_videos.reverse_each do |v|
  nico_api.mylist_add($mylist_id, 5, v.id) # 5は動画を表す, 0が静止画らしい
  sleep 1.1 # マイリスト登録順はミリ秒単位ではソートされないので1秒以上間隔をあける
end

最後に

いろいろな制約によってコード書いていて情けなくなりました

花澤香菜さんと雨宮天の掛け合わせが心地いいラジオ番組をマイリストに登録する方法でした

5
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?