Module: VkMusic::Utility::PlaylistUrlParser
- Defined in:
- lib/vk_music/utility/playlist_url_parser.rb
Overview
Read inner of text-childrens of Nokogiri::XML::Node
node
Constant Summary collapse
- VK_PLAYLIST_URL_POSTFIX =
Regular expression to parse playlist link. Oh my, it is so big
%r{ .* # Garbage (?:audio_playlist|album/|playlist/) # Start of ids (-?\d+)_(\d+) # Ids themself (?:(?:(?:.*(?=&access_hash=)&access_hash=)|/|%2F|_)([\da-z]+))? # Access hash }x.freeze
Class Method Summary collapse
-
.call(url) ⇒ Array(Integer?, Integer?, String?)
Playlist data array: [owner_id, playlist_id, access_hash].
Class Method Details
.call(url) ⇒ Array(Integer?, Integer?, String?)
Returns playlist data array: [owner_id, playlist_id, access_hash].
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/vk_music/utility/playlist_url_parser.rb', line 19 def self.call(url) owner_id, playlist_id, access_hash = url.match(VK_PLAYLIST_URL_POSTFIX).captures owner_id = Integer(owner_id, 10) playlist_id = Integer(playlist_id, 10) access_hash = nil if access_hash&.empty? [owner_id, playlist_id, access_hash] rescue StandardError [nil, nil, nil] end |