Using curl to upload video to DailyMotion, all requests returning successful but video still not uploaded - dailymotion-api

I have implemented the following Bash script with which I'm trying to upload videos to my Dailymotion account. All the curl requests return JSON responses as listed on the official API documentation pages. However, my video fails to show up in my account. What am I doing wrong here?
#!/bin/bash
curl -s --output out.txt --data 'grant_type=password&client_id=<My-ID>&client_secret=<My-Secret>&username=<My-Username>&password=<My-password>&scope=read+write' https://api.dailymotion.com/oauth/token
var1=$(grep "access_token" out.txt | cut -d: --complement -f1)
acc_token=$(echo $var1 | cut -d, -f1 | cut -d\" --complement -f1 | cut -d\" -f1)
curl -s --output out.txt -i https://api.dailymotion.com/file/upload?access_token="$acc_token"
upload_url=$(grep "upload_url" out.txt | cut -d: --complement -f1 | cut -d\" --complement -f1 | cut -d\" -f1 | sed 's/\\//g')
curl -s --output out.txt -F 'file=#/home/zahaib/video.mp4' "$upload_url"
video_url=$(grep "url" out.txt | cut -d: --complement -f1-10 | cut -d\" --complement -f1 | cut -d# -f1 )
curl -s --output out.txt -d $video_url https://api.dailymotion.com/me/videos?access_token="$acc_token"
video_id=$(grep "id" out.txt | cut -d: --complement -f1 | cut -d\" --complement -f1 | cut -d\" -f1 )
curl -s --output out.txt -d 'title=Vid&channel=sport&tags=was' https://api.dailymotion.com/video/"$video_id"/access_token="$acc_token"
curl -s --output out.txt -d 'published=true' https://api.dailymotion.com/video/"$video_id"/access_token="$acc_token"

There's a typo in your script on the last two lines:
https://api.dailymotion.com/video/"$video_id"/access_token="$acc_token"
Instead of:
https://api.dailymotion.com/video/"$video_id"/?access_token="$acc_token"
It's right there, in your out.txt:
{
"error":{
"code":501,
"message":"Invalid method name: POST \/video\/<xid>\/access_token=<redated>.",
"type":"invalid_method"
}
}

Related

How to pass url at runtime using curl command which in encoded with ` sign?

I am trying to pass url in curl command using bash script
URL=www.google.com
response=``curl --location --request GET **${URL}** | jq . | grep buildVersion | awk '{print $2}' | sed 's/"//' | sed 's/"//' | sed 's/,//'``
echo $URL
The command in response variable is encoded with `
Is there a way I can send URL variable at runtime ?
This works fine for me
response=``curl --location --request GET www.google.com/data | jq . | grep buildVersion | awk '{print $2}' | sed 's/"//' | sed 's/"//' | sed 's/,//'`
Note : URL is sample site
I want to pass url at runtime I tried sending the --url parameter

Search for part of string with grep in all files in folder and subfolders

I have .html files in directories and subdirectories. I need to extract all strings that starts with "domain.com". Part of string can look like this:
["https://example.com/folder1",
href="https://example.com/anotherfolder2" target="
etc.
What I want to extract is:
folder1
anotherfolder2
etc.
from all files in all folders to one list, each word - new line.
Found some examples on StackOverflow with many likes, but not worked. I tried like this (from some examples):
grep -Po '(?<=example.com=)[^,]*'
Thank you for help!
grep "example.com" your-directory -r | grep -o '".*"' | cut -d \" -f2| sed -e 's/https:\/\/example.com\///g'
grep "example.com" your-directory -r | grep -o '".*"' your-directory -r | cut -d \" -f2 extracts the content of quoted string
sed -e 's/https:\/\/example.com\///g' get the suffix of https://example.com/
echo "https://example.com/folder1" | tr -s '/' | tr '/' '\n' > file
sed -i '1d' file
sed -n '1p' file # This will give you example.com
sed -n '2p' file # This will give you folder1
sed -i 1s'#example\.com#newsite.com#' file
echo "http://" > nf
sed -n '2,$p' file >> nf
cat nf | tr '\n' '/' > newfile
cat newfile # This should be http://newsite.com/folder1
rm -v ./nf

dynamic exclusion of files through grep matching

I have a file source-push.sh which returns the list of files which I want to exclude from the results of find command.
It looks like this:
#!/usr/bin/env bash
find . -not \( -path './node_modules' -prune \) -name '*.js' | grep -vE $(echo $(./source-push.sh | xargs -I{} echo -n "{}|") | rev | cut -b2- | rev) | xargs -L1 standard --fix
find . -not \( -path './node_modules' -prune \) -name '*.css' | grep -vE $(echo $(./source-push.sh | xargs -I{} echo -n "{}|") | rev | cut -b2- | rev) | xargs -L1 stylelint --config stylelint.json
There are supposed to be a way to do the job better than that. Any suggestions?
Instead of:
... | grep -vE $(echo $(./source-push.sh | xargs -I{} echo -n "{}|") | rev | cut -b2- | rev ) | ...
you can use the POSIX options -F and -f:
... | grep -v -F -f <( ./source-push.sh ) | ...
-F tells grep that the patterns are fixed strings
(avoiding the problem that your original code would break if the patterns contain characters that are special to grep -E)
-f file tells grep to use a list of patterns from file
<( ... ) is a bash way to present output of a program as a file (named pipe)

Cut the Apostrophe (') with cut or awk

I'm trying to cut a line of asterisk output.
The complete line:
[2017-11-01 08:23:58] NOTICE[13443]: res_pjsip/pjsip_distributor.c:659 log_failed_request: Request 'INVITE' from '"66666" <sip:66666#192.168.1.248>' failed for '163.172.107.10:5070' (callid: f64a37f3cc5a88f4cd957ecb7b65a14f) - No matching endpoint found
I need to see only this 163.172.107.10 in my output
So my command is this:
cat test | grep endpoint | awk '{print $13}' | awk -F':' '{print $1}'
My output:
'163.172.107.10
But I can't get rid of the ' (Apostrophe)
I tried: cut -d '''
But that didn't work
Any suggestions?
If this line follows a similar patters as pointed above, then
try this
gawk -F"'" '{print $6}' | cut -d":" -f1
as in
echo "[2017-11-01 08:23:58] NOTICE[13443]: res_pjsip/pjsip_distributor.c:659 log_failed_request: Request 'INVITE' from '"66666" <sip:66666#192.168.1.248>' failed for '163.172.107.10:5070' (callid: f64a37f3cc5a88f4cd957ecb7b65a14f) - No matching endpoint found" | gawk -F"'" '{print $6}' | cut -d":" -f1
Please let me know if the below helps.
cat test | grep endpoint | awk '{print $13}' | awk -F':' '{print $1}' | tr -d "'"
If your Input_file is same as shown sample then following may help you in same.
awk '{sub(/.*failed for \047/,"");sub(/:.*/,"");print}' Input_file

xargs: String concatenation

zgrep -i XXX XXX | grep -o "RID=[0-9|A-Z]*" |
uniq | cut -d "=" -f2 |
xargs -0 -I string echo "RequestID="string
My output is
RequestID=121212112
8127127128
8129129812
But my requirement is to have the request ID prefixed before all the output.
Any help is appreciated
I had a similar task and this worked for me. It might be what you are looking for:
zgrep -i XXX XXX | grep -o "RID=[0-9|A-Z]*" |
uniq | cut -d "=" -f2 |
xargs -I {} echo "RequestID="{}
Try -n option of xargs.
-n max-args
Use at most max-args arguments per command line. Fewer than max-args arguments will be used if the size (see the -s option)
is exceeded,
unless the -x option is given, in which case xargs will exit.
Example:
$ echo -e '1\n2' | xargs echo 'str ='
str = 1 2
$ echo -e '1\n2' | xargs -n 1 echo 'str ='
str = 1
str = 2

Resources