Skip to content

Commit b408366

Browse files
committed
20210402- Version 1.3.0
1 parent 8a3c9e0 commit b408366

File tree

5 files changed

+223
-33
lines changed

5 files changed

+223
-33
lines changed

.github/workflows/codacy-analysis.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# This workflow checks out code, performs a Codacy security scan
2+
# and integrates the results with the
3+
# GitHub Advanced Security code scanning feature. For more information on
4+
# the Codacy security scan action usage and parameters, see
5+
# https://github.com/codacy/codacy-analysis-cli-action.
6+
# For more information on Codacy Analysis CLI in general, see
7+
# https://github.com/codacy/codacy-analysis-cli.
8+
9+
name: Codacy Security Scan
10+
11+
on:
12+
push:
13+
branches: [ main ]
14+
pull_request:
15+
# The branches below must be a subset of the branches above
16+
branches: [ main ]
17+
schedule:
18+
- cron: '41 16 * * 3'
19+
20+
jobs:
21+
codacy-security-scan:
22+
name: Codacy Security Scan
23+
runs-on: ubuntu-latest
24+
steps:
25+
# Checkout the repository to the GitHub Actions runner
26+
- name: Checkout code
27+
uses: actions/checkout@v2
28+
29+
# Execute Codacy Analysis CLI and generate a SARIF output with the security issues identified during the analysis
30+
- name: Run Codacy Analysis CLI
31+
uses: codacy/[email protected]
32+
with:
33+
# Check https://github.com/codacy/codacy-analysis-cli#project-token to get your project token from your Codacy repository
34+
# You can also omit the token and run the tools that support default configurations
35+
project-token: ${{ secrets.CODACY_PROJECT_TOKEN }}
36+
verbose: true
37+
output: results.sarif
38+
format: sarif
39+
# Adjust severity of non-security issues
40+
gh-code-scanning-compat: true
41+
# Force 0 exit code to allow SARIF file generation
42+
# This will handover control about PR rejection to the GitHub side
43+
max-allowed-issues: 2147483647
44+
45+
# Upload the SARIF file generated in the previous step
46+
- name: Upload SARIF results file
47+
uses: github/codeql-action/upload-sarif@v1
48+
with:
49+
sarif_file: results.sarif
50+
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# This workflow integrates Scan with GitHub's code scanning feature
2+
# Scan is a free open-source security tool for modern DevOps teams from ShiftLeft
3+
# Visit https://slscan.io/en/latest/integrations/code-scan for help
4+
name: SL Scan
5+
6+
on:
7+
push:
8+
branches: [ main ]
9+
pull_request:
10+
# The branches below must be a subset of the branches above
11+
branches: [ main ]
12+
schedule:
13+
- cron: '45 22 * * 4'
14+
15+
jobs:
16+
Scan-Build:
17+
# Scan runs on ubuntu, mac and windows
18+
runs-on: ubuntu-latest
19+
steps:
20+
- uses: actions/checkout@v1
21+
# Instructions
22+
# 1. Setup JDK, Node.js, Python etc depending on your project type
23+
# 2. Compile or build the project before invoking scan
24+
# Example: mvn compile, or npm install or pip install goes here
25+
# 3. Invoke Scan with the github token. Leave the workspace empty to use relative url
26+
27+
- name: Perform Scan
28+
uses: ShiftLeftSecurity/scan-action@master
29+
env:
30+
WORKSPACE: ""
31+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
32+
SCAN_AUTO_BUILD: true
33+
with:
34+
output: reports
35+
# Scan auto-detects the languages in your project. To override uncomment the below variable and set the type
36+
# type: credscan,java
37+
# type: python
38+
39+
- name: Upload report
40+
uses: github/codeql-action/upload-sarif@v1
41+
with:
42+
sarif_file: reports

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,12 @@ ydownl.sh is a simple youtube-dl bash script which can be used to extract audio
77
![alt text](https://raw.githubusercontent.com/yafp/ydownl.sh/main/docs/current_output.png)
88

99

10+
## features
11+
* checks if the URL is reachable
12+
* tries to extract the audio from the URL
1013

11-
## requirements
14+
15+
## dependencies
1216
The following packages are required:
1317

1418
* youtube-dl

docs/CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
11
# changelog
2+
## Version 1.3.0 (20210402)
3+
* Youtube-DL: Adding --add-metadata
4+
* Youtube-DL: Adding --write-info-json
5+
* Youtube-DL: Adding --write-annotations
6+
* Youtube-DL: Adding --write-thumbnail
7+
* Youtube-DL: Adding --embed-thumbnail
8+
* Youtube-DL: Adding --user-agent
9+
* Youtube-DL: Adding --output-na-placeholder
10+
* Improved output by missing dependency
11+
12+
213
## Version 1.2.0 (20210330)
314
* Added check for updates - see #1
415
* Added dependecy check for ffmpeg

ydownl.sh

Lines changed: 115 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,17 @@
66
# ./ydownl.sh URL
77
#
88

9+
# ------------------------------------------------------------------------------
10+
# IDEAS
11+
# ------------------------------------------------------------------------------
12+
# - setting for target dir:
13+
# example: CONFIG_TARGET_DIR="~/Downloads"
14+
# - youtube-dl parameter:
15+
# - youtube-dl: ffmpeg or avconv?
16+
# --prefer-avconv (default)
17+
# --prefer-ffmpeg
18+
#
19+
920
# ------------------------------------------------------------------------------
1021
# DEBUG
1122
# ------------------------------------------------------------------------------
@@ -17,9 +28,10 @@
1728
# DEFINE CONSTANTS - DON'T TOUCH
1829
# ------------------------------------------------------------------------------
1930
SCRIPT_NAME="ydownl.sh"
20-
SCRIPT_VERSION="1.2.0"
31+
SCRIPT_VERSION="1.3.0"
2132
SCRIPT_LATEST="https://github.com/yafp/ydownl.sh/releases/latest"
2233
SCRIPT_DEMO_URL="https://www.youtube.com/watch?v=Y52M28WQu2s"
34+
SCRIPT_USERAGENT="ydownl.sh"
2335

2436

2537

@@ -56,6 +68,14 @@ CONFIG_ZENITY_HEIGHT=150 # default 150
5668
# ------------------------------------------------------------------------------
5769
# FUNCTIONS
5870
# ------------------------------------------------------------------------------
71+
72+
#######################################
73+
# Defines some text color & formating options
74+
# Arguments:
75+
# none
76+
# Outputs:
77+
# none
78+
#######################################
5979
function initColors() {
6080
# format
6181
bold=$(tput bold)
@@ -77,46 +97,76 @@ function initColors() {
7797
white=$(tput setaf 7)
7898
}
7999

100+
#######################################
101+
# Clears the terminal / screen
102+
# Arguments:
103+
# none
104+
# Outputs:
105+
# none
106+
#######################################
80107
function reset() {
81108
tput reset
82109
}
83110

111+
#######################################
112+
# Shows a simple header
113+
# Arguments:
114+
# none
115+
# Outputs:
116+
# none
117+
#######################################
84118
function showHeader() {
85119
printf " ${bold}${lime_yellow}%s${normal} - ${bold}%s ${normal}\n" "$SCRIPT_NAME" "$SCRIPT_VERSION"
86120
printf " ${bold}----------------------------------------------------------${normal}\n"
87121
}
88122

89-
function showNotification() {
90-
if ! hash notify-send 2>/dev/null
91-
then
92-
printf "Notifications using notify-send is not supported - skipping ...\n"
93-
else
94-
#notify-send -u low -t 0 "$SCRIPT_NAME" "$1"
95-
zenity --info --text="$1" --title="$SCRIPT_NAME" --width="$CONFIG_ZENITY_WIDTH" --height="$CONFIG_ZENITY_HEIGHT" --timeout="$CONFIG_ZENITY_TIMEOUT"
96-
fi
123+
#######################################
124+
# Displays a text notification using zenity
125+
# Arguments:
126+
# notification text
127+
# Outputs:
128+
# none
129+
#######################################
130+
function showGuiNotification() {
131+
zenity \
132+
--info \
133+
--text="$1" \
134+
--title="$SCRIPT_NAME" \
135+
--width="$CONFIG_ZENITY_WIDTH" \
136+
--height="$CONFIG_ZENITY_HEIGHT" \
137+
--timeout="$CONFIG_ZENITY_TIMEOUT"
97138
}
98139

140+
#######################################
141+
# Checks if a file/executable exists.
142+
# Arguments:
143+
# Name of executable
144+
# Outputs:
145+
# OK if it exists
146+
# Error if it doesnt exists
147+
#######################################
99148
function checkIfExists() {
100149
if ! hash "$1" 2>/dev/null
101150
then
102-
# does not exist
103-
printf "${red}[ FAIL ]${normal} $1 not found\n"
151+
printf "${red}[ FAIL ]${normal} $1 not found on this system. Please install this dependency.\n" # does not exist
104152
exit 1
105153
else
106-
# exists
107-
printf "${green}[ OK ]${normal} $1 detected\n"
154+
printf "${green}[ OK ]${normal} $1 detected\n" # exists
108155
fi
109156
}
110157

158+
#######################################
159+
# Checks if a newer version of the script is available
160+
# Arguments:
161+
# none
162+
# Outputs:
163+
# OK if no update available
164+
# INFO if update is available
165+
#######################################
111166
function checkVersion() {
112-
SCRIPT_LATEST_VERSION=`curl --silent "https://api.github.com/repos/yafp/ydownl.sh/releases/latest" | # Get latest release from GitHub api
167+
SCRIPT_LATEST_VERSION=$(curl --silent "https://api.github.com/repos/yafp/ydownl.sh/releases/latest" | # Get latest release from GitHub api
113168
grep '"tag_name":' | # Get tag line
114-
sed -E 's/.*"([^"]+)".*/\1/' ` # Pluck JSON value
115-
116-
117-
#printf "Your version: $SCRIPT_VERSION\n"
118-
#printf "Latest version: $SCRIPT_LATEST_VERSION\n"
119-
169+
sed -E 's/.*"([^"]+)".*/\1/' ) # Pluck JSON value
120170

121171
if [ "$SCRIPT_LATEST_VERSION" == "$SCRIPT_VERSION" ]
122172
then
@@ -126,26 +176,59 @@ function checkVersion() {
126176
fi
127177
}
128178

179+
#######################################
180+
# Triggers the download using youtube-dl
181+
# Arguments:
182+
# URL
183+
# Outputs:
184+
# none
185+
#######################################
186+
function startDownload () {
187+
# start downloading (alt: youtube-dlc)
188+
youtube-dl \
189+
--format bestaudio \
190+
--extract-audio \
191+
--restrict-filenames \
192+
--write-description \
193+
--newline \
194+
--console-title \
195+
--audio-format "$CONFIG_YTDL_AUDIOFORMAT" \
196+
--audio-quality $CONFIG_YTDL_AUDIOQUALITY \
197+
--output "%(playlist_index)s%(playlist)s%(title)s.%(ext)s" \
198+
--output-na-placeholder "" \
199+
--write-info-json \
200+
--write-annotations \
201+
--write-thumbnail \
202+
--embed-thumbnail \
203+
--add-metadata \
204+
--user-agent "$SCRIPT_USERAGENT" \
205+
"$1"
206+
}
207+
129208

130209
# ------------------------------------------------------------------------------
131210
# SCRIPT
132211
# ------------------------------------------------------------------------------
133212
reset # clear the screen
134213
initColors # initialize the color and font formating variables
135214
showHeader # show the script header
136-
checkIfExists "youtube-dl"
137-
checkIfExists "ffmpeg"
138-
checkIfExists "zenity"
139-
checkIfExists "curl"
140-
checkIfExists "sed"
141-
checkVersion
142-
143-
# Check if a parameter was supplied - if not stop execution
215+
216+
# check all dependencies / requirements
217+
checkIfExists "youtube-dl" # main-component
218+
checkIfExists "ffmpeg" # youtube-dl dependency
219+
checkIfExists "zenity" # for dialogs
220+
checkIfExists "curl" # for update-check
221+
checkIfExists "sed" # for update-check
222+
223+
# check for available updates of this script
224+
checkVersion
225+
226+
# Check if a parameter/url was supplied
144227
if [ -z "$1" ]
145228
then
146229
printf "${yellow}[ WARN ]${normal} no URL detected. Starting input dialog\n"
147230

148-
# start input dialog to handle the missing url
231+
# start zenity input dialog to ask for the missing url
149232
URL=$(zenity --entry --width="$CONFIG_ZENITY_WIDTH" --height="$CONFIG_ZENITY_HEIGHT" --title="$SCRIPT_NAME" --text="Please insert an URL:")
150233
if [ -z "$URL" ]
151234
then
@@ -162,10 +245,10 @@ if curl --output /dev/null --silent --head --fail "$URL"; then
162245
printf "${green}[ OK ]${normal} URL is valid\n"
163246
printf "\nStart processing the following url:\n\t${bold}%s${normal}\n\n" "$URL"
164247

165-
# start downloading (alt: youtube-dlc)
166-
youtube-dl -f bestaudio --extract-audio --restrict-filenames --write-description --newline --console-title --audio-format "$CONFIG_YTDL_AUDIOFORMAT" --audio-quality $CONFIG_YTDL_AUDIOQUALITY -o "%(playlist_index)s-%(playlist)s---%(title)s.%(ext)s" $URL
248+
startDownload "$URL"
249+
167250
printf "\n${green}[ OK ]${normal} Finished processing the URL: $URL\n\n"
168-
showNotification "Finished downloading\n\t<a href='$URL'>$URL</a>"
251+
showGuiNotification "Finished downloading\n\t<a href='$URL'>$URL</a>"
169252
else
170253
printf "${red}[ FAIL ]${normal} URL is not reachable. Aborting..\n\n"
171254
exit 1

0 commit comments

Comments
 (0)