How I can retrieve and play audio file in cakephp - apache2

I am uploading audio files using cakephp app. I can move file successfully to folder and can update its path in database too. But I can not retrive that file successfully. server reply with 206 Partial Content AND some times with 304 Not Modified status. can anyone help me to figure out why server respondig with such status?

You are using chromium. Mp3 is not supported in both chromium and firefox for ubuntu. You can convert mp3 to ogg to play them in chromium and firefox. Or you can install chrome if you don't want to convert mp3 to ogg. If you want to convert them, you can do it with this shell script
#!/bin/bash
echo "The script convert mp3->ogg or ogg->mp3.";
echo "The script takes one parameter: ";
echo "[mp3ogg] - converting mp3->ogg";
echo "[oggmp3] - converting ogg->mp3";
if [ "$1" = "" ]; then
echo "";
echo "Argument does not exist!!!";
exit 102;
fi
if [ "$1" = "mp3ogg" ]; then
for file in *.mp3; do
avconv -i "$file" "`echo '../ogg/'${file%.mp3}.ogg`";
done
exit 0;
fi
if [ "$1" = "oggmp3" ]; then
for file in *.ogg; do
avconv -i "$file" -acodec libmp3lame "`echo ${file%.ogg}.mp3`";
done
exit 0;
fi
exit 104;
But you only problem is that chromium and firefox will not support mp3, they will support only ogg in ubuntu.

Related

How can I cycle through an array in bash while also passing an argument to the script?

I have the following bash script I want to use as my "standard browser" with xdg-open.
It should prompt dmenu for me to choose the browser to open the url in.
Now xdg-open passes the url as an argument to the program (I suppose) and as I'm cycling through an array of browsers using the # symbol, it confuses this one with the argument (url) and errors on the dmenu command.
Is there a workaround to this problem or am I doing something completely wrong? --This problem was solved
#!/usr/bin/env bash
set -euo pipefail
_path="$(cd "$(dirname "${BASH_SOURCE[0]}")" && cd "$(dirname "$(readlink "${BASH_SOURCE[0]}" || echo ".")")" && pwd)"
if [[ -f "${_path}/_dm-helper.sh" ]]; then
# shellcheck disable=SC1090,SC1091
source "${_path}/_dm-helper.sh"
else
# shellcheck disable=SC1090
echo "No helper-script found"
fi
# script will not hit this if there is no config-file to load
# shellcheck disable=SC1090
source "$(get_config)"
main() {
if [ -t 0 ]
then
_url=$1
else
read _url
fi
_browser=$(printf '%s\n' "${!browsers[#]}" | sort | ${DMENU} 'Select browser: ') # "$#") ## Thx to #jhnc
_command=${browsers[${_browser}]}
if [[ -n ${_url} ]];then
$_command $_url
fi
}
[[ "${BASH_SOURCE[0]}" == "${0}" ]] && main "$#"
(get config) loads the dmenu command:
DMENU=dmenu -i -l 20 -p
as well as the array of browsers:
declare -A browsers
browsers[brave]="brave-browser"
browsers[firefox]="firefox"
browsers[opera]="opera"
browsers[badwolf]="badwolf"
from my config file.
Originally if i ran xdg-open "https://" or if I clicked on a url in some other program, brave was opened with on that site.
Now after xdg-settings set default-web-browser dmenu-script.desktop with the following .desktop file:
[Desktop Entry]
Version=1.0
Name=Dmenu Browser Script
GenericName=Web Browser
# Gnome and KDE 3 uses Comment.
Comment=Access the Internet
Exec=$HOME/.local/bin/dmenu-browser %U
StartupNotify=true
Terminal=false
Icon=brave-browser
Type=Application
Categories=Network;WebBrowser;
MimeType=application/pdf;application/rdf+xml;application/rss+xml;application/xhtml+xml;application/xhtml_xml;application/xml;image/gif;image/jpeg;image/png;image/webp;text/html;text/xml;x-scheme-handler/http;x-scheme-handler/https;x-scheme-handler/ipfs;x-scheme-handler/ipns;
Actions=new-window;new-private-window;
[Desktop Action new-window]
Name=New Window
Exec=$HOME/.local/bin/dmenu-browser
[Desktop Action new-private-window]
Name=New Incognito Window
Exec=$HOME/.local/bin/dmenu-browser --incognito
It only works if I execute xdg-open from my command line. (I modified the .desktop file of brave-browser, because I had no clue how to write one.)

No URLs matched- while copying file to google cloud storage

I am copying two files into Google Cloud Storage (GCS). When I run the script from informatica, I get error but when I run the same script from Unix it works fine.
Below is a link from GitHub where a similar issue is discussed. I don't understand what's the issue.
------------------------PART OF SCRIPT------------------------
echo "$LFS_File_Path/$File_Name";
gsutil cp "$LFS_File_Path/$File_Name" $GCS_Path;
if [[ $? -eq 0 ]]; then
echo "copy to GCS success for LFS Data File";
else
echo "copy to GCS Failed for LFS" >> $Log_File_Path/$Workflow_Name.txt ;
exit 1
fi
echo "$LFS_File_Path/$Del_File_Name";
gsutil cp "$LFS_File_Path/$Del_File_Name" $GCS_Path;
if [[ $? -eq 0 ]]; then
echo "copy to GCS success for LFS Delete Data File";
else
echo "copy to GCS Failed for LFS" >> $Log_File_Path/$Workflow_Name.txt ;
exit 1
fi
------------------------PART OF SCRIPT------------------------
error:-
CommandException: No URLs matched: /opt/u01/app/informatica/server/infa_shared/TgtFiles/BQ_RT/DW_ORDER_HEADER_DEL.csv
Similar topic:-
https://github.com/GoogleCloudPlatform/gsutil/issues/501
It might be related to the permissions in that file or maybe the command is being run as a user but only root has access to read inside that folder.
resolved it after creating another directory
its because of the hiddenfiles in that directory,the hidden file used the gstuil commands and found some escape characters init
try to create one more directory on the same filesystem and move the files from the directory
its mainly because of the escape characters,try to remove/move the hidden files
it will avoid the the above error
errors:
1)"No URLS matched"
2)CommandException: No URLs matched

SOLR POST files with no extension

I am using SOLR 5 and I want to scan documents that have no extensions. Unfortunately changing the file to have extensions is not an option in my case.
the command I am using is simply:
$bin/post -c mycore ../foldertobescaned -type application/pdf
the command works fine for documents that do have extension but I am getting:
Entering auto mode. File endings considered are xml,json,csv,pdf,doc,docx,ppt,pptx,xls,xlsx,odt,odp,ods,ott,otp,ots,rtf,htm,html,txt,log
If renaming the files is not an option, you can use the following script as a workaround until Solr improves its post method. It is a simple bash for loop that submits each file individually and works regardless of the file extension. Note that this script will be slower than using post on the whole folder, because each individual file transfer needs to be initialized.
Save the script below as postFolderToSolr.sh inside your Solr folder (so that Solrs bin/ folder is a subdirectory), make it executable with chmod +x postFolderToSolr.sh and then use it as follows: ./postFolderToSolr.sh mycore /home/user1/foldertobescaned/ application/pdf
Using no arguments or the wrong number of arguments prints a short usage message as help.
#!/bin/bash
set -o nounset
if [ "$#" -ne 3 ]
then
echo "Post contents of a folder to Solr."
echo
echo "Usage: postFolderToSolr.sh <colletionName> </path/to/folder> <MIME>"
echo
exit 1
fi
collection=$1
inputPath=${2%/} # remove suffix / if it exists
mime=$3
for element in $inputPath"/"*; do
bin/post -c $collection -type $mime $element
done

Batch script to convert all avi to mp4 and delete after conversion using HandBrake command line

So easy and cool batch question. Sorry for this ultimate newbie question !
I've a folder which contains hundreds of videos like that:
Video001 - Introduction.avi
Video002 - History of Stack Overflow.avi
Video003 - Before Asking.avi
...
Video999 - Conclusion.avi
I need re-encode all of them with x264 codec. Ffmpeg is very slow so I tried to use HandBrake. There is a command line edition of HB and great default presents. I could write this command for converting only one file with "Normal" present:
HandBrakeCLI.exe -i "Video001 - Introduction.avi" -o "Video001 - Introduction.mp4" -Z Normal
My question: How can I convert all of them in folder and delete after conversion process? Thank you!
Note: If you think ffmpeg is better solution I can give my fav present. Handbrake says about Normal present:
Normal: -e x264 -q 20.0 -a 1 -E faac -B 160 -6 dpl2 -R Auto -D 0.0 --audio-copy-mask aac,ac3,dtshd,dts,mp3 --audio-fallback ffac3 -f mp4 --loose-anamorphic --modulus 2 -m --x264-preset veryfast --h264-profile main --h264-level 4.0
for %%f in (*.avi) do (
handbrakecli.exe -i "%%~nxf" -o "%%~nf.mp4" -Z Normal
del "%%~f"
)
For each avi file, call handbrake with the name and extension of input file and generate an output file with the name of the original file and .mp4 extension

Export VCF image to JPEG

I have created a .vcf contact with an iPhone and sent the file to myself in email. In that .vcf, I took a photo which is directly saved in the vCard, not in the phone's memory.
In the source of the .vcf, there is a code part starting like this:
PHOTO;ENCODING=b;TYPE=JPEG:/9j/4AAQSkZJRgABAQAAAQABAAD/4QBYRXhpZgAATU0AKgAA
And it continues on... Now, I would like to get this photo and save it as a .JPEG. Any ideas how to do that?
Thanks.
In macOS, it easy to to from the line command with "vi" and "base64.
For example,
Export the "Apple Inc." contact that comes with every user account.
Use vi to manually remove the other lines.
Remove the heading and the meta-data for that line
PHOTO;ENCODING=b;TYPE=JPEG:
base64 decode the remaining file
# base64 -D -i Apple\ Inc..vcf -o Apple_Logo.jpeg
The encoding is Base64. You can find a tool for decoding online.
I can recommend Freeformatter.com's decoder, which lets you save as a binary file. You will then need to rename that file to photo.jpg.
You should use a vCard parser (like vpim) that provides the ability to pull photo data from the vCard.
Another vCard parser is ez-vcard, which is written in Java (disclaimer: I am the author).
File file = new File("vcard.vcf");
VCard vcard = Ezvcard.parse(file).first();
for (PhotoType photo : vcard.getPhotos()){
byte data[] = photo.getData();
//save byte array to file
}
Because this isn't https://apple.stackexchange.com/ I'll suggest a quick bash script that I've used to extracted images from .vcf files on the command line:
#!/bin/bash
#vcf_photo_extractor ver 20180207094631 Copyright 2018 alexx, MIT Licence
if [ ! -f "$1" ]; then
echo "Usage: $(basename $0) [path/]any/contact.vcf"
exit 1
fi
DATA=$(cat "$1" |tr -d "\r\n"|sed -e 's/.*TYPE=//' -e 's/END:VCARD.*//')
NAME=$(grep -a '^N;' $1|sed -e 's/.*://')
#if [ $(wc -c <<< $DATA) -lt 5 ];then #bashism
if [ $(echo $DATA|wc -c) -lt 5 ];then
echo "No images found in $1"
exit 2
fi
EXT=${DATA%%:*}
if [ "$EXT" == 'BEGIN' ]; then echo "FAILED to extract $EXT"; exit 3; fi
IMG=${DATA#*:}
FILE=${1%.*}
Fn=${FILE##*/}
if [ -f "${FILE}.${EXT}" ]; then
echo "Overwrite ${FILE}.${EXT} ? "
read -r YN
if [ "$YN" != 'y' ]; then exit; fi
fi
echo $IMG | base64 -id > ${FILE}.${EXT} || \
echo "Failed to output $NAME to ${FILE}.${EXT}"
This script tries to extract the base64 data, decode it using base64 and create an image file. I found on linux that base64 -id worked but base64 -d threw errors.
If you are a fan of single-line code or code-golf then this might work:
cat 1.vcf|tr -d "\n"|sed -e 's/.*TYPE=[^:]*://' -e 's/END:V.*//'|base64 -id >1.jpg
If you want something cleaner then Matt Brock's
vCard_photo_extractor.sh might be what you are looking for.
Used http://www.sobolsoft.com/convertvcfjpg/ with vCards from OSX, with success.

Resources