How to correctly save a file with a Cyrillic name?
Now the file name looks like this: "Максим Р—РёРЅСЏРєР开发者_如何学CѕРІ feat. Indigo - You And Me Only". The correct name is "Максим Зиняков feat. Indigo - You And Me Only".
I get the file from HTTP URL:
agent = Mechanize.new
agent.get(url).save_as("#{mp3_dir}/#{title}.mp3")
As somebody mentioned, you probably need to convert the title
string to utf-8 using iconv
:
require 'rubygems'
require 'mechanize'
require 'iconv'
agent = Mechanize.new
# If source encoding is indeed windows-1251, 'from' is CP1251
title = Iconv.conv('UTF8', 'CP1251', title)
agent.get(url).save_as("#{mp3_dir}/#{title}.mp3")
精彩评论