repotube 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +6 -0
  3. data/exe/repotube +31 -0
  4. data/lib/repotube.rb +84 -0
  5. metadata +95 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f85f05d82a54961d23fef432c76187dd2a3ce6c705201897b459de97ac00f03a
4
+ data.tar.gz: 0bdb04a417cc8b546d80b9fe26fa7f73d2d68c76703646686354cbd4b9f7dd94
5
+ SHA512:
6
+ metadata.gz: d464bc9d304b7540ac13a90c66ee13e50b1b8263f25d22902b5c14a1b4f55d29bc1ad58769b1fffba8c27c8ea196fa3bfdf72119307307ee862d069725760c28
7
+ data.tar.gz: 86551e8194965119fca08ef39ec7463c41e0e5c74042a59adea6548d43d99c0a90b65626becd68797801ba6e21cccf8f46698c5b9a772a6ddafd4bdfbdc20a7f
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify dependencies in repotube.gemspec
6
+ gemspec
data/exe/repotube ADDED
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH.unshift File.expand_path("../lib", __dir__)
4
+
5
+ require 'mercenary'
6
+ require 'repotube'
7
+
8
+ Mercenary.program(:repotube) do |p|
9
+
10
+ p.version RepoTube::VERSION
11
+ p.description "YouTube time-marked URLs from Git commit timestamps"
12
+ p.syntax "repotube [options] <youtube short URL>"
13
+ p.option "start", "-s SECONDS", 'Set the timestamp for the first commit; defaults to 0'
14
+ p.option "offset", "-o SECONDS", "Set the offset, from the start of the video, for the first commit;\n defaults to 0"
15
+ p.option "first", "-f HASH", "Set the hash of the first commit in the video"
16
+ p.option "last", "-l HASH", "Set the hash of the last commit in the video"
17
+
18
+ p.action do |args, options|
19
+ thing = RepoTube::Program.new(args,options)
20
+ if thing.is_repo?
21
+ puts "At least we're in a Git repo"
22
+ thing.process_commits
23
+ puts thing.commits
24
+ thing.output_index
25
+ else
26
+ puts "Not a Git repo!"
27
+ abort
28
+ end
29
+ end
30
+
31
+ end
data/lib/repotube.rb ADDED
@@ -0,0 +1,84 @@
1
+ #! /usr/bin/env ruby
2
+
3
+ require 'pathname'
4
+
5
+ module RepoTube
6
+ VERSION = "0.1.0"
7
+
8
+ class Program
9
+ #COMMITS = `git log #{RANGE} --date=unix --format=tformat:"%at|%h|%s" --reverse`
10
+
11
+ attr_reader :git_path, :url, :start, :offset, :first, :last, :commits
12
+
13
+ def initialize(args,options)
14
+ @git_path = Pathname.new(File.expand_path('.git', Dir.pwd))
15
+
16
+ @url = args.last.chomp unless args.length < 1
17
+ @start = set_value(options['start'].to_i, 0)
18
+ @offset = set_value(options['offset'].to_i, 0)
19
+ @first = set_value(options['first'], "")
20
+ @last = set_value(options['last'], "HEAD")
21
+
22
+ @commits = log_commits
23
+
24
+ end
25
+
26
+ def is_repo?
27
+ @git_path.exist?
28
+ end
29
+
30
+ def log_commits
31
+ # TODO: include the range
32
+ if !@first.empty?
33
+ range = "#{@first}~1..#{@last}"
34
+ else
35
+ range = ""
36
+ end
37
+ if is_repo?
38
+ `git log #{range} --date=unix --format=tformat:"%at|%h|%s" --reverse`
39
+ else
40
+ puts "Oops. repotube must be run in a Git repository"
41
+ abort
42
+ end
43
+ end
44
+
45
+ def set_value(custom,default)
46
+ if custom.to_s.empty?
47
+ custom = default
48
+ end
49
+ custom
50
+ end
51
+
52
+ def process_commits
53
+ commits = @commits.split("\n")
54
+
55
+ commits.map! do |commit|
56
+ c = commit.split("|")
57
+ commit = {
58
+ ut: c[0].to_i,
59
+ ch: c[1],
60
+ cs: c[2]
61
+ }
62
+ end
63
+
64
+ commits[0][:offset] = @start
65
+ commits[1][:offset] = @offset
66
+
67
+ commits.each_index do |i|
68
+ if (i > 1)
69
+ commits[i][:offset] = commits[i-1][:ut] - commits[0][:ut] + @offset
70
+ end
71
+ end
72
+
73
+ @commits = commits
74
+ end
75
+
76
+ def output_index
77
+ puts "Video Index by Commit:"
78
+ @commits.each do |commit|
79
+ puts "#{commit[:cs]}: https://youtu.be/V-rIj30x_LM?t=#{commit[:offset]}"
80
+ end
81
+ end
82
+
83
+ end
84
+ end
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: repotube
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Karl Stolley
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-05-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: mercenary
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.4'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.4'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '12.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '12.3'
55
+ description: Ruby CLI app to generate YouTube time-markers from the timestamps of
56
+ Git commits.
57
+ email:
58
+ - karl.stolley@gmail.com
59
+ executables:
60
+ - repotube
61
+ extensions: []
62
+ extra_rdoc_files: []
63
+ files:
64
+ - Gemfile
65
+ - exe/repotube
66
+ - lib/repotube.rb
67
+ homepage: https://github.com/karlstolley/repotube
68
+ licenses:
69
+ - MIT
70
+ metadata:
71
+ bug_tracker_uri: https://github.com/karlstolley/repotube/issues
72
+ changelog_uri: https://github.com/karlstolley/repotube/releases
73
+ documentation_uri: https://github.com/karlstolley/repotube/README.md
74
+ homepage_uri: https://github.com/karlstolley/repotube
75
+ source_code_uri: https://github.com/karlstolley/repotube
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - "~>"
83
+ - !ruby/object:Gem::Version
84
+ version: '2.6'
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubygems_version: 3.1.2
92
+ signing_key:
93
+ specification_version: 4
94
+ summary: YouTube time-marked URLs from Git commit timestamps
95
+ test_files: []