yandex_music 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +0 -0
- data/CHANGELOG.md +4 -0
- data/MIT_LICENSE +20 -0
- data/README.md +21 -0
- data/Rakefile +8 -0
- data/lib/version.rb +3 -0
- data/lib/yandex_music.rb +30 -0
- data/test/test_yandex_music.rb +33 -0
- data/yandex_music.gemspec +13 -0
- metadata +52 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: e0c1e3f7d4b441e161c5c1212e2688471c74e5f9
|
|
4
|
+
data.tar.gz: d1b151cdc3070c807f9853cd72e263ba85e51fcf
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 5a0ae59166d959f17e12ccdc0e3ae3f66a80a58474d7736fb9096d9c98030c68124344174ce2b53af7948b0a822d632c8e3bd84c6a0144054fb6fc62d4316db3
|
|
7
|
+
data.tar.gz: fc25769c315644bd54ad2b2340e39e77febbfdec7c2d70874a826c643b46bfb702ca56075ccb809f94a9b282e985f29d366f6e09aa3eabe94e4fb136d042679a
|
data/.gitignore
ADDED
|
File without changes
|
data/CHANGELOG.md
ADDED
data/MIT_LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Copyright (c) 2017 Dmitry Ilin
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
4
|
+
a copy of this software and associated documentation files (the
|
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
9
|
+
the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be
|
|
12
|
+
included in all copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
YandexMusic is a solution to get audio info from Yandex Music
|
|
2
|
+
|
|
3
|
+
## Getting started
|
|
4
|
+
|
|
5
|
+
```ruby
|
|
6
|
+
gem 'yandex_music'
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
Run the bundle command to install it.
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
``` ruby
|
|
14
|
+
audio = YandexMusic.new('https://music.yandex.ru/album/3113802/track/13301302')
|
|
15
|
+
# audio.track_id => 13301302
|
|
16
|
+
# audio.embed_code => <iframe src="https://music.yandex.ru/iframe/#track/13301302" frameborder="0" width="100%" height="100" style="border:none;width:100%;height:100px;"></iframe>
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## License
|
|
20
|
+
|
|
21
|
+
MIT License.
|
data/Rakefile
ADDED
data/lib/version.rb
ADDED
data/lib/yandex_music.rb
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
require 'version'
|
|
2
|
+
|
|
3
|
+
class YandexMusic
|
|
4
|
+
attr_accessor :url
|
|
5
|
+
def initialize(url, options = {})
|
|
6
|
+
@url = url
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
# get yandex audio track id
|
|
10
|
+
def track_id
|
|
11
|
+
@url.gsub(_url_regex, '')
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def embed_code(options = {})
|
|
15
|
+
iframe_attributes = options.fetch(:iframe_attributes, {})
|
|
16
|
+
iframe_attrs = ["src=\"#{_embed_url}\"", 'frameborder="0" width="100%" height="100" style="border:none;width:100%;height:100px;"']
|
|
17
|
+
iframe_attrs << iframe_attributes
|
|
18
|
+
"<iframe #{iframe_attrs.reject(&:empty?).join(' ')}></iframe>"
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
private
|
|
22
|
+
|
|
23
|
+
def _url_regex
|
|
24
|
+
%r{\Ahttp(s?):\/\/music.yandex.ru\/(|album\/\d+\/)track\/}i
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def _embed_url
|
|
28
|
+
"https://music.yandex.ru/iframe/#track/#{track_id}"
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
require 'minitest/autorun'
|
|
2
|
+
require 'yandex_music'
|
|
3
|
+
|
|
4
|
+
class YandexMusicTest < Minitest::Test
|
|
5
|
+
def good_tracks_list
|
|
6
|
+
%w[
|
|
7
|
+
https://music.yandex.ru/album/3113802/track/13301302
|
|
8
|
+
http://music.yandex.ru/album/3113802/track/13301302
|
|
9
|
+
https://music.yandex.ru/track/13301302
|
|
10
|
+
]
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def test_must_return_yandex_id
|
|
14
|
+
good_tracks_list.each do |track|
|
|
15
|
+
new_track = YandexMusic.new(track)
|
|
16
|
+
assert_equal new_track.track_id, '13301302'
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def test_must_return_yandex_embed_url
|
|
21
|
+
good_tracks_list.each do |track|
|
|
22
|
+
new_track = YandexMusic.new(track)
|
|
23
|
+
assert_equal new_track.send(:_embed_url), 'https://music.yandex.ru/iframe/#track/13301302'
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def test_must_return_yandex_embed_code
|
|
28
|
+
good_tracks_list.each do |track|
|
|
29
|
+
new_track = YandexMusic.new(track)
|
|
30
|
+
assert_equal new_track.embed_code, '<iframe src="https://music.yandex.ru/iframe/#track/13301302" frameborder="0" width="100%" height="100" style="border:none;width:100%;height:100px;"></iframe>'
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
Gem::Specification.new do |s|
|
|
2
|
+
s.name = 'yandex_music'
|
|
3
|
+
s.version = '0.0.1'
|
|
4
|
+
s.date = '2017-11-29'
|
|
5
|
+
s.summary = 'Yandex music'
|
|
6
|
+
s.description = 'Get audio info from Yandex Music'
|
|
7
|
+
s.authors = ['Dmitry Ilin']
|
|
8
|
+
s.email = 'dm.ilin@mail.ru'
|
|
9
|
+
s.files = `git ls-files`.split($/)
|
|
10
|
+
s.homepage = 'https://github.com/NILID/yandex_music'
|
|
11
|
+
s.platform = Gem::Platform::RUBY
|
|
12
|
+
s.license = 'MIT'
|
|
13
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: yandex_music
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Dmitry Ilin
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2017-11-29 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description: Get audio info from Yandex Music
|
|
14
|
+
email: dm.ilin@mail.ru
|
|
15
|
+
executables: []
|
|
16
|
+
extensions: []
|
|
17
|
+
extra_rdoc_files: []
|
|
18
|
+
files:
|
|
19
|
+
- ".gitignore"
|
|
20
|
+
- CHANGELOG.md
|
|
21
|
+
- MIT_LICENSE
|
|
22
|
+
- README.md
|
|
23
|
+
- Rakefile
|
|
24
|
+
- lib/version.rb
|
|
25
|
+
- lib/yandex_music.rb
|
|
26
|
+
- test/test_yandex_music.rb
|
|
27
|
+
- yandex_music.gemspec
|
|
28
|
+
homepage: https://github.com/NILID/yandex_music
|
|
29
|
+
licenses:
|
|
30
|
+
- MIT
|
|
31
|
+
metadata: {}
|
|
32
|
+
post_install_message:
|
|
33
|
+
rdoc_options: []
|
|
34
|
+
require_paths:
|
|
35
|
+
- lib
|
|
36
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - ">="
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '0'
|
|
41
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
42
|
+
requirements:
|
|
43
|
+
- - ">="
|
|
44
|
+
- !ruby/object:Gem::Version
|
|
45
|
+
version: '0'
|
|
46
|
+
requirements: []
|
|
47
|
+
rubyforge_project:
|
|
48
|
+
rubygems_version: 2.5.2
|
|
49
|
+
signing_key:
|
|
50
|
+
specification_version: 4
|
|
51
|
+
summary: Yandex music
|
|
52
|
+
test_files: []
|