weibo: normalize weibo urls in artist entries.

Normalize all Weibo URLs in artist entries to one of these forms:

* https://www.weibo.com/u/5399876326
* https://www.weibo.com/p/1005055399876326
* https://www.weibo.com/chengziyou666
This commit is contained in:
evazion
2022-03-13 20:48:42 -05:00
parent 1d9a15a119
commit 223742c365
3 changed files with 39 additions and 3 deletions

View File

@@ -61,6 +61,17 @@ class Artist < ApplicationRecord
def clear_url_string_changed
self.url_string_changed = false
end
class_methods do
# Find all artist URLs matching `regex`, and replace the `from` regex with the `to` string.
def rewrite_urls(regex, from, to)
Artist.transaction do
Artist.joins(:urls).where_regex("artist_urls.url", regex).find_each do |artist|
artist.update!(url_string: artist.url_string.gsub(from, to))
end
end
end
end
end
concerning :NameMethods do