-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.rb
executable file
·51 lines (40 loc) · 1.27 KB
/
example.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/local/bin/ruby
# -*- coding: utf-8 -*-
require 'yaml'
require_relative 'nico'
# 設定ファイルを読み込む
# config.ymlは予めconfig.yml.sampleを参考に作成する必要がある
config = YAML.load_file('config.yml')
# Nicovideoにログインする
# mailとpasswordは設定ファイルのものが使われる
nv = Nicovideo.login(config["mail"], config["password"])
# video_idの動画とそのサムネイルをダウンロードする
output_thumb_name = "thumb.jpg"
output_video_name_without_ext = "video"
nv.watch(config["video_id"]) {|video|
puts video.title
puts video.description
output_video_name = output_video_name_without_ext + "." + video.type
File.open(output_thumb_name, "wb") {|f|
f.write video.thumbnail
}
File.open(output_video_name, "wb") {|f|
video.video {|buf|
f.write buf
}
}
}
# from_mylist_idのマイリストのうち、
# マイリストコメントが"comment"である動画を
# to_mylist_idのマイリストに移動する
nv.mylist(config["from_mylist_id"]) {|mylist|
item_ids = []
mylist.list['mylistitem'].each {|item|
if item['description'] == "comment" then
item_ids << item['item_id']
end
}
unless item_ids.empty? then
mylist.move(config["to_mylist_id"], item_ids)
end
}