douyin_download 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 96fae7569cf04a6214adf8f841e3bdafc507d73e57cf3e377e2381501bc77dec
4
+ data.tar.gz: a5f83e945e6f7e14f01cea4670632538cab8fe3c92f81e205988b36c2d7f6b11
5
+ SHA512:
6
+ metadata.gz: 037ca005a48a0f3b9776e5cf7bfbc927d3a527ced7952cc4f6c342253c1dfe52de0f3fa2f3ba4c61f0f59477659f14050fefbe98500980622ab6d11e5b39ad2c
7
+ data.tar.gz: 61c50b6f4f8feac86fbf759068c2f8ae6fbe8c8e0a5cb75f8aef3eeb8a09915905cc6f7624c8413abeb3c12df59338cbef5da1dc289e9391dce13069c3f6a22a
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+
13
+ .ruby-version
14
+ .ruby-gemset
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.6.1
7
+ before_install: gem install bundler -v 1.17.3
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at aotianlong@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in douyin_download.gemspec
6
+ gemspec
7
+
8
+ # gem "rake", ">= 12.3.3"
9
+ gem 'faraday'
10
+ gem 'thor'
data/Gemfile.lock ADDED
@@ -0,0 +1,41 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ douyin_download (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.3)
10
+ faraday (1.0.1)
11
+ multipart-post (>= 1.2, < 3)
12
+ multipart-post (2.1.1)
13
+ rake (13.0.1)
14
+ rspec (3.9.0)
15
+ rspec-core (~> 3.9.0)
16
+ rspec-expectations (~> 3.9.0)
17
+ rspec-mocks (~> 3.9.0)
18
+ rspec-core (3.9.1)
19
+ rspec-support (~> 3.9.1)
20
+ rspec-expectations (3.9.1)
21
+ diff-lcs (>= 1.2.0, < 2.0)
22
+ rspec-support (~> 3.9.0)
23
+ rspec-mocks (3.9.1)
24
+ diff-lcs (>= 1.2.0, < 2.0)
25
+ rspec-support (~> 3.9.0)
26
+ rspec-support (3.9.2)
27
+ thor (1.0.1)
28
+
29
+ PLATFORMS
30
+ ruby
31
+
32
+ DEPENDENCIES
33
+ bundler (~> 1.17)
34
+ douyin_download!
35
+ faraday
36
+ rake (>= 12.3.3)
37
+ rspec (~> 3.0)
38
+ thor
39
+
40
+ BUNDLED WITH
41
+ 1.17.3
data/README.md ADDED
@@ -0,0 +1,48 @@
1
+ # DouyinDownload
2
+
3
+ DouyinDownload can download douyin 抖音 video without watermark
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'douyin_download'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install douyin_download
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+ require "douyin_download"
25
+ url = "https://v.douyin.com/T4Sjhd/"
26
+ parser = DouyinDownload::Parser.new url
27
+ parser.play_url # video url without watermark
28
+ ```
29
+
30
+ ```bash
31
+ douyin_download download https://v.douyin.com/T4Sjhd/
32
+ ```
33
+
34
+ this command should download the video named T4Sjhd.mp4
35
+
36
+ ## Development
37
+
38
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
39
+
40
+ 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).
41
+
42
+ ## Contributing
43
+
44
+ Bug reports and pull requests are welcome on GitHub at https://github.com/aotianlong/douyin_download. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
45
+
46
+ ## Code of Conduct
47
+
48
+ Everyone interacting in the DouyinDownload project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/douyin_download/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/SECURITY.md ADDED
@@ -0,0 +1,21 @@
1
+ # Security Policy
2
+
3
+ ## Supported Versions
4
+
5
+ Use this section to tell people about which versions of your project are
6
+ currently being supported with security updates.
7
+
8
+ | Version | Supported |
9
+ | ------- | ------------------ |
10
+ | 5.1.x | :white_check_mark: |
11
+ | 5.0.x | :x: |
12
+ | 4.0.x | :white_check_mark: |
13
+ | < 4.0 | :x: |
14
+
15
+ ## Reporting a Vulnerability
16
+
17
+ Use this section to tell people how to report a vulnerability.
18
+
19
+ Tell them where to go, how often they can expect to get an update on a
20
+ reported vulnerability, what to expect if the vulnerability is accepted or
21
+ declined, etc.
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "douyin_download"
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(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,43 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "douyin_download/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "douyin_download"
8
+ spec.version = DouyinDownload::VERSION
9
+ spec.authors = ["aotianlong"]
10
+ spec.email = ["aotianlong@gmail.com"]
11
+
12
+ spec.summary = %q{download douyin video}
13
+ spec.description = %q{download douyin video without watermark}
14
+ spec.homepage = "https://www.aotianlong.com"
15
+
16
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
18
+ =begin
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata["allowed_push_host"] = "https://rubygems.org'"
21
+
22
+ spec.metadata["homepage_uri"] = spec.homepage
23
+ spec.metadata["source_code_uri"] = "https://github.com/aotianlong/douyin_download"
24
+ spec.metadata["changelog_uri"] = "https://github.com/aotianlong/douyin_download/CHANGELOG.md"
25
+ else
26
+ raise "RubyGems 2.0 or newer is required to protect against " \
27
+ "public gem pushes."
28
+ end
29
+ =end
30
+
31
+ # Specify which files should be added to the gem when it is released.
32
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
33
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
34
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
35
+ end
36
+ spec.bindir = "exe"
37
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
38
+ spec.require_paths = ["lib"]
39
+
40
+ spec.add_development_dependency "bundler", "~> 1.17"
41
+ spec.add_development_dependency "rake", ">= 12.3.3"
42
+ spec.add_development_dependency "rspec", "~> 3.0"
43
+ end
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env ruby
2
+ require "bundler/setup"
3
+ require "douyin_download"
4
+ require "thor"
5
+ class DouyinDownloadCli < Thor
6
+ desc "download URL", "download a video from douyin shared url"
7
+ def download(url)
8
+ begin
9
+ puts "download #{url}"
10
+ parser = DouyinDownload::Parser.new(url)
11
+ play_url = parser.play_url
12
+ description = parser.description
13
+ filename = parser.download
14
+ if filename
15
+ puts "download complete, file: #{filename}"
16
+ else
17
+ puts "download failed."
18
+ end
19
+ rescue Exception => e
20
+ puts "download failed: '#{e.message}'"
21
+ end
22
+ end
23
+ end
24
+ DouyinDownloadCli.start(ARGV)
@@ -0,0 +1,7 @@
1
+ require "douyin_download/version"
2
+ require "douyin_download/parser"
3
+
4
+ module DouyinDownload
5
+ class Error < StandardError; end
6
+ # Your code goes here...
7
+ end
@@ -0,0 +1,94 @@
1
+ require "faraday"
2
+ require "json"
3
+ class DouyinDownload::Parser
4
+ MOBILE_USER_AGENT = "Mozilla/5.0 (iPhone; CPU iPhone OS 12_1_4 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.0 Mobile/15E148 Safari/604.1"
5
+ class InvalidDouyinUrlError < Exception; end
6
+ def initialize(url)
7
+ @url = url
8
+ regexp = /v\.douyin\.com\/[\w\d]+/
9
+ unless @url =~ regexp
10
+ raise InvalidDouyinUrlError.new("Invalid douyin url: #{@url}")
11
+ end
12
+ end
13
+
14
+ def douyin_id
15
+ url = @url.gsub /https?:\/\/v\.douyin\.com\//,''
16
+ url.gsub '/',''
17
+ end
18
+
19
+ def long_url
20
+ @long_url ||= begin
21
+ # url = "https://v.douyin.com/T4Sjhd/"
22
+ # body = Faraday.get(@url).body
23
+ headers = Faraday.get(@url).headers
24
+ headers['location']
25
+ end
26
+ end
27
+
28
+ def download_url
29
+ info.dig('item_list',0,'video','download_addr','url_list',0)
30
+ end
31
+
32
+ def description
33
+ info.dig('item_list',0,'desc')
34
+ end
35
+
36
+ def api_play_url
37
+ info.dig('item_list',0,'video','play_addr','url_list',0)
38
+ end
39
+
40
+ def play_url
41
+ # 这个是终极的播放url
42
+ # http://v9-dy-y.ixigua.com/390e2ef55562a7f85c79d98dc9814475/5ea127a5/video/tos/cn/tos-cn-ve-15/7131a6682c1040c1aa713f8405c34670/?a=1128&amp;br=0&amp;bt=907&amp;cr=0&amp;cs=0&amp;dr=0&amp;ds=6&amp;er=&amp;l=202004231229000100140472040B062432&amp;lr=&amp;qs=0&amp;rc=M3I7NG87PHVodDMzNmkzM0ApaTM2Ojc3Zzs8N2Y6ZTU7ZGdfMGJsNTNhNmRfLS0tLS9zcy40NDU0YDM2LWA2NC1eLzM6Yw%3D%3D&amp;vl=&amp;vr
43
+ headers = Faraday.get(api_play_url,{},'User-Agent': MOBILE_USER_AGENT).headers
44
+ headers['location']
45
+ end
46
+
47
+ def info
48
+ # 用移动端设备ua访问该页面
49
+ @info ||= begin
50
+ result = {}
51
+ ua = MOBILE_USER_AGENT
52
+ body = Faraday.get(long_url, {}, 'User-Agent': ua).body
53
+ # puts body
54
+ regexp = /\.init\(\{(.+)\}\)\;\s+\}\)\;/m
55
+ api_url = nil
56
+ if body =~ regexp
57
+ json = "{#{$1}}"
58
+ data = parse_json json
59
+ # pp data
60
+
61
+ # 构建api url
62
+ item_ids = data[:itemId]
63
+ dytk = data[:dytk]
64
+ api_url = "https://www.iesdouyin.com/web/api/v2/aweme/iteminfo/?item_ids=#{item_ids}&dytk=#{dytk}"
65
+ else
66
+ # byebug
67
+ end
68
+
69
+ if api_url
70
+ body = Faraday.get(api_url).body
71
+ result = JSON.parse body
72
+ end
73
+ result
74
+ end
75
+ end
76
+
77
+ def download(filename: nil)
78
+ begin
79
+ body = Faraday.get(play_url, {}, 'User-Agent': MOBILE_USER_AGENT).body
80
+ # filename ||= [douyin_id, description].join("-") + ".mp4"
81
+ filename ||= douyin_id + ".mp4"
82
+ File.open(filename,"wb+"){|f|
83
+ f.write body
84
+ }
85
+ filename
86
+ rescue Exception
87
+ end
88
+ end
89
+
90
+ private
91
+ def parse_json(str)
92
+ eval str
93
+ end
94
+ end
@@ -0,0 +1,3 @@
1
+ module DouyinDownload
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: douyin_download
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - aotianlong
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-04-23 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.17'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.17'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 12.3.3
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 12.3.3
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: download douyin video without watermark
56
+ email:
57
+ - aotianlong@gmail.com
58
+ executables:
59
+ - douyin_download
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - ".rspec"
65
+ - ".travis.yml"
66
+ - CODE_OF_CONDUCT.md
67
+ - Gemfile
68
+ - Gemfile.lock
69
+ - README.md
70
+ - Rakefile
71
+ - SECURITY.md
72
+ - bin/console
73
+ - bin/setup
74
+ - douyin_download.gemspec
75
+ - exe/douyin_download
76
+ - lib/douyin_download.rb
77
+ - lib/douyin_download/parser.rb
78
+ - lib/douyin_download/version.rb
79
+ homepage: https://www.aotianlong.com
80
+ licenses: []
81
+ metadata: {}
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirements: []
97
+ rubygems_version: 3.0.2
98
+ signing_key:
99
+ specification_version: 4
100
+ summary: download douyin video
101
+ test_files: []