Efty.Edge

Problem to start a Python script

10 posts in this topic

Hi,

 

Here is my idea of a youtube video downloader workflow.

 

I try to catch the url of the browser and send the url to the youtube-dl script created by Ricardo Garcia Gonzalez (http://rg3.github.io/youtube-dl/index.html).

 

The syntax to download a youtube video in HQ is simple, just: youtube-dl <url>

 

Everthing works fine except one thing. First I dropped the youtube-dl script into the workflow folder. Then i opened a Youtube Video and started my workflow. In the notification center the catched url is shown. But the youtube-dl script/programm didn't start.

 

Please give me some advice. I'm really, really new to scripting ...

 

Thanx in advance

Efty

 

 

#!/bin/bash

# cases that handles fetching the URL them self
case "$1" in
    
    *)
        # all other options need the URL, so lets fetch it
        THEURL=$(sh getURL.sh)
        # if no url then just exit
        if [ -z "$1" ]
            then
            echo "Unable to find a URL"
            exit
        else
           echo $THEURL
           youtube-dl  + $THEURL
        fi       
esac

 

 

 

Share this post


Link to post

Hi,

 

Here is my idea of a youtube video downloader workflow.

 

I try to catch the url of the browser and send the url to the youtube-dl script created by Ricardo Garcia Gonzalez (http://rg3.github.io/youtube-dl/index.html).

 

The syntax to download a youtube video in HQ is simple, just: youtube-dl <url>

 

Everthing works fine except one thing. First I dropped the youtube-dl script into the workflow folder. Then i opened a Youtube Video and started my workflow. In the notification center the catched url is shown. But the youtube-dl script/programm didn't start.

 

Please give me some advice. I'm really, really new to scripting ...

 

Thanx in advance

Efty

 

 

#!/bin/bash

# cases that handles fetching the URL them self
case "$1" in
    
    *)
        # all other options need the URL, so lets fetch it
        THEURL=$(sh getURL.sh)
        # if no url then just exit
        if [ -z "$1" ]
            then
            echo "Unable to find a URL"
            exit
        else
           echo $THEURL
           youtube-dl  + $THEURL
        fi       
esac

 

Try this..

In the Run Script module, leave the language set to /bin/bash.

 

var="{query}"
if [ -z $var ]; then
  echo "No url provided"
else
  youtube-dl "$var"
fi

 

This will run the script if a value is passed. You could always just set your keyword to require an argument and you won't have to check if its empty. This worked for me.

Share this post


Link to post

Hi David!

 

Sorry for my late reply and thank you for your help.

 

But i'm not able to get your script to work with mine. So developed following solution in applescript.

 

#/usr/bin/osascript

try
	tell application "Safari" to tell document 1
		set theLink to (get URL)
	end tell
end try

try
    tell application "Terminal"
        do shell script "python youtube-dl -o ~/Downloads/movie.mp4 " & theLink
    end tell
end try

tell application "Terminal" to quit

return "Download Finished... " 

 

 

This one works really fine, but i have a few questions you can maybe help me with.

 

I would like to use an argument after the keyword to replace the filename 'movie.mp4' with a user defined one. How can i do it?

 

Is it possible the execute the 'do shell script...' without a visible Terminal window?

 

And at last. Is it possible to display a notification in the Notification Center like 'Download started...' at the start of the script which stays visible until the script is finished!? Actual it disappears after 5 sec. as normal.

 

Thank you again.

Efty

Edited by Efty Edge

Share this post


Link to post

Is it possible the execute the 'do shell script...' without a visible Terminal window?

 

David's infinitely more qualified than I am to answer your questions, so I'll take the easy one :-) The do shell script command normally does run without creating a Terminal window, the only reason it's doing it here is because you included it in a tell application "Terminal" block. Try this:

 

#/usr/bin/osascript

try
    tell application "Safari" to tell document 1
	set theLink to (get URL)
    end tell
end try

try
    do shell script "python youtube-dl -o ~/Downloads/movie.mp4 " & theLink
end try

return "Download Finished... "

For the record, if you are using AppleScript to tell Terminal to run a shell script, you can actually do it with do script rather than the full do shell script command :-)

 

EDIT: I'm also not sure what the duplicate try blocks are meant to accomplish. Couldn't you achieve the same thing with just one?

#/usr/bin/osascript

try
    tell application "Safari" to tell document 1
	set theLink to (get URL)
    end tell

    do shell script "python youtube-dl -o ~/Downloads/movie.mp4 " & theLink
end try

return "Download Finished... "
Edited by Subject22

Share this post


Link to post

Hi David!

 

Sorry for my late reply and thank you for your help.

 

But i'm not able to get your script to work with mine. So developed following solution in applescript.

 

#/usr/bin/osascript

try
	tell application "Safari" to tell document 1
		set theLink to (get URL)
	end tell
end try

try
    tell application "Terminal"
        do shell script "python youtube-dl -o ~/Downloads/movie.mp4 " & theLink
    end tell
end try

tell application "Terminal" to quit

return "Download Finished... " 

 

 

This one works really fine, but i have a few questions you can maybe help me with.

 

I would like to use an argument after the keyword to replace the filename 'movie.mp4' with a user defined one. How can i do it?

 

Is it possible the execute the 'do shell script...' without a visible Terminal window?

 

And at last. Is it possible to display a notification in the Notification Center like 'Download started...' at the start of the script which stays visible until the script is finished!? Actual it disappears after 5 sec. as normal.

 

Thank you again.

Efty

 

Try this: download

 

I tried this with several videos and it worked perfectly for me. Give it a youtube link, it downloads the video, names the file the title of the video and saves it to your desktop

Share this post


Link to post

Hi Subject22 and David.

 

Thanx for your help and your advice. I'm a scripting newbie, so i'm very glad and thankful for any help!

 

David - your script works like charm, but i didn't really understand how it works. I promise, i've tried it an hour or two!!! At last i finished mine in Applescript ...

 

 

Efty

Share this post


Link to post

Does this still work? I can't get it to work with the latest version of Alfred. It says download complete suspiciously fast and the file doesn't appear.

Share this post


Link to post

Does this still work? I can't get it to work with the latest version of Alfred. It says download complete suspiciously fast and the file doesn't appear.

 

Chances are you just need to update the youtube-dl script within the workflow. Looky here.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now