开发者

Saving a file with a Cyrillic name

开发者 https://www.devze.com 2023-02-13 13:24 出处:网络
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 corre

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")
0

精彩评论

暂无评论...
验证码 换一张
取 消