Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support setproctitle on Mac OS X [was: Question: Any way for a shell script to check if youtube-dl is running?] #8717

Open
Wowfunhappy opened this issue Mar 1, 2016 · 6 comments
Labels

Comments

@Wowfunhappy
Copy link

@Wowfunhappy Wowfunhappy commented Mar 1, 2016

Hello, I've created an Applescript for personal use that works as a sort of wrapper around youtube-dl so I can download multiple videos quickly. I'm trying to modify it so that it won't download multiple videos at the same time.

In order to accomplish this, I need to check to see if the youtube-dl process is already running (and if so, wait until it finishes. I'm currently accomplishing this with the following shell script:
ps -ax -o etime,command -c | grep python
Which will return the empty string if python is not running. Since youtube-dl uses python, this can be used to approximate whether youtube-dl itself is running.

Of course, however, this causes problems if I run a program other than youtube-dl which depends on Python. Is there any way to check if youtube-dl itself is currently running? Thank you so much!

@dstftw
Copy link
Collaborator

@dstftw dstftw commented Mar 1, 2016

Just don't run it in background and you won't have this problem at all.

@Wowfunhappy
Copy link
Author

@Wowfunhappy Wowfunhappy commented Mar 1, 2016

Sorry, I'm not sure I understand. I'm not doing anything special to make youtube-dl run in the background. Is there something specific I need to do to make sure it runs in the foreground?

@dstftw
Copy link
Collaborator

@dstftw dstftw commented Mar 2, 2016

Post your code.

@Wowfunhappy
Copy link
Author

@Wowfunhappy Wowfunhappy commented Mar 2, 2016

First, I check if youtube-dl is already running (by checking if python is running—if I check for youtube-dl directly, it will never be reported as running):

repeat while (do shell script "ps -ax -o etime,command -c | grep python; exit 0") is not equal to ""
    delay 5
end repeat

Then, I start the download:

do shell script "cd " & theFolder & "; " & YoutubeDL & " -f bestvideo[ext=mp4]+bestaudio[ext=m4a] --no-playlist --include-ads --ffmpeg-location ../  -o '%(autonumber)s.mp4' '" & theURL & "'"

theFolder has been set to my working directory and YoutubeDL has been set to the path to the youtube-dl executable. The actual terminal command that gets executed is:

cd '/Applications/Video Downloader.app/Downloading....app/1456888872.674809.tmp'; '/Applications/Video Downloader.app/Downloading....app/youtube-dl' -f bestvideo[ext=mp4]+bestaudio[ext=m4a] --no-playlist --include-ads --ffmpeg-location ../  -o '%(autonumber)s.mp4' 'https://www.youtube.com/watch?v=s4C_wDRbatM'

I run multiple of these in parallel, which is where the first piece of code (Is youtube-dl running already?) comes into play.

Here is the full program, I'm not 100% sure what you need to see.

@smitelli
Copy link

@smitelli smitelli commented Mar 2, 2016

Sounds to me like your script should create, check, and manage its own pidfile/lockfile. That is, instead of checking whether another instance of youtube-dl was running, it would instead check to see if another instance of itself was running and block until that was no longer true.

@yan12125
Copy link
Collaborator

@yan12125 yan12125 commented Mar 12, 2016

As you're writing Applescript, I guess you're using Mac OS X. On Llinux setproctitle enables the following usage:

$ pgrep youtube-dl
13507

Currently this feature supports "normal" Linuxes only. py-setproctitle can be a good reference if we're going to implement it on more systems.

@yan12125 yan12125 added the request label Mar 12, 2016
@yan12125 yan12125 changed the title Question: Any way for a shell script to check if youtube-dl is running? Support setproctitle on Mac OS X [was: Question: Any way for a shell script to check if youtube-dl is running?] Mar 12, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.