how to set up default download location in youtube-dl [closed] - youtube

Closed. This question is not about programming or software development. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 3 months ago.
The community reviewed whether to reopen this question 3 months ago and left it closed:
Original close reason(s) were not resolved
Improve this question
how can I set default download location in youtube-dl so that everything that I download with youtube-dl goes into that default directory?

You need to use the -o switch with the Configuration file
Output on youtube-dl is handled with the --output or -o switch; pass it as an option, followed by the destination you want to save your downloads to:
youtube-dl -o "%USERPROFILE%\Desktop\%(title)s-%(id)s.%(ext)s" www.youtube.com/link/to/video
Note that -o has a dual function in that it also sets a template for how your output files will be named, using variables. In this example, it will output the title of the original downloaded video followed by the file extension, which is my personal preference. For all of the variables that can be used in a filename, have a look at the youtube-dl documentation here.
youtube-dl also allows use of a configuration file - a file that can be used to configure the switches you most frequently use so the program can pull them from there instead, saving you from having to explicitly call them each time you run it. This is what you'll need for the default download location that you're looking for. The configuration file can be used to set a default output destination so that you never have to explicitly set an output again.
To set up a configuration file for youtube-dl, assuming you have Windows:
In %APPDATA%\Roaming, create a youtube-dl folder if one doesn't already exist.
Inside that folder, create a plain text file named config.txt.
Place youtube-dl options in the file as you'd normally use them on the command line with youtube-dl, placing each one on a new line. For example, for the output switch, you'd use: -o %USERPROFILE%\Desktop. For more on the Configuration file, read the documentation on it here.
Overriding the Configuration file
Even when an option is configured in a configuration file, it can be overridden by calling it explicitly from the command line. So, if you have -o set in a configuration file to be the default location for downloads, but want to save downloads to somewhere else for a current job, simply calling -o on the command line will override the configuration file for the current run of the program only.

I find a way to directly download files in Downloads folder. I search for long hours. I copied my entire function then you can understand the context around. Here is my code it will maybe helpful for someone:
import os
def download_audio(request):
SAVE_PATH = '/'.join(os.getcwd().split('/')[:3]) + '/Downloads'
ydl_opts = {
'format': 'bestaudio/best',
'postprocessors': [{
'key': 'FFmpegExtractAudio',
'preferredcodec': 'mp3',
'preferredquality': '192',
}],
'outtmpl':SAVE_PATH + '/%(title)s.%(ext)s',
}
link = request.GET.get('video_url')
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
ydl.download(["https://www.youtube.com/watch?v="+link])
Tell me if there is a problem.

According to the configuration documentation, you can configure youtube-dl with a global or user-specific configuration file:
You can configure youtube-dl by placing any supported command line option to a configuration file. On Linux and macOS, the system wide configuration file is located at /etc/youtube-dl.conf and the user wide configuration file at ~/.config/youtube-dl/config. On Windows, the user wide configuration file locations are %APPDATA%\youtube-dl\config.txt or C:\Users\<user name>\youtube-dl.conf. Note that by default configuration file may not exist so you may need to create it yourself.
On linux, this would be your user config file:
# Save all my videos to the Videos directory:
-o ~/Videos/%(title)s.%(ext)s

Depending on your needs, I think moving the file afterwards would be just as usefull:
--exec CMD Execute a command on the file after
downloading, similar to find's -exec
syntax. Example: --exec 'adb push {}
/sdcard/Music/ && rm {}'
By creating a function which will move the file

Here is the complete solution I use:
from youtube_dl import YoutubeDL
ydl_opts = {
'format': 'best',
'outtmpl': 'DIR-PATH-HERE%(title)s'+'.mp4',
'noplaylist': True,
'extract-audio': True,
}
video = "https://www.youtube.com/watch?v=SlPhMPnQ58k"
with YoutubeDL(ydl_opts) as ydl:
info_dict = ydl.extract_info(video, download=True)
video_url = info_dict.get("url", None)
video_title = info_dict.get('title', None)
video_length = info_dict.get('duration')
# print(video_title)

In command line or in the bash file use the double quotes, like this:
"%userprofile%/Desktop/DL/%(title)s-%(id)s.%(ext)s"
My bash command:
youtube-dl -c -i -f "mp4" -o "/home/Youtube_Downloads/%(title)s-%(id)s.%(ext)s" -a youtube_list
where 'youtube_list' - a raw text file with Youtube links, that goes line by line

I found there is an official comment by the authors about that specific question.
In the manual, here's what they say: (man youtube-dl):
How do I put downloads into a specific folder?
Use the -o to specify an output template, for example -o "/home/user/videos/%(title)s-%(id)s.%(ext)s". If you want this for all of your downloads, put the option into your configuration file.
That filename pattern is the default, as per the man as well:
The current default template is %(title)s-%(id)s.%(ext)s.
I agree it would be nice to have the output folder decoupled from the default template in case the default changes one day, but I'm guessing the authors must have had a reason to have it this way.

This is the EXACT ANOTHER USEFUL method to download your video into a desired DIRECTORY, and also keep the native filename of the download.
Decide where you want to create a configuration file.
Create a file, "youtube-dl.conf". You can create a youtube-dl.txt first it it's easier, but the file must be "youtube-dl.conf".
Here is a basic sample of a config file: this is where you want your downloads to go. This is all you have to put into the file. Where -o is the flag, %userprofile%/Desktop/DL/ is where I want the download to go, and %(title)s-%(id)s.%(ext)s is the command to keep the native filename.This is your config file below:
-o %userprofile%/Desktop/DL/%(title)s-%(id)s.%(ext)s
Options found here
Config here
The command paramaters: %program% -f %option% "%youtubelink%" "%MYCONFIG%" "%MYPATH%"
Batch File setup:
::Variables:
Set program="%USERPROFILE%\Desktop\YOUTUBE-DL\v20201209\youtube-dl.exe"
Set option=best
SET MYPATH="%USERPROFILE%\Desktop\YOUTUBE-DL\v20201209\config"
SET MYCONFIG="--config-location"
SET MYDLDIR="%USERPROFILE%\Desktop\DL"
SET INSTR='%%(title)s-%%(id)s.%%(ext)s'
MKDIR "%USERPROFILE%\Desktop\DL"
::Ask user for input.
Set /P youtubelink=[Past Link]:
:: For use of config file, for default download location.
%program% -f %option% "%youtubelink%" "%MYCONFIG%" "%MYPATH%"
:: There are many ways to accomplish this:
:: For Batch File, NOTE extra (%) character needed.
:: "%program%" -f "option" --merge-output-format mp4 -o "%MYDLDIR%"\%%(title)s-%%(id)s.%%(ext)s %youtubelink%
:: or this use of variable
:: "%program%" -f "option" --merge-output-format mp4 -o "%MYDLDIR%"\%INSTR% %youtubelink%
NOTE: The use of "quotes" when there are spaces in your variable options.
Final Message:
Create the config file, put it in a folder (directory) that you wish to refer to it. Go to your youtube-dl.exe file and pass the "parameters" listed above to it using your CMD or a batch file. Done. (contribution, and being kind)

Related

How do I use configuration variables in Tesseract?

I went through this tutorial successfully: Tesseract OCR Tutorial for iOS. It uses the Tesseract OCR iOS framework.
The app works well with the sample image provided by the tutorial, but none of my own images that I test work (the output is gibberish).
To troubleshoot, the docs recommend toggling a configuration variable tessedit_write_images to true (or using configfile get.images) to view the image file to be processed. But I don't see where to set the boolean value and I'm not sure where to place or how to use a configfile.
Search for "tessedit_write_images" in the files in Xcode don't return anything.
You can set configuration variables either by providing as command line option or in a configuration file
Using Command Line Option
$tesseract input.jpg output.txt --oem 2 -l eng -c tessedit_write_images=1
-c configvar=value
Set value for control parameter. Multiple -c arguments are allowed.
Using Config File (myConfig) Option
$ tesseract Lord_Saraswathi.jpg text --oem 2 -l eng myConfig
$ cat myConfig
tessedit_write_images 1

Alternative to using --squash when building docker images on Windows using local files

We have some local installers and zip files that we use to build our docker images. It is easy to get this to work in a Dockerfile:
FROM mcr.microsoft.com/windows/nanoserver
COPY myinstaller.exe .
RUN myinstaller.exe; \
del myinstaller.exe
The problem here is that it produces a layer for the COPY line, which increases the size of the image. A common work-around for this is to have one RUN line, that downloads the file from the Internet, runs commands, and then deletes the installation file. The problem, as written above, is that the installers are on the local filesystem.
I found that there is a --squash command for docker:
docker build --squash -t mytestimage .
This does exactly what I want: It gives me an image without this extra installer file that is not necessary. To run this command, you need to enable experimental features though. There is also an open issue to simply remove this feature:
https://github.com/moby/moby/issues/34565
Is there some alternative way of using local installers in a Dockerfile when running on Windows, that doesn't involve setting up a server to provide the files?
We ended up setting up nginx to provide files when building. On our build server, the machine building our docker images and the server that has the installer files have a very good connection between them, so downloading huge files is not a real problem.
When it comes to --squash, it is bugged for Docker on Windows. Here is the relevant issue for it:
https://github.com/moby/moby/issues/31468
There is an issue to move --squash out of experimental, but it doesn't seem to have a lot of support:
https://github.com/moby/moby/issues/38657
The alternative that some people propose instead of --squash is multi stage build, discussion here:
https://github.com/moby/moby/issues/34565
There is an alternative to --squash, if you have local installer files, you don't want to set up a web server, and you would like your docker image to be small, and you are running Windows: Use mapped drives.
In Windows, you can share folders with other users on your network. Docker containers are like another computer that is running on your physical machine, and it can access these network drives.
First set up a new user, for example username share and password password1. Create a folder somewhere on your computer. Then right click it, click properties, and then go to the Sharing tab and click "Share". Find the user that you have just created, using the little dropdown menu and Find people ..., and share the folder with this user.
Create a folder somewhere for your test project. Create a batch file setupshare.bat that looks like this:
#echo off
for /f "tokens=2 delims=:" %%i in ('ipconfig ^| findstr "Default Gateway"') do (
set hostip=%%i
goto :end
)
:end
set hostip=%hostip: =%
net use O: \\%hostip%\vms /USER:share password1
The first part of this file is only to find the ip address that the docker container can use to access its host computer. It is not the most pretty thing I've ever put together, so let me know if there's a better way!
It uses a for-loop, as that is the way to save the output of a command to a variable in batch files. The command is ipconfig, and we pipe it to findstr and searches for Default Gateway. We need to use ^| instead of just | because it is in a for-loop. The first part of the for-loop divides each line from the command on the delimiter, which is : in this case, and we only take the second token. The for-loop only handles the first line, if there are multiple entries with a Default Gateway. This script doesn't work if there are multiple entries and the first one is not the correct one.
The line set hostip=%hostip: =% is to remove a space at the start of the string.
We then have the IP address that we want to use stored in hostip. We use this in the net use command, which will map O:\ to shared folder vms on the machine with IP hostip. We use the username share and the password password1. Note that this is a very bad way of handling passwords, as they kind of should be secret!
With a batch file like this, we can set up a Dockerfile in this way:
# escape=`
FROM mcr.microsoft.com/dotnet/core/sdk:3.0
COPY setupshare.bat .
RUN setupshare.bat && `
copy O:\file.txt file.txt
The RUN command will first call setupshare.bat that sets up the network share properly. We can then use any file that we shared, for example a huge installer, and install the things that we want. In this case I have only shared a test file file.txt to see that it works, so just change that line.
I would still advice everyone to just set up a little web server, for example nginx, and use the standard way of writing Dockerfiles, with downloading files and running it in the same RUN command. That's what people expect when they see a Dockerfile, and it should be a more robust solution.
We can also hope that the Docker people either makes a COPY command that can copy, run, and delete installers in the same layer, or that --squash is implemented properly.

how do I change default editor for sudo vipw from "vi" to "vim" by tcsh in FreeBSD

When I use command sudo vipw to edit my password file, It's always use vi as editor. I don't like this very much and want to change it to vim.
I already tried:
Add export EDITOR=/usr/local/bin/vim in /etc/profile.
But shell told me "export: Command not found". I thought the reason is export is built-in function only in bash. And I don't want to change my shell.
AddEDITOR=/usr/lcoal/bin/vim in default block of /etc/login.conf
Add setenv EDITOR vim in /root/.cshrc, /.cshrc, ~/.cshrc
All above didn't work at all.
I have google for hours but could not find anything help.
Your /etc/sudoers file doesn't keep your EDITOR environment variable.
I personally have an /etc/sudoers.d/local file, something like
# We don't need to worry about wheel users breaking in to get root access because they already have it.
Defaults:%wheel env_keep+="HOME EDITOR",!set_home,shell_noargs
I'm not sure why this isn't the default, since wheel users have already been given full access. But it's apparently prevailing wisdom to continue hassling them.
Note: If you're using an older /etc/sudoers file that doesn't support an /etc/sudoers.d directory, these lines can be dropped in there... or you could add #includedir /etc/sudoers.d as the last line of your /etc/sudoers file to enable an /etc/sudoers.d directory. Um, yes, the # is a required part of that line, because someone thought it was important for that directive to look like a comment.
Try adding this to the root user /root/.chsrc:
setenv EDITOR vim
or to set it globally to all users using shell tcsh/csh add it in /etc/csh.cshrc
From the man:
A login shell begins by executing commands from the system files /etc/csh.cshrc
and /etc/csh.login. It then executes commands from files in the user's home directory:
first ~/.tcshrc or, if ~/.tcshrc is not found, ~/.cshrc ...
Non-login shells read only /etc/csh.cshrc and ~/.tcshrc or ~/.cshrc on startup.
Also verify vim is installed since is not by default, you could try:
pkg install vim-console
setting the EDITOR or VISUAL environment variable is the key.
if you don't want to go to the trouble of modifying config files (which is indeed the long term solution) then you could sudo su - to get to the root prompt and then you could export EDITOR=/usr/bin/vim before running vipw
There is an empty file called .selected_editor in $HOME (/root).
Remove it and the next call to vipw will ask you to select the editor.

Run script from dock in Mac OS X

I am developing web applications using Ruby on Rails and Sublime Text 3 on OS X 10.8.4. I recently installed the package RubyTest. The tests only work when Sublime is launched using the command
subl
in terminal. Otherwise I get the error message:
/bin/sh: rspec: command not found
I think that's meant to be the case; that's implied in RubyTest's readme file on github.
However I'd like to retain the ability to launch from the dock. Is there a way I can do this?
Unfortunately, OSX applications do not pick up on your $PATH variable set in Terminal. To change the internal PATH settings in Mountain Lion (this method hasn't been tested with previous versions, although it should work), you'll need to edit /etc/launchd.conf:
Make sure you have admin privileges.
Open Terminal or your favorite substitute and see if there's anything in the file /etc/launchd.conf:
cat /etc/launchd.conf
If you get an error like
cat: /etc/launchd.con: No such file or directory
then continue with the next step. If the cat command does display some content, copy it to the clipboard.
Create a new text file with the following content, modified to fit your needs:
setenv PATH /usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin:/Users/YourUserName/bin:/path/to/gems/bin
If the cat command displayed some content in the previous step, paste it into the new file before the setenv PATH command. If it already contains a setenv PATH command, just modify it to add the directories you need, such as /path/to/gems/bin
Save the new file in your home directory (/Users/YourUserName) as launchd.conf.
Go back to Terminal and enter:
sudo mv ~/launchd.conf /etc
to use admin power to move the new file to /etc, replacing anything that was there before. Depending on your previous usage of the sudo command, you may get a short "be careful doing what you're doing" message, but either way you'll need to enter your password. /etc is not directly accessible through the Save dialog unless you're a real power user and know how to get around OSX's file system restrictions.
Reboot your computer
And you should be all set. If you're interested, launchd and launchctl use the csh/tcsh syntax, so you can't use the bash/zsh export PATH=/usr/local/bin:... format.

Avoiding the creation of .aux, .log and .synctex.gz files when using pdflatex [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 1 year ago.
Locked. This question and its answers are locked because the question is off-topic but has historical significance. It is not currently accepting new answers or interactions.
I just want to have a .tex file which I compile with pdflatex and end up with a .pdf file. I don't want all the other .aux, .log and .synctex.gz files. pdflatex doesn't seem to have arguments for this.
latexmk -c will remove the unnecessary files. latexmk is a great way to manage the compile too!
I always build my PDF files like this:
pdflatex -aux-directory=/some/temp/dir <additional options>
That way, I don't have too see all the additional files. Those files should not be removed, as they are important for cross referencing, bibliographies, table of contents etc. To run pdflatex several times and then remove the files takes too much time.
The -aux-directory unfortunately does not exist in the linux version of pdflatex. Tested on Ubuntu Lucid.
For people on Linux the equivalent to -aux-directory appears to be -output-directory, unfortunately it doesn't play nicely with \include{...} (included files' .aux files still get dumped in the current directory).
See also: the man page.
If anyone using TeXnicCenter has the same desire to only get a *.pdf file for the given *.tex file (no *.aux, *.bbl, *.blg and *.log files), here is a quick solution:
Choose from the menu: Build | Define Output Profiles, copy the "LaTeX => PDF" profile to a new profile "LaTeX => PDF ONLY", then on the Postprocessor tab create four new postprocessors:
Name: delete *.XXX
Executable: "C:\WINDOWS\system32\cmd.exe"
Arguments: /C del "%bm.XXX"
Replace XXX with aux, bbl, blg, log, respectively.
For MikTeX:
texify -cp file.tex
It will run pdflatex as many times as necessairy and clean temp files afterwards. Very useful.
A well crafted wrapper script seems to be the best answer. Something along these lines, which I've tested on Ubuntu using texlive-latex (pdftex 1.40.10) :
#!/bin/bash
TMPDIR=$(mktemp -d)
trap "rm -fr $TMPDIR; exit 255;" SIGINT SIGTERM SIGKILL
/usr/bin/latex -interaction=batchmode -output-directory=$TMPDIR $1
cp $TMPDIR/$1.dvi .
rm -fr $TMPDIR
IIRC \nofiles in your file suppresses the .aux output.
Write a shell-script wrapper which removes the files:
#!/bin/sh
pdflatex "$#" && rm -f *.aux *.log *.synctex.gz
Bonus-assignment: modifying the script to only remove the files actually created by pdflatex.
How are you creating/editing your LaTex document? If you are using Sublime Text 2, you can edit the project file to suppress opening the file types of your choosing. They will still be created upon compile but won't be loaded into your project, keeping them invisible.
Use pdflatex with -enable-write18 option and write at the end of your LaTeX file
\write18{del *.aux}
\write18{del *.log}
\write18{del *.gz}
or more pricise
\write18{del \jobname.aux}
\write18{del \jobname.log}
\write18{del \jobname.synctex.gz}
\write18{del \jobname.toc}
\write18{del \jobname.loc}
del is a DOS-function. Use rm for UNIX.

Resources