universal_pipe_handler 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (123) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +461 -0
  3. data/doc/README.gen +417 -0
  4. data/doc/todo/todo_for_the_universal_pipe_handler_project.md +300 -0
  5. data/img/UNIVERSAL_PIPE_HANDLER_LOGO.jpg +0 -0
  6. data/img/pipe_paradise.png +0 -0
  7. data/lib/universal_pipe_handler/base/base.rb +147 -0
  8. data/lib/universal_pipe_handler/cmdlet/cmdlet.rb +287 -0
  9. data/lib/universal_pipe_handler/cmdlets/add.rb +15 -0
  10. data/lib/universal_pipe_handler/cmdlets/add_audio.rb +22 -0
  11. data/lib/universal_pipe_handler/cmdlets/all.rb +37 -0
  12. data/lib/universal_pipe_handler/cmdlets/any.rb +25 -0
  13. data/lib/universal_pipe_handler/cmdlets/ascii_video.rb +30 -0
  14. data/lib/universal_pipe_handler/cmdlets/assign.rb +24 -0
  15. data/lib/universal_pipe_handler/cmdlets/capture_screen.rb +46 -0
  16. data/lib/universal_pipe_handler/cmdlets/colourize.rb +35 -0
  17. data/lib/universal_pipe_handler/cmdlets/convert_to.rb +21 -0
  18. data/lib/universal_pipe_handler/cmdlets/convert_to_images.rb +17 -0
  19. data/lib/universal_pipe_handler/cmdlets/convert_to_mp3.rb +28 -0
  20. data/lib/universal_pipe_handler/cmdlets/convert_to_wav.rb +17 -0
  21. data/lib/universal_pipe_handler/cmdlets/copy_directories.rb +23 -0
  22. data/lib/universal_pipe_handler/cmdlets/count_character.rb +31 -0
  23. data/lib/universal_pipe_handler/cmdlets/count_longest_row.rb +21 -0
  24. data/lib/universal_pipe_handler/cmdlets/crop.rb +26 -0
  25. data/lib/universal_pipe_handler/cmdlets/cut.rb +101 -0
  26. data/lib/universal_pipe_handler/cmdlets/days.rb +41 -0
  27. data/lib/universal_pipe_handler/cmdlets/decolourize.rb +25 -0
  28. data/lib/universal_pipe_handler/cmdlets/download.rb +30 -0
  29. data/lib/universal_pipe_handler/cmdlets/download_torrent.rb +17 -0
  30. data/lib/universal_pipe_handler/cmdlets/duration.rb +34 -0
  31. data/lib/universal_pipe_handler/cmdlets/extract.rb +27 -0
  32. data/lib/universal_pipe_handler/cmdlets/extract_all.rb +23 -0
  33. data/lib/universal_pipe_handler/cmdlets/extract_audio.rb +30 -0
  34. data/lib/universal_pipe_handler/cmdlets/extract_video.rb +18 -0
  35. data/lib/universal_pipe_handler/cmdlets/find_all.rb +40 -0
  36. data/lib/universal_pipe_handler/cmdlets/generate_random_video.rb +29 -0
  37. data/lib/universal_pipe_handler/cmdlets/generate_string.rb +27 -0
  38. data/lib/universal_pipe_handler/cmdlets/get_all_audio_files.rb +33 -0
  39. data/lib/universal_pipe_handler/cmdlets/get_all_files.rb +61 -0
  40. data/lib/universal_pipe_handler/cmdlets/get_all_images.rb +47 -0
  41. data/lib/universal_pipe_handler/cmdlets/get_all_images_including_subdirs.rb +26 -0
  42. data/lib/universal_pipe_handler/cmdlets/get_all_video_files.rb +34 -0
  43. data/lib/universal_pipe_handler/cmdlets/get_last_characters.rb +24 -0
  44. data/lib/universal_pipe_handler/cmdlets/help.rb +36 -0
  45. data/lib/universal_pipe_handler/cmdlets/identify.rb +29 -0
  46. data/lib/universal_pipe_handler/cmdlets/increase_audio.rb +26 -0
  47. data/lib/universal_pipe_handler/cmdlets/install.rb +32 -0
  48. data/lib/universal_pipe_handler/cmdlets/match_regex.rb +24 -0
  49. data/lib/universal_pipe_handler/cmdlets/n_directories.rb +25 -0
  50. data/lib/universal_pipe_handler/cmdlets/n_files.rb +20 -0
  51. data/lib/universal_pipe_handler/cmdlets/n_words.rb +25 -0
  52. data/lib/universal_pipe_handler/cmdlets/number_lines.rb +34 -0
  53. data/lib/universal_pipe_handler/cmdlets/open_in_browser.rb +40 -0
  54. data/lib/universal_pipe_handler/cmdlets/pad_left.rb +20 -0
  55. data/lib/universal_pipe_handler/cmdlets/pad_right.rb +20 -0
  56. data/lib/universal_pipe_handler/cmdlets/play.rb +18 -0
  57. data/lib/universal_pipe_handler/cmdlets/position.rb +21 -0
  58. data/lib/universal_pipe_handler/cmdlets/processes.rb +18 -0
  59. data/lib/universal_pipe_handler/cmdlets/random.rb +21 -0
  60. data/lib/universal_pipe_handler/cmdlets/random_video.rb +23 -0
  61. data/lib/universal_pipe_handler/cmdlets/read_file.rb +44 -0
  62. data/lib/universal_pipe_handler/cmdlets/read_line.rb +31 -0
  63. data/lib/universal_pipe_handler/cmdlets/read_n_lines.rb +38 -0
  64. data/lib/universal_pipe_handler/cmdlets/read_n_lines_inverted.rb +36 -0
  65. data/lib/universal_pipe_handler/cmdlets/remove_audio.rb +22 -0
  66. data/lib/universal_pipe_handler/cmdlets/remove_comments.rb +26 -0
  67. data/lib/universal_pipe_handler/cmdlets/remove_directories.rb +29 -0
  68. data/lib/universal_pipe_handler/cmdlets/remove_html.rb +25 -0
  69. data/lib/universal_pipe_handler/cmdlets/remove_newlines.rb +23 -0
  70. data/lib/universal_pipe_handler/cmdlets/remove_numbers.rb +25 -0
  71. data/lib/universal_pipe_handler/cmdlets/repackage_to.rb +27 -0
  72. data/lib/universal_pipe_handler/cmdlets/replace_underscores.rb +29 -0
  73. data/lib/universal_pipe_handler/cmdlets/resize.rb +39 -0
  74. data/lib/universal_pipe_handler/cmdlets/resize_image.rb +45 -0
  75. data/lib/universal_pipe_handler/cmdlets/reverse.rb +22 -0
  76. data/lib/universal_pipe_handler/cmdlets/screenshot.rb +41 -0
  77. data/lib/universal_pipe_handler/cmdlets/search_torrent.rb +24 -0
  78. data/lib/universal_pipe_handler/cmdlets/seconds.rb +23 -0
  79. data/lib/universal_pipe_handler/cmdlets/select.rb +23 -0
  80. data/lib/universal_pipe_handler/cmdlets/show_lines.rb +31 -0
  81. data/lib/universal_pipe_handler/cmdlets/shuffle.rb +16 -0
  82. data/lib/universal_pipe_handler/cmdlets/shuffle_csv.rb +55 -0
  83. data/lib/universal_pipe_handler/cmdlets/size.rb +21 -0
  84. data/lib/universal_pipe_handler/cmdlets/sort_alphabetical.rb +20 -0
  85. data/lib/universal_pipe_handler/cmdlets/sort_by_date.rb +23 -0
  86. data/lib/universal_pipe_handler/cmdlets/starts_with.rb +25 -0
  87. data/lib/universal_pipe_handler/cmdlets/stat_file.rb +61 -0
  88. data/lib/universal_pipe_handler/cmdlets/to_ascii.rb +38 -0
  89. data/lib/universal_pipe_handler/cmdlets/to_camel_case.rb +38 -0
  90. data/lib/universal_pipe_handler/cmdlets/to_dna.rb +31 -0
  91. data/lib/universal_pipe_handler/cmdlets/to_movie.rb +16 -0
  92. data/lib/universal_pipe_handler/cmdlets/to_pdf.rb +58 -0
  93. data/lib/universal_pipe_handler/cmdlets/translate.rb +36 -0
  94. data/lib/universal_pipe_handler/cmdlets/upload_to.rb +29 -0
  95. data/lib/universal_pipe_handler/cmdlets/word_count.rb +39 -0
  96. data/lib/universal_pipe_handler/cmdlets/word_wrap.rb +26 -0
  97. data/lib/universal_pipe_handler/cmdlets/write_to.rb +51 -0
  98. data/lib/universal_pipe_handler/cmdlets/years.rb +30 -0
  99. data/lib/universal_pipe_handler/cmdlets_handler/cmdlets_handler.rb +193 -0
  100. data/lib/universal_pipe_handler/colours/colourize.rb +112 -0
  101. data/lib/universal_pipe_handler/colours/colours.rb +54 -0
  102. data/lib/universal_pipe_handler/configuration/configuration.rb +18 -0
  103. data/lib/universal_pipe_handler/constants/constants.rb +201 -0
  104. data/lib/universal_pipe_handler/dataset/dataset.rb +14 -0
  105. data/lib/universal_pipe_handler/project/project.rb +36 -0
  106. data/lib/universal_pipe_handler/requires/do_require_the_individual_cmdlet_files.rb +21 -0
  107. data/lib/universal_pipe_handler/requires/require_the_universal_pipe_handler.rb +14 -0
  108. data/lib/universal_pipe_handler/shell/shell.rb +256 -0
  109. data/lib/universal_pipe_handler/toplevel_methods/all_actions.rb +48 -0
  110. data/lib/universal_pipe_handler/toplevel_methods/cmdlet_directory.rb +22 -0
  111. data/lib/universal_pipe_handler/toplevel_methods/e.rb +16 -0
  112. data/lib/universal_pipe_handler/toplevel_methods/misc.rb +54 -0
  113. data/lib/universal_pipe_handler/toplevel_methods/rds.rb +18 -0
  114. data/lib/universal_pipe_handler/toplevel_methods/token.rb +18 -0
  115. data/lib/universal_pipe_handler/version/version.rb +19 -0
  116. data/lib/universal_pipe_handler/yaml/aliases_to_cmdlets.yml +250 -0
  117. data/lib/universal_pipe_handler/yaml/allowed_cmdlets.yml +118 -0
  118. data/lib/universal_pipe_handler/yaml/predefined_methods.yml +15 -0
  119. data/lib/universal_pipe_handler.rb +5 -0
  120. data/test/testing_the_universal_pipe_handler.rb +65 -0
  121. data/test/this_file +46 -0
  122. data/universal_pipe_handler.gemspec +80 -0
  123. metadata +299 -0
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'universal_pipe_handler/cmdlets/count_longest_row.rb'
6
+ # =========================================================================== #
7
+ module UniversalPipeHandler
8
+
9
+ # ========================================================================= #
10
+ # === UniversalPipeHandler.cmdlet_count_longest_row
11
+ # ========================================================================= #
12
+ def self.cmdlet_count_longest_row
13
+ n_number = 0
14
+ result?.each {|_|
15
+ n_number = _.size unless n_number > _.size
16
+ }
17
+ set_result(n_number)
18
+ return result?
19
+ end; self.instance_eval { alias count_longest_row cmdlet_count_longest_row } # === UniversalPipeHandler.count_longest_row
20
+
21
+ end
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'universal_pipe_handler/cmdlets/crop.rb'
6
+ # =========================================================================== #
7
+ module UniversalPipeHandler
8
+
9
+ # ========================================================================= #
10
+ # === UniversalPipeHandler.cmdlet_crop
11
+ #
12
+ # This method can be used to crop an image.
13
+ # ========================================================================= #
14
+ def self.cmdlet_crop(
15
+ crop_command_to_use = result?
16
+ )
17
+ filename = result?
18
+ crop = ImageParadise::Crop.new(
19
+ filename, crop_command_to_use, :dont_run_yet
20
+ )
21
+ crop.run
22
+ set_result(crop.result?)
23
+ return result?
24
+ end; self.instance_eval { alias crop cmdlet_crop } # === UniversalPipeHandler.crop
25
+
26
+ end
@@ -0,0 +1,101 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'universal_pipe_handler/cmdlets/cut.rb'
6
+ # =========================================================================== #
7
+ module UniversalPipeHandler
8
+
9
+ # ========================================================================= #
10
+ # === UniversalPipeHandler.cmdlet_cut (cut tag)
11
+ #
12
+ # This action allows you to cut a video or audio file.
13
+ #
14
+ # The input can be as complex as "20%-50%".
15
+ # ========================================================================= #
16
+ def self.cmdlet_cut(
17
+ start_position = result?,
18
+ duration_in_n_seconds = nil
19
+ )
20
+ # To prepare for the duration. bl $RUBY_TIME/start_length_duration.rb
21
+ start_length_duration = MultimediaParadise::StartLengthDuration.new
22
+ start_position = start_position.first if start_position.is_a? Array # Trying this since Dec 2014.
23
+ # original_input = start_position.dup
24
+ _ = Multimedia::FileDuration.new(result?) # This will contain the filename.
25
+ # ======================================================================= #
26
+ # === Handle percent-input next
27
+ #
28
+ # This can be either -30 or 30. If we count more than one %, we treat the
29
+ # whole instruction as a range.
30
+ # ======================================================================= #
31
+ if start_position.include?('%')
32
+ # ===================================================================== #
33
+ # Enter a %-Range next:
34
+ # ===================================================================== #
35
+ if start_position.count('%') > 1 # This here is valid if we have something like "30%-80%"
36
+ splitted = start_position.split('%')
37
+ end_pos_in_percent = splitted[-1].to_f.abs
38
+ duration_in_n_seconds = _.one_percent * end_pos_in_percent
39
+ else # else we have just one %.
40
+ start_position = start_position.to_i.abs
41
+ end
42
+ end
43
+ length = _.file_duration # Get the absolute length of the file here.
44
+ # ========================================================================= #
45
+ # We set the total length of the file here. This is useful because
46
+ # we can use this information to calculate extra things.
47
+ # ========================================================================= #
48
+ start_length_duration.length = length
49
+ this_file = result?.first
50
+ e 'The total length of the file '+sfile(this_file)+' is '+
51
+ simportant(length.to_s)+' seconds.'
52
+ _ = 'ffmpeg -y -i '+this_file # Build our sys string here. -y so we overwrite our string.
53
+ # ========================================================================= #
54
+ # The variable save_to will keep track of where we will store the newly
55
+ # generated file (in other words, the output file).
56
+ # ========================================================================= #
57
+ save_to = start_dir?+
58
+ File.basename(this_file.gsub(/\.mp3/,''))+'_ouput'
59
+ # ========================================================================= #
60
+ # Hack, hack hackety hack.
61
+ # ========================================================================= #
62
+ if File.extname(this_file) == '.mp4'
63
+ save_to << '.mp4'
64
+ else
65
+ save_to << '.mp3'
66
+ end
67
+ unless duration_in_n_seconds
68
+ duration_in_n_seconds = start_position.to_i
69
+ end
70
+ start_position = 0 # Default.
71
+ # ========================================================================= #
72
+ # If @position has been set, then we will add the position both to the
73
+ # start position, and to the end position.
74
+ # ========================================================================= #
75
+ if @position
76
+ start_position = start_position.to_i + @position
77
+ end
78
+ # ========================================================================= #
79
+ # Use StartLengthDuration now to get the required info.
80
+ # ========================================================================= #
81
+ start_length_duration.start = start_position
82
+ start_length_duration.set_duration = duration_in_n_seconds
83
+ _ << ' -ss '+start_length_duration.start.to_s
84
+ _ << ' -t '+(start_length_duration.duration).to_s
85
+ # ========================================================================= #
86
+ # The problem with -acodec copy is that an AAC file can not be easily
87
+ # copied into a .mp3 file. Hence we must use -acodec libmp3lame
88
+ # instead here.
89
+ # ========================================================================= #
90
+ if save_to.include? 'mp3'
91
+ _ << ' -acodec libmp3lame '
92
+ else
93
+ _ << ' -acodec copy '
94
+ end
95
+ _ << save_to
96
+ esystem " #{_}"
97
+ set_result(save_to)
98
+ result?
99
+ end; self.instance_eval { alias cut cmdlet_cut } # === UniversalPipeHandler.cut
100
+
101
+ end
@@ -0,0 +1,41 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'universal_pipe_handler/cmdlets/days.rb'
6
+ # =========================================================================== #
7
+ module UniversalPipeHandler
8
+
9
+ # ========================================================================= #
10
+ # === UniversalPipeHandler.cmdlet_days?
11
+ #
12
+ # The input should be amount of seconds.
13
+ #
14
+ # However had, this is context-dependent and thus a bit difficult to
15
+ # handle correctly.
16
+ #
17
+ # For instance, take these two different inputs:
18
+ #
19
+ # '5 years | days?'
20
+ # '45 days | n_seconds?'
21
+ #
22
+ # The first variant obviously gives us n seconds to days?, and then
23
+ # days? can output the amount of days.
24
+ #
25
+ # The second variant should however had simply give us the amount of
26
+ # seconds that 45 days have.
27
+ #
28
+ # The convention thus will be that we will always convert into seconds,
29
+ # and when it is fed into n_seconds? then we will not do any further
30
+ # modification.
31
+ # ========================================================================= #
32
+ def self.cmdlet_days?(i = result?)
33
+ i = i.join.strip if i.is_a? Array
34
+ # result = i.to_f / ONE_DAY_HAS_N_SECONDS.to_f
35
+ # i = result.floor
36
+ set_result(i)
37
+ return result?
38
+ end; self.instance_eval { alias action_days? cmdlet_days? } # === UniversalPipeHandler.action_days?
39
+ self.instance_eval { alias action_n_days? cmdlet_days? } # === UniversalPipeHandler.action_days?
40
+
41
+ end
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'universal_pipe_handler/cmdlets/decolourize.rb'
6
+ # =========================================================================== #
7
+ module UniversalPipeHandler
8
+
9
+ # ========================================================================= #
10
+ # === UniversalPipeHandler.cmdlet_decolourize
11
+ #
12
+ # This method will get rid of the colours from a video file.
13
+ # ========================================================================= #
14
+ def self.cmdlet_decolourize(
15
+ this_file = result?
16
+ )
17
+ this_file = this_file.first if this_file.is_a? Array
18
+ output_file = 'decolourized_file_'+File.basename(this_file)
19
+ _ = 'ffmpeg -i '+this_file+' -vf format=gray '+output_file
20
+ esystem _
21
+ set_result(output_file)
22
+ return result?
23
+ end; self.instance_eval { alias decolourize cmdlet_decolourize } # === UniversalPipeHandler.decolourize
24
+
25
+ end
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'universal_pipe_handler/cmdlets/download.rb'
6
+ # =========================================================================== #
7
+ module UniversalPipeHandler
8
+
9
+ begin
10
+ require 'wget'
11
+ rescue LoadError; end
12
+
13
+ # ========================================================================= #
14
+ # === UniversalPipeHandler.cmdlet_download
15
+ #
16
+ # Download a file via this cmdlet.
17
+ # ========================================================================= #
18
+ def self.cmdlet_download(i)
19
+ if Object.const_defined? :Wget # Then use WgetWrapper if it is available.
20
+ Wget.new(i)
21
+ else
22
+ cmd = 'wget '+i
23
+ run_sys_cmd(cmd)
24
+ end
25
+ @file = File.basename(i)
26
+ set_result @file
27
+ result?
28
+ end; self.instance_eval { alias download cmdlet_download } # === UniversalPipeHandler.download
29
+
30
+ end
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'universal_pipe_handler/cmdlets/torrent.rb'
6
+ # =========================================================================== #
7
+ module UniversalPipeHandler
8
+
9
+ # ========================================================================= #
10
+ # === UniversalPipeHandler.cmdlet_torrent
11
+ # ========================================================================= #
12
+ def self.cmdlet_torrent
13
+ cmdlet_search_torrent
14
+ cmdlet_download(result?)
15
+ end; self.instance_eval { alias torrent cmdlet_torrent } # === UniversalPipeHandler.torrent
16
+
17
+ end
@@ -0,0 +1,34 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'universal_pipe_handler/cmdlets/duration.rb'
6
+ # =========================================================================== #
7
+ module UniversalPipeHandler
8
+
9
+ begin
10
+ require 'multimedia_paradise/audio/file_duration/file_duration.rb'
11
+ rescue LoadError; end
12
+
13
+ # ========================================================================= #
14
+ # === UniversalPipeHandler.cmdlet_duration
15
+ # ========================================================================= #
16
+ def self.cmdlet_duration(
17
+ i = result?
18
+ )
19
+ n_seconds = 0
20
+ if i.is_a? Array
21
+ i.each {|entry|
22
+ _ = Multimedia::FileDuration.new(entry)
23
+ n_seconds += _.duration?
24
+ }
25
+ else
26
+ _ = Multimedia::FileDuration.new(i)
27
+ n_seconds += _.duration?
28
+ end
29
+ result = 'Duration of `'+sfile(i)+'`: '+sfancy(n_seconds.to_s)+' seconds.'
30
+ set_result(result)
31
+ return result?
32
+ end; self.instance_eval { alias duration cmdlet_duration } # === UniversalPipeHandler.duration
33
+
34
+ end
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'universal_pipe_handler/cmdlets/extract.rb'
6
+ # =========================================================================== #
7
+ module UniversalPipeHandler
8
+
9
+ # ========================================================================= #
10
+ # === UniversalPipeHandler.cmdlet_extract
11
+ #
12
+ # Here we will extract the audio and the video.
13
+ # ========================================================================= #
14
+ def self.cmdlet_extract(i = nil)
15
+ _ = result?
16
+ if i.is_a? Array
17
+ case i.first
18
+ when 'audio'
19
+ action_extract_audio _, Dir.pwd
20
+ end
21
+ else # Delegate towards the two other methods here.
22
+ action_extract_audio _, Dir.pwd
23
+ action_extract _
24
+ end
25
+ end; self.instance_eval { alias extract cmdlet_extract } # === UniversalPipeHandler.extract
26
+
27
+ end
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'universal_pipe_handler/cmdlets/extract_all.rb'
6
+ # =========================================================================== #
7
+ module UniversalPipeHandler
8
+
9
+ # ========================================================================= #
10
+ # === UniversalPipeHandler.cmdlet_extract_all
11
+ # ========================================================================= #
12
+ def self.cmdlet_extract_all(dir = result?)
13
+ dir = dir.first if dir.is_a? Array
14
+ all_files = get_all_files_from(dir)
15
+ all_files.each { |file|
16
+ _ = extract_aller.new(file, :dont_run_yet) # If it is an archive, extract_all it.
17
+ _.set_extract_all_to_this_location(dir) # We will extract_all into the same directory.
18
+ _.run
19
+ }
20
+ set_result(all_files)
21
+ end; self.instance_eval { alias extract_all cmdlet_extract_all } # === UniversalPipeHandler.extract_all
22
+
23
+ end
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'universal_pipe_handler/cmdlets/extract_audio.rb'
6
+ # =========================================================================== #
7
+ module UniversalPipeHandler
8
+
9
+ # ========================================================================= #
10
+ # === UniversalPipeHandler.cmdlet_extract_audio
11
+ #
12
+ # This method will extract audio from a video container.
13
+ #
14
+ # We will make use of the project ExtractAudio for this, so we
15
+ # absolutely depend on that project.
16
+ #
17
+ # The functionality is implemented as part of the multimedia_paradise
18
+ # gem.
19
+ # ========================================================================= #
20
+ def self.cmdlet_extract_audio(
21
+ i = result?,
22
+ optional_store_where = nil
23
+ )
24
+ e "Extracting audio from #{sfancy(i)} next." if be_verbose?
25
+ _ = MultimediaParadise.extract_audio(i, optional_store_where)
26
+ set_result(_)
27
+ return result?
28
+ end; self.instance_eval { alias extract_audio cmdlet_extract_audio } # === UniversalPipeHandler.extract_audio
29
+
30
+ end
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'universal_pipe_handler/cmdlets/extract_video.rb'
6
+ # =========================================================================== #
7
+ module UniversalPipeHandler
8
+
9
+ # ========================================================================= #
10
+ # === UniversalPipeHandler.cmdlet_extract_video
11
+ #
12
+ # Simply delegate towards MultimediaParadise.
13
+ # ========================================================================= #
14
+ def self.cmdlet_extract_video(i = result?)
15
+ MultimediaConversions.extract_video(i)
16
+ end; self.instance_eval { alias extract_video cmdlet_extract_video } # === UniversalPipeHandler.extract_video
17
+
18
+ end
@@ -0,0 +1,40 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'universal_pipe_handler/cmdlets/find_all.rb'
6
+ # =========================================================================== #
7
+ module UniversalPipeHandler
8
+
9
+ # ========================================================================= #
10
+ # === UniversalPipeHandler.cmdlet_find_all (find tag)
11
+ #
12
+ # This cmdlet can be used in similar ways as "grep".
13
+ # ========================================================================= #
14
+ def self.cmdlet_find_all(
15
+ search_term = commandline_arguments?
16
+ )
17
+ keyphrase_to_search_for = search_term
18
+ if keyphrase_to_search_for.is_a? Array
19
+ keyphrase_to_search_for = keyphrase_to_search_for.first
20
+ end
21
+ e 'Now searching for the term `'+
22
+ sfancy(keyphrase_to_search_for)+'`:'+N+N
23
+ dataset = result?
24
+ dataset = dataset.reject {|line|
25
+ line !~ /#{keyphrase_to_search_for}/ # Here we apply the "grep" action.
26
+ }
27
+ colourize = true
28
+ # ======================================================================= #
29
+ # If we enable colourizing the result, then we will add swarn(search_term)
30
+ # ======================================================================= #
31
+ if colourize
32
+ dataset.map! {|entry|
33
+ entry.gsub!(/(#{keyphrase_to_search_for})/, swarn("\\1"))
34
+ }
35
+ end
36
+ set_result(dataset)
37
+ return result?
38
+ end; self.instance_eval { alias find_all cmdlet_find_all } # === UniversalPipeHandler.find_all
39
+
40
+ end
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'universal_pipe_handler/cmdlets/generate_random_video.rb'
6
+ # =========================================================================== #
7
+ module UniversalPipeHandler
8
+
9
+ # ========================================================================= #
10
+ # === UniversalPipeHandler.cmdlet_generate_random_video
11
+ #
12
+ # We generate a random video here.
13
+ #
14
+ # The second argument is a hash that can keep extra options.
15
+ # ========================================================================= #
16
+ def self.cmdlet_generate_random_video(i = result?, hash_with_options = {})
17
+ output_file = 'output.mpg'
18
+ if hash_with_options.has_key? :duration
19
+ duration = 'duration='+hash_with_options.delete(:duration)
20
+ else
21
+ duration = 'duration=15' # The default.
22
+ end
23
+ _ = 'ffmpeg -f lavfi -i testsrc='+duration+':size=1280x720:rate=30 '+output_file
24
+ esystem _
25
+ set_result(output_file)
26
+ return result?
27
+ end; self.instance_eval { alias generate_random_video cmdlet_generate_random_video } # === UniversalPipeHandler.generate_random_video
28
+
29
+ end
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'universal_pipe_handler/cmdlets/generate_string.rb'
6
+ # =========================================================================== #
7
+ module UniversalPipeHandler
8
+
9
+ # ========================================================================= #
10
+ # === UniversalPipeHandler.cmdlet_generate_string
11
+ #
12
+ # This method will simply generate a random string.
13
+ #
14
+ # action_generate_string 25, false
15
+ #
16
+ # ========================================================================= #
17
+ def self.cmdlet_generate_string(
18
+ max = 50,
19
+ assign_to_result = true
20
+ )
21
+ alphabet = ('a'..'z').to_a << ' '
22
+ _ = (0...max).map { alphabet.sample }.join
23
+ set_result(_) if assign_to_result
24
+ return result?
25
+ end; self.instance_eval { alias generate_string cmdlet_generate_string } # === UniversalPipeHandler.generate_string
26
+
27
+ end
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'universal_pipe_handler/cmdlets/get_all_audio_files.rb'
6
+ # =========================================================================== #
7
+ module UniversalPipeHandler
8
+
9
+ # ========================================================================= #
10
+ # === UniversalPipeHandler.cmdlet_get_all_audio_files
11
+ #
12
+ # We depend on the action "get all files" for this method here.
13
+ #
14
+ # We will obtain all audio files from the current working directory,
15
+ # by first obtaining all files, and then applying a filter.
16
+ # ========================================================================= #
17
+ def self.cmdlet_get_all_audio_files(
18
+ from = Dir.pwd
19
+ )
20
+ from = '/Depot/Audio' if from.nil?
21
+ _ = action_get_all_audio_files(from)
22
+ # ======================================================================= #
23
+ # Next, we apply a filter to get only the audio files:
24
+ # ======================================================================= #
25
+ _.reject! {|entry|
26
+ entry = File.extname(entry).delete('.')
27
+ ! ARRAY_AUDIO_FILES.include?(entry)
28
+ }
29
+ set_result(_) # We use this result.
30
+ return _
31
+ end; self.instance_eval { alias get_all_audio_files cmdlet_get_all_audio_files } # === UniversalPipeHandler.get_all_audio_files
32
+
33
+ end
@@ -0,0 +1,61 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'universal_pipe_handler/cmdlets/get_all_files.rb'
6
+ # =========================================================================== #
7
+ module UniversalPipeHandler
8
+
9
+ require 'universal_pipe_handler/toplevel_methods/misc.rb'
10
+
11
+ # ========================================================================= #
12
+ # === UniversalPipeHandler.cmdlet_get_all_files (files tag)
13
+ #
14
+ # Invoked via list_content(). We use expand_path here to get the
15
+ # real absolute path. It will return all files that matched a
16
+ # certain criteria.
17
+ #
18
+ # The first argument is the target directory. This MUST include a
19
+ # trailing '/' - the method here will NOT append a trailing '/'.
20
+ #
21
+ # The second argument, called `include_the_subdirectories`, instructs this method
22
+ # to traverse into subdirectories.
23
+ # ========================================================================= #
24
+ def self.cmdlet_get_all_files(
25
+ from_this_directory = :try_to_use_the_working_directory_variable,
26
+ include_the_subdirectories = false
27
+ )
28
+ if from_this_directory.is_a? Array
29
+ from_this_directory = from_this_directory.first
30
+ end
31
+ case from_this_directory
32
+ # ======================================================================= #
33
+ # === :default
34
+ # ======================================================================= #
35
+ when :default, :def, nil
36
+ from_this_directory = return_pwd
37
+ # ======================================================================= #
38
+ # === :try_to_use_the_working_directory_variable
39
+ # ======================================================================= #
40
+ when :try_to_use_the_working_directory_variable
41
+ from_this_directory = UniversalPipeHandler.working_directory?
42
+ if from_this_directory.nil?
43
+ from_this_directory = return_pwd
44
+ end
45
+ end
46
+
47
+ @target_directory = from_this_directory # this may have to be changed eventually.
48
+ if @target_directory.start_with? ':' # assume it is a special keyword.
49
+ @target_directory = sanitize_url(@target_directory)
50
+ end
51
+ target = @target_directory+'**'
52
+ target = @target_directory+'**/**' if include_the_subdirectories
53
+ _ = Dir[target].map {|entry| File.expand_path(entry) }
54
+ set_result(_)
55
+ return result? # We will return all found files.
56
+ end; self.instance_eval { alias get_all_files cmdlet_get_all_files } # === UniversalPipeHandler.get_all_files
57
+ self.instance_eval { alias get_all_files_from cmdlet_get_all_files } # === UniversalPipeHandler.get_all_files_from
58
+ self.instance_eval { alias list_content cmdlet_get_all_files } # === UniversalPipeHandler.list_content
59
+ self.instance_eval { alias cmdlet_ls cmdlet_get_all_files } # === UniversalPipeHandler.cmdlet_ls
60
+
61
+ end
@@ -0,0 +1,47 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'universal_pipe_handler/cmdlets/get_all_images.rb'
6
+ # =========================================================================== #
7
+ module UniversalPipeHandler
8
+
9
+ # ========================================================================= #
10
+ # === UniversalPipeHandler.cmdlet_get_all_images
11
+ #
12
+ # The first argument specifies from where we get the image files.
13
+ #
14
+ # In order for this to work, we will tap into the method called
15
+ # action_get_all_files().
16
+ # ========================================================================= #
17
+ def self.cmdlet_get_all_images(
18
+ dir = start_directory?,
19
+ include_subdirs = false
20
+ )
21
+ if dir.is_a? Hash
22
+ if dir.has_key? :from
23
+ dir = dir.delete :from
24
+ end
25
+ end
26
+ if dir == :include_subdirs
27
+ dir = start_directory?
28
+ include_subdirs = true
29
+ end
30
+ dir = dir.first if dir.is_a? Array
31
+ dir << '/' unless dir.end_with? '/'
32
+ dir = sanitize_url(dir)
33
+ dir = dir.first if dir.is_a? Array # We must check again here due to sanitize_url().
34
+ case dir.delete('/')
35
+ when 'njoy_dir','njoy'
36
+ dir = '/home/x/data/images/NJOY/'
37
+ end
38
+ @target_directory = dir # this may have to be changed eventually.
39
+ _ = action_get_all_files(target_directory?, include_subdirs)
40
+ _.select! {|file|
41
+ ARRAY_IMAGE_FILE_TYPES.include?(File.extname(file).delete('.'))
42
+ }
43
+ set_result(_)
44
+ return result?
45
+ end; self.instance_eval { alias get_all_images cmdlet_get_all_images } # === UniversalPipeHandler.get_all_images
46
+
47
+ end