songle-song-uri-parser 1.0.0
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 +11 -0
- data/.gitlab-ci.yml +24 -0
- data/.rspec +3 -0
- data/.ruby-version +1 -0
- data/CHANGELOG.md +4 -0
- data/Dockerfile +17 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +35 -0
- data/LICENSE.txt +21 -0
- data/README.md +58 -0
- data/Rakefile +6 -0
- data/lib/songle-song-uri-parser.rb +16 -0
- data/lib/songle/song_uri.rb +108 -0
- data/lib/songle/song_uri/invalid_song_uri_error.rb +11 -0
- data/lib/songle/song_uri/mp3_song_uri.rb +62 -0
- data/lib/songle/song_uri/nn_scheme_song_uri.rb +50 -0
- data/lib/songle/song_uri/nn_short_song_uri.rb +50 -0
- data/lib/songle/song_uri/nn_song_uri.rb +48 -0
- data/lib/songle/song_uri/sc_scheme_song_uri.rb +50 -0
- data/lib/songle/song_uri/sc_song_uri.rb +48 -0
- data/lib/songle/song_uri/yt_scheme_song_uri.rb +50 -0
- data/lib/songle/song_uri/yt_short_song_uri.rb +50 -0
- data/lib/songle/song_uri/yt_song_uri.rb +48 -0
- data/songle-song-uri-parser.gemspec +29 -0
- metadata +109 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e56cc4ca2df8bd3dcea18a2822627b9dc30561eca2c75d32e88b8c54033f7f0f
|
4
|
+
data.tar.gz: e3ade3da897f495a3c021e9b96fdd0203fad7fc872123fc12c237631df29e6ff
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d8eae1681c74a6b82402ec2434c1fcc0d3f56058a1ea77895409199ddcf596ca4ba6b743f9350435d68308824339a26c441738e06dbdba1e7ab6e81a71167e68
|
7
|
+
data.tar.gz: c6a5a1cae2bab2731862a8b9558f8339bd43c24cf914528b77fc1efaa11f2c3b1e72d02fde12149aa93614f3b7fb912c25c3d892f3f68cd7344f2f6773fad4d8
|
data/.gitignore
ADDED
data/.gitlab-ci.yml
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
####
|
2
|
+
## @see http://docs.gitlab.com/ce/ci/yaml/README.html
|
3
|
+
####
|
4
|
+
image: docker:git
|
5
|
+
|
6
|
+
stages:
|
7
|
+
- build_and_test
|
8
|
+
|
9
|
+
variables:
|
10
|
+
APP_ENV: develop
|
11
|
+
IMAGE_PATH: ${CI_REGISTRY}/${CI_PROJECT_NAMESPACE}/${CI_PROJECT_NAME}
|
12
|
+
|
13
|
+
build_and_test:
|
14
|
+
stage: build_and_test
|
15
|
+
script:
|
16
|
+
- docker build --build-arg RUBY_VERSION=2.3 -t ${IMAGE_PATH}:${APP_ENV} .
|
17
|
+
- docker run ${IMAGE_PATH}:${APP_ENV}
|
18
|
+
- docker build --build-arg RUBY_VERSION=2.4 -t ${IMAGE_PATH}:${APP_ENV} .
|
19
|
+
- docker run ${IMAGE_PATH}:${APP_ENV}
|
20
|
+
- docker build --build-arg RUBY_VERSION=2.5 -t ${IMAGE_PATH}:${APP_ENV} .
|
21
|
+
- docker run ${IMAGE_PATH}:${APP_ENV}
|
22
|
+
- docker build --build-arg RUBY_VERSION=2.6 -t ${IMAGE_PATH}:${APP_ENV} .
|
23
|
+
- docker run ${IMAGE_PATH}:${APP_ENV}
|
24
|
+
environment: ${APP_ENV}
|
data/.rspec
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.6.0
|
data/CHANGELOG.md
ADDED
data/Dockerfile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
ARG RUBY_VERSION=2.6
|
3
|
+
|
4
|
+
FROM ruby:${RUBY_VERSION}.0-alpine
|
5
|
+
MAINTAINER Takahiro INOUE <takahiro.inoue@aist.go.jp>
|
6
|
+
|
7
|
+
WORKDIR /work
|
8
|
+
|
9
|
+
ADD . .
|
10
|
+
|
11
|
+
RUN apk update && \
|
12
|
+
apk add \
|
13
|
+
git
|
14
|
+
|
15
|
+
RUN bundle install -j $(cat /proc/cpuinfo | grep '^processor' | wc -l)
|
16
|
+
|
17
|
+
ENTRYPOINT [ "rake", "spec" ]
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
songle-song-uri-parser (1.0.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
diff-lcs (1.3)
|
10
|
+
rake (10.5.0)
|
11
|
+
rspec (3.8.0)
|
12
|
+
rspec-core (~> 3.8.0)
|
13
|
+
rspec-expectations (~> 3.8.0)
|
14
|
+
rspec-mocks (~> 3.8.0)
|
15
|
+
rspec-core (3.8.0)
|
16
|
+
rspec-support (~> 3.8.0)
|
17
|
+
rspec-expectations (3.8.2)
|
18
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
19
|
+
rspec-support (~> 3.8.0)
|
20
|
+
rspec-mocks (3.8.0)
|
21
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
22
|
+
rspec-support (~> 3.8.0)
|
23
|
+
rspec-support (3.8.0)
|
24
|
+
|
25
|
+
PLATFORMS
|
26
|
+
ruby
|
27
|
+
|
28
|
+
DEPENDENCIES
|
29
|
+
bundler (~> 1.0)
|
30
|
+
rake (~> 10.0)
|
31
|
+
rspec (~> 3.0)
|
32
|
+
songle-song-uri-parser!
|
33
|
+
|
34
|
+
BUNDLED WITH
|
35
|
+
1.17.2
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 Takahiro INOUE
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
# Songle Song URI Parser
|
2
|
+
|
3
|
+
## What is a Song URI?
|
4
|
+
|
5
|
+
A [Song URI](//songle.jp/songs/staff.aist.go.jp%2Ft.nakano%2Fmusic%2FVocaWatcher.Prologue.Miku.mp3) is an unique song ID of managed by the [Songle](//songle.jp).
|
6
|
+
|
7
|
+
This gem package can parse it.
|
8
|
+
|
9
|
+
## Usage
|
10
|
+
|
11
|
+
### Prerequirements
|
12
|
+
|
13
|
+
- ruby 2.x
|
14
|
+
|
15
|
+
### Installation
|
16
|
+
|
17
|
+
```sh
|
18
|
+
$ gem install songle-song-uri-parser
|
19
|
+
```
|
20
|
+
|
21
|
+
### Example
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
require "songle-song-uri-parser"
|
25
|
+
|
26
|
+
song =
|
27
|
+
::Songle::SongURI.parse("http://songle.jp/songs/staff.aist.go.jp%2Ft.nakano%2Fmusic%2FVocaWatcher.Prologue.Miku.mp3")
|
28
|
+
|
29
|
+
p song.permalink #=> "http://staff.aist.go.jp/t.nakano/music/VocaWatcher.Prologue.Miku.mp3"
|
30
|
+
p song.type #=> "mp3"
|
31
|
+
p song.to_s #=> "http://songle.jp/songs/staff.aist.go.jp%2Ft.nakano%2Fmusic%2FVocaWatcher.Prologue.Miku.mp3"
|
32
|
+
```
|
33
|
+
|
34
|
+
## Development
|
35
|
+
|
36
|
+
### Prerequirements
|
37
|
+
|
38
|
+
- ruby 2.x
|
39
|
+
|
40
|
+
Install dependenting gem packages using bundler.
|
41
|
+
|
42
|
+
```sh
|
43
|
+
$ bundle install
|
44
|
+
```
|
45
|
+
|
46
|
+
### Running test
|
47
|
+
|
48
|
+
```sh
|
49
|
+
$ rake spec
|
50
|
+
```
|
51
|
+
|
52
|
+
## Contributing
|
53
|
+
|
54
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/hinata/songle-song-uri-parser.
|
55
|
+
|
56
|
+
## License
|
57
|
+
|
58
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require "songle/song_uri"
|
3
|
+
require "songle/song_uri/mp3_song_uri"
|
4
|
+
require "songle/song_uri/nn_song_uri"
|
5
|
+
require "songle/song_uri/nn_scheme_song_uri"
|
6
|
+
require "songle/song_uri/nn_short_song_uri"
|
7
|
+
require "songle/song_uri/sc_song_uri"
|
8
|
+
require "songle/song_uri/sc_scheme_song_uri"
|
9
|
+
require "songle/song_uri/yt_song_uri"
|
10
|
+
require "songle/song_uri/yt_scheme_song_uri"
|
11
|
+
require "songle/song_uri/yt_short_song_uri"
|
12
|
+
require "songle/song_uri/invalid_song_uri_error"
|
13
|
+
|
14
|
+
module ::SongleSongURIParser
|
15
|
+
VERSION = "1.0.0"
|
16
|
+
end
|
@@ -0,0 +1,108 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
module ::Songle
|
3
|
+
module SongURI
|
4
|
+
attr_reader :endpoint_scheme
|
5
|
+
attr_reader :endpoint_host
|
6
|
+
attr_reader :endpoint_path
|
7
|
+
attr_reader :source_host
|
8
|
+
attr_reader :source_path
|
9
|
+
attr_reader :source_id
|
10
|
+
|
11
|
+
##
|
12
|
+
# @constant
|
13
|
+
#
|
14
|
+
ENDPOINT_SCHEME = "https"
|
15
|
+
|
16
|
+
##
|
17
|
+
# @constant
|
18
|
+
#
|
19
|
+
ENDPOINT_HOST = "songle.jp"
|
20
|
+
|
21
|
+
##
|
22
|
+
# @constant
|
23
|
+
#
|
24
|
+
ENDPOINT_PATH = "/songs/"
|
25
|
+
|
26
|
+
##
|
27
|
+
# @constructor
|
28
|
+
#
|
29
|
+
def initialize string, options = nil
|
30
|
+
options ||= {}
|
31
|
+
|
32
|
+
@endpoint_scheme =
|
33
|
+
options[ :endpoint_scheme ] || ENDPOINT_SCHEME
|
34
|
+
|
35
|
+
@endpoint_host =
|
36
|
+
options[ :endpoint_host ] || ENDPOINT_HOST
|
37
|
+
|
38
|
+
@endpoint_path =
|
39
|
+
options[ :endpoint_path ] || ENDPOINT_PATH
|
40
|
+
end
|
41
|
+
|
42
|
+
##
|
43
|
+
# @function
|
44
|
+
#
|
45
|
+
def endpoint
|
46
|
+
return "#{ self.endpoint_scheme }://#{ self.endpoint_host }#{ self.endpoint_path }"
|
47
|
+
end
|
48
|
+
|
49
|
+
##
|
50
|
+
# @function
|
51
|
+
#
|
52
|
+
def permalink
|
53
|
+
return "http://#{ self.source_host }#{ self.source_path }"
|
54
|
+
end
|
55
|
+
|
56
|
+
##
|
57
|
+
# @function
|
58
|
+
#
|
59
|
+
def type
|
60
|
+
return nil
|
61
|
+
end
|
62
|
+
|
63
|
+
##
|
64
|
+
# @function
|
65
|
+
#
|
66
|
+
def to_s
|
67
|
+
encoded_source_host =
|
68
|
+
::URI.encode_www_form_component(self.source_host)
|
69
|
+
|
70
|
+
encoded_source_path =
|
71
|
+
::URI.encode_www_form_component(self.source_path)
|
72
|
+
|
73
|
+
return "#{ self.endpoint }#{ encoded_source_host }#{ encoded_source_path }"
|
74
|
+
end
|
75
|
+
|
76
|
+
class << self
|
77
|
+
##
|
78
|
+
# @function
|
79
|
+
# @static
|
80
|
+
#
|
81
|
+
def parse string, options = nil
|
82
|
+
string =
|
83
|
+
::URI.decode_www_form_component(string)
|
84
|
+
|
85
|
+
case
|
86
|
+
when string =~ ::Songle::SongURI::NnSongURI::URI_REGEX
|
87
|
+
return ::Songle::SongURI::NnSongURI.new(string, options)
|
88
|
+
when string =~ ::Songle::SongURI::NnSchemeSongURI::URI_REGEX
|
89
|
+
return ::Songle::SongURI::NnSchemeSongURI.new(string, options)
|
90
|
+
when string =~ ::Songle::SongURI::NnShortSongURI::URI_REGEX
|
91
|
+
return ::Songle::SongURI::NnShortSongURI.new(string, options)
|
92
|
+
when string =~ ::Songle::SongURI::ScSongURI::URI_REGEX
|
93
|
+
return ::Songle::SongURI::ScSongURI.new(string, options)
|
94
|
+
when string =~ ::Songle::SongURI::ScSchemeSongURI::URI_REGEX
|
95
|
+
return ::Songle::SongURI::ScSchemeSongURI.new(string, options)
|
96
|
+
when string =~ ::Songle::SongURI::YtSongURI::URI_REGEX
|
97
|
+
return ::Songle::SongURI::YtSongURI.new(string, options)
|
98
|
+
when string =~ ::Songle::SongURI::YtSchemeSongURI::URI_REGEX
|
99
|
+
return ::Songle::SongURI::YtSchemeSongURI.new(string, options)
|
100
|
+
when string =~ ::Songle::SongURI::YtShortSongURI::URI_REGEX
|
101
|
+
return ::Songle::SongURI::YtShortSongURI.new(string, options)
|
102
|
+
else
|
103
|
+
return ::Songle::SongURI::Mp3SongURI.new(string, options)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
module ::Songle::SongURI
|
3
|
+
class Mp3SongURI
|
4
|
+
include ::Songle::SongURI
|
5
|
+
|
6
|
+
##
|
7
|
+
# @constant
|
8
|
+
#
|
9
|
+
TYPE = "mp3"
|
10
|
+
|
11
|
+
##
|
12
|
+
# @constant
|
13
|
+
#
|
14
|
+
URI_REGEX = /^(\/\/|http(|s):\/\/)(.+)$/
|
15
|
+
|
16
|
+
##
|
17
|
+
# @constructor
|
18
|
+
#
|
19
|
+
def initialize string, options
|
20
|
+
super(string, options)
|
21
|
+
|
22
|
+
if string =~ URI_REGEX
|
23
|
+
string = $3
|
24
|
+
end
|
25
|
+
|
26
|
+
if string =~ /^#{ self.endpoint_host }(.+)$/
|
27
|
+
string = $1
|
28
|
+
end
|
29
|
+
|
30
|
+
if string =~ /^#{ self.endpoint_path }(.+)$/
|
31
|
+
string = $1
|
32
|
+
end
|
33
|
+
|
34
|
+
source_uri =
|
35
|
+
::URI.parse("//#{ string }")
|
36
|
+
|
37
|
+
@source_host = source_uri.host
|
38
|
+
@source_path = source_uri.path
|
39
|
+
@source_id = nil
|
40
|
+
end
|
41
|
+
|
42
|
+
##
|
43
|
+
# @function
|
44
|
+
#
|
45
|
+
def type
|
46
|
+
return TYPE
|
47
|
+
end
|
48
|
+
|
49
|
+
##
|
50
|
+
# @function
|
51
|
+
#
|
52
|
+
def to_s
|
53
|
+
encoded_source_host =
|
54
|
+
::URI.encode_www_form_component(self.source_host).gsub("+", "%2520")
|
55
|
+
|
56
|
+
encoded_source_path =
|
57
|
+
::URI.encode_www_form_component(self.source_path).gsub("+", "%2520")
|
58
|
+
|
59
|
+
return "#{ self.endpoint }#{ encoded_source_host }#{ encoded_source_path }"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
module ::Songle::SongURI
|
3
|
+
class NnSchemeSongURI
|
4
|
+
include ::Songle::SongURI
|
5
|
+
|
6
|
+
##
|
7
|
+
# @constant
|
8
|
+
#
|
9
|
+
SOURCE_HOST = ::Songle::SongURI::NnSongURI::SOURCE_HOST
|
10
|
+
|
11
|
+
##
|
12
|
+
# @constant
|
13
|
+
#
|
14
|
+
SOURCE_PATH = ::Songle::SongURI::NnSongURI::SOURCE_PATH
|
15
|
+
|
16
|
+
##
|
17
|
+
# @constant
|
18
|
+
#
|
19
|
+
TYPE = ::Songle::SongURI::NnSongURI::TYPE
|
20
|
+
|
21
|
+
##
|
22
|
+
# @constant
|
23
|
+
#
|
24
|
+
URI_REGEX = /^nn:\/\/(.+)$/
|
25
|
+
|
26
|
+
##
|
27
|
+
# @constructor
|
28
|
+
#
|
29
|
+
def initialize string, options
|
30
|
+
super(string, options)
|
31
|
+
|
32
|
+
@source_host = SOURCE_HOST
|
33
|
+
@source_path = SOURCE_PATH
|
34
|
+
@source_id = $1 if string =~ URI_REGEX
|
35
|
+
|
36
|
+
if @source_id.nil? || @source_id.strip.empty?
|
37
|
+
raise ::Songle::SongURI::InvalidSongURIError.new(string)
|
38
|
+
end
|
39
|
+
|
40
|
+
@source_path += @source_id
|
41
|
+
end
|
42
|
+
|
43
|
+
##
|
44
|
+
# @function
|
45
|
+
#
|
46
|
+
def type
|
47
|
+
return TYPE
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
module ::Songle::SongURI
|
3
|
+
class NnShortSongURI
|
4
|
+
include ::Songle::SongURI
|
5
|
+
|
6
|
+
##
|
7
|
+
# @constant
|
8
|
+
#
|
9
|
+
SOURCE_HOST = ::Songle::SongURI::NnSongURI::SOURCE_HOST
|
10
|
+
|
11
|
+
##
|
12
|
+
# @constant
|
13
|
+
#
|
14
|
+
SOURCE_PATH = ::Songle::SongURI::NnSongURI::SOURCE_PATH
|
15
|
+
|
16
|
+
##
|
17
|
+
# @constant
|
18
|
+
#
|
19
|
+
TYPE = ::Songle::SongURI::NnSongURI::TYPE
|
20
|
+
|
21
|
+
##
|
22
|
+
# @constant
|
23
|
+
#
|
24
|
+
URI_REGEX = /\/\/nico\.ms\/(.+)$/
|
25
|
+
|
26
|
+
##
|
27
|
+
# @constructor
|
28
|
+
#
|
29
|
+
def initialize string, options
|
30
|
+
super(string, options)
|
31
|
+
|
32
|
+
@source_host = SOURCE_HOST
|
33
|
+
@source_path = SOURCE_PATH
|
34
|
+
@source_id = $1 if string =~ URI_REGEX
|
35
|
+
|
36
|
+
if @source_id.nil? || @source_id.strip.empty?
|
37
|
+
raise ::Songle::SongURI::InvalidSongURIError.new(string)
|
38
|
+
end
|
39
|
+
|
40
|
+
@source_path += @source_id
|
41
|
+
end
|
42
|
+
|
43
|
+
##
|
44
|
+
# @function
|
45
|
+
#
|
46
|
+
def type
|
47
|
+
return TYPE
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
module ::Songle::SongURI
|
3
|
+
class NnSongURI
|
4
|
+
include ::Songle::SongURI
|
5
|
+
|
6
|
+
##
|
7
|
+
# @constant
|
8
|
+
#
|
9
|
+
SOURCE_HOST = "www.nicovideo.jp"
|
10
|
+
|
11
|
+
##
|
12
|
+
# @constant
|
13
|
+
#
|
14
|
+
SOURCE_PATH = "/watch/"
|
15
|
+
|
16
|
+
##
|
17
|
+
# @constant
|
18
|
+
#
|
19
|
+
TYPE = "nn"
|
20
|
+
|
21
|
+
##
|
22
|
+
# @constant
|
23
|
+
#
|
24
|
+
URI_REGEX = /#{ SOURCE_HOST.gsub("www.", "") }(#{ SOURCE_PATH.gsub("?", "\\?") }(.+))/
|
25
|
+
|
26
|
+
##
|
27
|
+
# @constructor
|
28
|
+
#
|
29
|
+
def initialize string, options
|
30
|
+
super(string, options)
|
31
|
+
|
32
|
+
@source_host = SOURCE_HOST
|
33
|
+
@source_path = $1 if string =~ URI_REGEX
|
34
|
+
@source_id = $2 if string =~ URI_REGEX
|
35
|
+
|
36
|
+
if @source_id.nil? || @source_id.strip.empty?
|
37
|
+
raise ::Songle::SongURI::InvalidSongURIError.new(string)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
##
|
42
|
+
# @function
|
43
|
+
#
|
44
|
+
def type
|
45
|
+
return TYPE
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
module ::Songle::SongURI
|
3
|
+
class ScSchemeSongURI
|
4
|
+
include ::Songle::SongURI
|
5
|
+
|
6
|
+
##
|
7
|
+
# @constant
|
8
|
+
#
|
9
|
+
SOURCE_HOST = ::Songle::SongURI::ScSongURI::SOURCE_HOST
|
10
|
+
|
11
|
+
##
|
12
|
+
# @constant
|
13
|
+
#
|
14
|
+
SOURCE_PATH = ::Songle::SongURI::ScSongURI::SOURCE_PATH
|
15
|
+
|
16
|
+
##
|
17
|
+
# @constant
|
18
|
+
#
|
19
|
+
TYPE = ::Songle::SongURI::ScSongURI::TYPE
|
20
|
+
|
21
|
+
##
|
22
|
+
# @constant
|
23
|
+
#
|
24
|
+
URI_REGEX = /^sc:\/\/(.+)$/
|
25
|
+
|
26
|
+
##
|
27
|
+
# @constructor
|
28
|
+
#
|
29
|
+
def initialize string, options
|
30
|
+
super(string, options)
|
31
|
+
|
32
|
+
@source_host = SOURCE_HOST
|
33
|
+
@source_path = SOURCE_PATH
|
34
|
+
@source_id = $1 if string =~ URI_REGEX
|
35
|
+
|
36
|
+
if @source_id.nil? || @source_id.strip.empty?
|
37
|
+
raise ::Songle::SongURI::InvalidSongURIError.new(string)
|
38
|
+
end
|
39
|
+
|
40
|
+
@source_path += @source_id
|
41
|
+
end
|
42
|
+
|
43
|
+
##
|
44
|
+
# @function
|
45
|
+
#
|
46
|
+
def type
|
47
|
+
return TYPE
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
module ::Songle::SongURI
|
3
|
+
class ScSongURI
|
4
|
+
include ::Songle::SongURI
|
5
|
+
|
6
|
+
##
|
7
|
+
# @constant
|
8
|
+
#
|
9
|
+
SOURCE_HOST = "soundcloud.com"
|
10
|
+
|
11
|
+
##
|
12
|
+
# @constant
|
13
|
+
#
|
14
|
+
SOURCE_PATH = "/"
|
15
|
+
|
16
|
+
##
|
17
|
+
# @constant
|
18
|
+
#
|
19
|
+
TYPE = "sc"
|
20
|
+
|
21
|
+
##
|
22
|
+
# @constant
|
23
|
+
#
|
24
|
+
URI_REGEX = /#{ SOURCE_HOST.gsub("www.", "") }(#{ SOURCE_PATH.gsub("?", "\\?") }(.+))/
|
25
|
+
|
26
|
+
##
|
27
|
+
# @constructor
|
28
|
+
#
|
29
|
+
def initialize string, options
|
30
|
+
super(string, options)
|
31
|
+
|
32
|
+
@source_host = SOURCE_HOST
|
33
|
+
@source_path = $1 if string =~ URI_REGEX
|
34
|
+
@source_id = $2 if string =~ URI_REGEX
|
35
|
+
|
36
|
+
if @source_id.nil? || @source_id.strip.empty?
|
37
|
+
raise ::Songle::SongURI::InvalidSongURIError.new(string)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
##
|
42
|
+
# @function
|
43
|
+
#
|
44
|
+
def type
|
45
|
+
return TYPE
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
module ::Songle::SongURI
|
3
|
+
class YtSchemeSongURI
|
4
|
+
include ::Songle::SongURI
|
5
|
+
|
6
|
+
##
|
7
|
+
# @constant
|
8
|
+
#
|
9
|
+
SOURCE_HOST = ::Songle::SongURI::YtSongURI::SOURCE_HOST
|
10
|
+
|
11
|
+
##
|
12
|
+
# @constant
|
13
|
+
#
|
14
|
+
SOURCE_PATH = ::Songle::SongURI::YtSongURI::SOURCE_PATH
|
15
|
+
|
16
|
+
##
|
17
|
+
# @constant
|
18
|
+
#
|
19
|
+
TYPE = ::Songle::SongURI::YtSongURI::TYPE
|
20
|
+
|
21
|
+
##
|
22
|
+
# @constant
|
23
|
+
#
|
24
|
+
URI_REGEX = /^yt:\/\/(.+)$/
|
25
|
+
|
26
|
+
##
|
27
|
+
# @constructor
|
28
|
+
#
|
29
|
+
def initialize string, options
|
30
|
+
super(string, options)
|
31
|
+
|
32
|
+
@source_host = SOURCE_HOST
|
33
|
+
@source_path = SOURCE_PATH
|
34
|
+
@source_id = $1 if string =~ URI_REGEX
|
35
|
+
|
36
|
+
if @source_id.nil? || @source_id.strip.empty?
|
37
|
+
raise ::Songle::SongURI::InvalidSongURIError.new(string)
|
38
|
+
end
|
39
|
+
|
40
|
+
@source_path += @source_id
|
41
|
+
end
|
42
|
+
|
43
|
+
##
|
44
|
+
# @function
|
45
|
+
#
|
46
|
+
def type
|
47
|
+
return TYPE
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
module ::Songle::SongURI
|
3
|
+
class YtShortSongURI
|
4
|
+
include ::Songle::SongURI
|
5
|
+
|
6
|
+
##
|
7
|
+
# @constant
|
8
|
+
#
|
9
|
+
SOURCE_HOST = ::Songle::SongURI::YtSongURI::SOURCE_HOST
|
10
|
+
|
11
|
+
##
|
12
|
+
# @constant
|
13
|
+
#
|
14
|
+
SOURCE_PATH = ::Songle::SongURI::YtSongURI::SOURCE_PATH
|
15
|
+
|
16
|
+
##
|
17
|
+
# @constant
|
18
|
+
#
|
19
|
+
TYPE = ::Songle::SongURI::YtSongURI::TYPE
|
20
|
+
|
21
|
+
##
|
22
|
+
# @constant
|
23
|
+
#
|
24
|
+
URI_REGEX = /\/\/youtu\.be\/(.+)$/
|
25
|
+
|
26
|
+
##
|
27
|
+
# @constructor
|
28
|
+
#
|
29
|
+
def initialize string, options
|
30
|
+
super(string, options)
|
31
|
+
|
32
|
+
@source_host = SOURCE_HOST
|
33
|
+
@source_path = SOURCE_PATH
|
34
|
+
@source_id = $1 if string =~ URI_REGEX
|
35
|
+
|
36
|
+
if @source_id.nil? || @source_id.strip.empty?
|
37
|
+
raise ::Songle::SongURI::InvalidSongURIError.new(string)
|
38
|
+
end
|
39
|
+
|
40
|
+
@source_path += @source_id
|
41
|
+
end
|
42
|
+
|
43
|
+
##
|
44
|
+
# @function
|
45
|
+
#
|
46
|
+
def type
|
47
|
+
return TYPE
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
module ::Songle::SongURI
|
3
|
+
class YtSongURI
|
4
|
+
include ::Songle::SongURI
|
5
|
+
|
6
|
+
##
|
7
|
+
# @constant
|
8
|
+
#
|
9
|
+
SOURCE_HOST = "www.youtube.com"
|
10
|
+
|
11
|
+
##
|
12
|
+
# @constant
|
13
|
+
#
|
14
|
+
SOURCE_PATH = "/watch?v="
|
15
|
+
|
16
|
+
##
|
17
|
+
# @constant
|
18
|
+
#
|
19
|
+
TYPE = "yt"
|
20
|
+
|
21
|
+
##
|
22
|
+
# @constant
|
23
|
+
#
|
24
|
+
URI_REGEX = /#{ SOURCE_HOST.gsub("www.", "") }(#{ SOURCE_PATH.gsub("?", "\\?") }(.+))/
|
25
|
+
|
26
|
+
##
|
27
|
+
# @constructor
|
28
|
+
#
|
29
|
+
def initialize string, options
|
30
|
+
super(string, options)
|
31
|
+
|
32
|
+
@source_host = SOURCE_HOST
|
33
|
+
@source_path = $1 if string =~ URI_REGEX
|
34
|
+
@source_id = $2 if string =~ URI_REGEX
|
35
|
+
|
36
|
+
if @source_id.nil? || @source_id.strip.empty?
|
37
|
+
raise ::Songle::SongURI::InvalidSongURIError.new(string)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
##
|
42
|
+
# @function
|
43
|
+
#
|
44
|
+
def type
|
45
|
+
return TYPE
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "songle-song-uri-parser"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "songle-song-uri-parser"
|
8
|
+
spec.version = ::SongleSongURIParser::VERSION
|
9
|
+
spec.authors = ["Takahiro INOUE"]
|
10
|
+
spec.email = ["takahiro.inoue@aist.go.jp"]
|
11
|
+
|
12
|
+
spec.summary = %q{The implementation of a Song URI parser of the Songle}
|
13
|
+
spec.description = %q{The implementation of a Song URI parser of the Songle}
|
14
|
+
spec.homepage = "https://github.com/hinata/songle-song-uri-parser"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Specify which files should be added to the gem when it is released.
|
18
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
19
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
20
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
21
|
+
end
|
22
|
+
spec.bindir = "exe"
|
23
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
|
+
spec.require_paths = ["lib"]
|
25
|
+
|
26
|
+
spec.add_development_dependency "bundler", "~> 1.0"
|
27
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
28
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: songle-song-uri-parser
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Takahiro INOUE
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-01-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
description: The implementation of a Song URI parser of the Songle
|
56
|
+
email:
|
57
|
+
- takahiro.inoue@aist.go.jp
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".gitlab-ci.yml"
|
64
|
+
- ".rspec"
|
65
|
+
- ".ruby-version"
|
66
|
+
- CHANGELOG.md
|
67
|
+
- Dockerfile
|
68
|
+
- Gemfile
|
69
|
+
- Gemfile.lock
|
70
|
+
- LICENSE.txt
|
71
|
+
- README.md
|
72
|
+
- Rakefile
|
73
|
+
- lib/songle-song-uri-parser.rb
|
74
|
+
- lib/songle/song_uri.rb
|
75
|
+
- lib/songle/song_uri/invalid_song_uri_error.rb
|
76
|
+
- lib/songle/song_uri/mp3_song_uri.rb
|
77
|
+
- lib/songle/song_uri/nn_scheme_song_uri.rb
|
78
|
+
- lib/songle/song_uri/nn_short_song_uri.rb
|
79
|
+
- lib/songle/song_uri/nn_song_uri.rb
|
80
|
+
- lib/songle/song_uri/sc_scheme_song_uri.rb
|
81
|
+
- lib/songle/song_uri/sc_song_uri.rb
|
82
|
+
- lib/songle/song_uri/yt_scheme_song_uri.rb
|
83
|
+
- lib/songle/song_uri/yt_short_song_uri.rb
|
84
|
+
- lib/songle/song_uri/yt_song_uri.rb
|
85
|
+
- songle-song-uri-parser.gemspec
|
86
|
+
homepage: https://github.com/hinata/songle-song-uri-parser
|
87
|
+
licenses:
|
88
|
+
- MIT
|
89
|
+
metadata: {}
|
90
|
+
post_install_message:
|
91
|
+
rdoc_options: []
|
92
|
+
require_paths:
|
93
|
+
- lib
|
94
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
requirements: []
|
105
|
+
rubygems_version: 3.0.1
|
106
|
+
signing_key:
|
107
|
+
specification_version: 4
|
108
|
+
summary: The implementation of a Song URI parser of the Songle
|
109
|
+
test_files: []
|