Comments (4)
Unknown file format. This means the site isn't supported yet. I'm sure though that you can extract the video address from a nicovideo page and use that.
from lavaplayer.
The problem is, it should be supported, since there is code for it
from lavaplayer.
Like @abalabahaha said, There is AudioSourceManager for Nicovideo, so it should be supported.
from lavaplayer.
This is working code written in Ruby from Here.
#!/usr/bin/env` ruby
require 'netrc'
require 'net/http'
require 'net/https'
require 'cgi'
LoginURI = URI.parse("https://secure.nicovideo.jp/secure/login?site=niconico")
LoginPostFormat = "current_form=login&mail=%s&password=%s&login_submit=Log+In"
VideoHost = "www.nicovideo.jp"
VideoPathFormat = "/watch/%s"
VideoURLRegexp = %r{^(?:(?:http://)?(?:\w+\.)?(?:nicovideo\.jp/(?:v/|(?:watch(?:\.php)?))?/)?(\w+))}
VideoInfoPathFormat = "/api/getflv?v=%s&as3=1"
VideoTypeRegexp = %r{^http://.*\.nicovideo\.jp/smile\?(.*?)=.*}
if ARGV.size < 1
raise "URL is not specified."
end
url = ARGV[0]
puts "Download #{url}"
# get user info
netrc_info = Netrc.read
user, password = netrc_info["nicovideo"]
if user.nil? || user.empty? || password.nil? || password.empty?
raise "Netrc is invalid."
end
# login
https = Net::HTTP.new(LoginURI.host, LoginURI.port)
https.use_ssl = true
https.verify_mode = OpenSSL::SSL::VERIFY_NONE
postdata = sprintf(LoginPostFormat, user, password)
response = https.post(LoginURI.request_uri, postdata)
user_session = nil
response.get_fields('set-cookie').each do |cookie|
key, value = cookie.split(';').first.split('=')
if (key == 'user_session') && (value != 'deleted')
user_session = value
break
end
end
if user_session.nil?
raise "Failed to login."
end
# get video id
video_id = nil
if match_data = VideoURLRegexp.match(url)
video_id = match_data[1]
else
raise "URL is invalid. [url=#{url}]"
end
# access video page and get cookie
http = Net::HTTP.new(VideoHost)
video_path = sprintf(VideoPathFormat, video_id)
response = http.get(video_path, {'Cookie' => "user_session=#{user_session};"})
nicohistory = nil
response.get_fields('set-cookie').each do |cookie|
key, value = cookie.split(';').first.split('=')
if key == 'nicohistory'
nicohistory = value
break
end
end
# get video uri
http = Net::HTTP.new(VideoHost)
video_info_path = sprintf(VideoInfoPathFormat, video_id)
response = http.get(video_info_path,
{'Cookie' => "user_session=#{user_session}; nicohistory=#{nicohistory};"})
while response.is_a?(Net::HTTPRedirection)
redirect_uri = URI.parse(response.get_fields('location').first)
http = Net::HTTP.new(redirect_uri.host)
response = http.get(redirect_uri.request_uri,
{'Cookie' => "user_session=#{user_session}; nicohistory=#{nicohistory};"})
end
video_uri = nil
begin
info = CGI.parse(response.body)
video_url = info['url'].first
video_uri = URI.parse(video_url)
rescue
raise "Failed to access video information."
end
# set output filename
video_extension = ".flv"
if match_data = VideoTypeRegexp.match(video_uri.to_s)
if match_data[1] == "s"
video_extension = ".swf"
elsif match_data[1] == "m"
video_extension = ".mp4"
else
video_extension = ".flv"
end
else
video_extension = ".flv"
end
output_filename = "#{video_id}#{video_extension}"
# get video data
http = Net::HTTP.new(video_uri.host)
http.request_get(video_uri.request_uri,
{'Cookie' => "user_session=#{user_session}; nicohistory=#{nicohistory};"}) do |response|
File.open(output_filename, "wb") do |file|
response.read_body do |video_block|
file.write(video_block)
end
end
end
puts "done."
from lavaplayer.
Related Issues (20)
- Youtube Master Token Update Failed HOT 2
- Error when Request YouTube Livestreams via YouTubes share-url
- Music Bot keeps connecting and disconnecting from the voice channel after /play command. HOT 3
- Bot has completely stopped playing music HOT 1
- Can't find YouTube playlists that are albums HOT 3
- crossfade feature
- Spotify Support HOT 4
- How to enable debug mode?
- libudpqueue.so: failed to map segment from shared object
- Unknown file format / Unsupported bits per sample HOT 1
- lavaplayer joins audio channel but errors and doesnt play only on Macos Ventura HOT 2
- Not success status code: 403 HOT 2
- How Lavaplayer seek YouTube video? HOT 4
- Bot just stopped playing tracks
- Lavaplayer stopped playing youtube links HOT 2
- playing music, but not sound
- Error HOT 3
- Lavaplayer completely stopped working without giving any errors HOT 3
- [email protected]() async def foo(ctx, arg): await ctx.send(arg)
- Something broke when playing the track happens every time i try to play a track HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lavaplayer.