mixcloud_parser 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +45 -0
- data/Rakefile +1 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/mixcloud_parser.rb +7 -0
- data/lib/mixcloud_parser/parser.rb +80 -0
- data/lib/mixcloud_parser/version.rb +3 -0
- data/mixcloud_parser.gemspec +27 -0
- data/spec/mixcloud_parser_spec.rb +29 -0
- data/spec/spec_helper.rb +5 -0
- metadata +145 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 46c70a8f32ff2781835e3995bb1e9888e1a685ee
|
4
|
+
data.tar.gz: a8a58837a9cef35625fd63ee650302df73ef6977
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e333259fb293de40f2ca2c08127aae469fc5e554b5133f010f7efe6643cdbfcae9e5a8726c6fa383694eaf20214a3ff8f1097b8a57be056ef9a9a292122881ca
|
7
|
+
data.tar.gz: 3188b3f217ee2407031867f628011948d1f42ebb8593ba48032ddd48d1507ac5d7132defe501e9b24c8897469e3ded8bbc1da6a90b5febe47a87261f5ea3d6b4
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 TakteS
|
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,45 @@
|
|
1
|
+
# MixcloudParser
|
2
|
+
|
3
|
+
Podcasts parser from mixcloud.com
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'mixcloud_parser'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install mixcloud_parser
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
gem 'mixcloud_parser'
|
25
|
+
|
26
|
+
file = MixcloudParser::Parser.new('https://www.mixcloud.com/link_to_podcast', '/path/to/your/folder')
|
27
|
+
file.parse
|
28
|
+
```
|
29
|
+
|
30
|
+
|
31
|
+
## Development
|
32
|
+
|
33
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
34
|
+
|
35
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
36
|
+
|
37
|
+
## Contributing
|
38
|
+
|
39
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/mixcloud_parser.
|
40
|
+
|
41
|
+
|
42
|
+
## License
|
43
|
+
|
44
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
45
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "mixcloud_parser"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
module MixcloudParser
|
2
|
+
class Parser
|
3
|
+
def initialize(url, path)
|
4
|
+
@url = url
|
5
|
+
@path = path
|
6
|
+
end
|
7
|
+
|
8
|
+
# Main parser method
|
9
|
+
def parse
|
10
|
+
# Try parse file
|
11
|
+
begin
|
12
|
+
# Open browser window for getting file name and URL (Mixcloud gives link only after starting a podcast)
|
13
|
+
browser = Watir::Browser.new
|
14
|
+
browser.goto @url
|
15
|
+
|
16
|
+
# Parse the resulted page through nokogiri
|
17
|
+
page = Nokogiri::HTML(browser.html)
|
18
|
+
|
19
|
+
# Close browser
|
20
|
+
browser.close
|
21
|
+
|
22
|
+
# Get file name
|
23
|
+
filename = page.search('cloudcast-title', '//h1').last.content
|
24
|
+
|
25
|
+
puts "Downloading '#{ filename }'..."
|
26
|
+
|
27
|
+
# Get file URL
|
28
|
+
url = page.css('audio')
|
29
|
+
url = URI.extract(url.to_s).first
|
30
|
+
|
31
|
+
# Check the download
|
32
|
+
check_file(url, filename)
|
33
|
+
|
34
|
+
# Return error message and retry
|
35
|
+
rescue
|
36
|
+
puts 'Error. Retrying...'
|
37
|
+
|
38
|
+
browser.close
|
39
|
+
retry
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
# Checking the download
|
46
|
+
def check_file(url, filename)
|
47
|
+
# Set full file name (with path and extension)
|
48
|
+
filename = @path + filename unless filename.include?(@path)
|
49
|
+
filename += '.m4a' unless filename.include?('m4a')
|
50
|
+
|
51
|
+
# Create a path if him is not exist
|
52
|
+
FileUtils.mkdir_p(@path) unless File.directory?(@path)
|
53
|
+
|
54
|
+
# Print message if file successfuly downloaded
|
55
|
+
if File.exist?(filename) && File.size(filename) > 0
|
56
|
+
puts "#{ filename.split('/').last } successfuly downloaded!"
|
57
|
+
|
58
|
+
# Download file if him exist, but him size is 0
|
59
|
+
elsif File.exist?(filename) && File.size(filename) == 0
|
60
|
+
download_file(url, filename)
|
61
|
+
|
62
|
+
# Create and download file if him is not exist
|
63
|
+
else
|
64
|
+
File.new(filename, 'w+')
|
65
|
+
download_file(url, filename)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
# Downloading
|
70
|
+
def download_file(url, filename)
|
71
|
+
File.open(filename, 'wb') do |saved_file|
|
72
|
+
open(url) do |read_file|
|
73
|
+
saved_file.write(read_file.read)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
check_file(url, filename)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'mixcloud_parser/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'mixcloud_parser'
|
8
|
+
spec.version = MixcloudParser::VERSION
|
9
|
+
spec.authors = ['TakteS']
|
10
|
+
spec.email = ['takt96@gmail.com']
|
11
|
+
|
12
|
+
spec.summary = %q{ Podcasts parser from mixcloud.com }
|
13
|
+
spec.homepage = 'https://github.com/TakteS/mixcloud_parser'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_development_dependency 'bundler', '~> 1.10'
|
22
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
23
|
+
spec.add_development_dependency 'rspec'
|
24
|
+
spec.add_development_dependency 'nokogiri'
|
25
|
+
spec.add_development_dependency 'watir-webdriver'
|
26
|
+
spec.add_development_dependency 'open-uri'
|
27
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe MixcloudParser do
|
4
|
+
describe 'Check file exist' do
|
5
|
+
context 'when file is downloaded' do
|
6
|
+
path = '/home/taktes/MixCloud/'
|
7
|
+
url = 'https://www.mixcloud.com/RedBullThre3style/dj-short-philippines-cebu-qualifier/'
|
8
|
+
file = MixcloudParser::Parser.new(url, path)
|
9
|
+
file.parse
|
10
|
+
|
11
|
+
it 'file exist' do
|
12
|
+
expect(File.exist?("#{ path }DJ Short | Philippines | Cebu Qualifier.m4a")).to equal(true)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe 'Check file size' do
|
18
|
+
context 'when file is downloaded' do
|
19
|
+
path = '/home/taktes/MixCloud/'
|
20
|
+
url = 'https://www.mixcloud.com/RedBullThre3style/dj-short-philippines-cebu-qualifier/'
|
21
|
+
file = MixcloudParser::Parser.new(url, path)
|
22
|
+
file.parse
|
23
|
+
|
24
|
+
it 'file size > 0' do
|
25
|
+
expect(File.size("#{ path }DJ Short | Philippines | Cebu Qualifier.m4a") > 0).to equal(true)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,145 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mixcloud_parser
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- TakteS
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-10-18 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.10'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.10'
|
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: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: nokogiri
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: watir-webdriver
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: open-uri
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description:
|
98
|
+
email:
|
99
|
+
- takt96@gmail.com
|
100
|
+
executables:
|
101
|
+
- console
|
102
|
+
- setup
|
103
|
+
extensions: []
|
104
|
+
extra_rdoc_files: []
|
105
|
+
files:
|
106
|
+
- ".gitignore"
|
107
|
+
- Gemfile
|
108
|
+
- LICENSE.txt
|
109
|
+
- README.md
|
110
|
+
- Rakefile
|
111
|
+
- bin/console
|
112
|
+
- bin/setup
|
113
|
+
- lib/mixcloud_parser.rb
|
114
|
+
- lib/mixcloud_parser/parser.rb
|
115
|
+
- lib/mixcloud_parser/version.rb
|
116
|
+
- mixcloud_parser.gemspec
|
117
|
+
- spec/mixcloud_parser_spec.rb
|
118
|
+
- spec/spec_helper.rb
|
119
|
+
homepage: https://github.com/TakteS/mixcloud_parser
|
120
|
+
licenses:
|
121
|
+
- MIT
|
122
|
+
metadata: {}
|
123
|
+
post_install_message:
|
124
|
+
rdoc_options: []
|
125
|
+
require_paths:
|
126
|
+
- lib
|
127
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
133
|
+
requirements:
|
134
|
+
- - ">="
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: '0'
|
137
|
+
requirements: []
|
138
|
+
rubyforge_project:
|
139
|
+
rubygems_version: 2.4.8
|
140
|
+
signing_key:
|
141
|
+
specification_version: 4
|
142
|
+
summary: Podcasts parser from mixcloud.com
|
143
|
+
test_files:
|
144
|
+
- spec/mixcloud_parser_spec.rb
|
145
|
+
- spec/spec_helper.rb
|