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

GUI #1865

Closed
Elite opened this issue Nov 30, 2013 · 24 comments
Closed

GUI #1865

Elite opened this issue Nov 30, 2013 · 24 comments

Comments

@Elite
Copy link

@Elite Elite commented Nov 30, 2013

Hi,

I see that progress is being made towards making youtube-dl exposed for use in other projects, I am new to python but would definitely want to give this a try and wrap YTDL in my project. Can you pls. provide a basic example to get things started i.e. how to start a download and receive progress updates in my app ?

Thanks

@jaimeMF
Copy link
Collaborator

@jaimeMF jaimeMF commented Nov 30, 2013

You can start with this code:

#!/usr/bin/env python

from youtube_dl import YoutubeDL

def progress_hook(pr):
    print(pr)

ydl_options = {
    'outtmpl': u'%(title)s-%(id)s.%(ext)s',
}

with YoutubeDL(ydl_options) as ydl:
    ydl.add_default_info_extractors()
    ydl.fd.add_progress_hook(progress_hook)
    ydl.download(['http://www.youtube.com/watch?v=BaW_jenozKc'])

The progress_hook function receives a dictionary with the download progress (not the extraction progress), you can use it to report the progress on a GUI.

I'll close the issue, but if you have any suggestion (or find a problem) for making integration easier, feel free to open new issues.

@jaimeMF jaimeMF closed this Nov 30, 2013
@velram
Copy link

@velram velram commented Nov 30, 2013

hi,
I'm also new to python. But I'm interested in this project could please
kindly involve me in this project..


velmurugan

On Sat, Nov 30, 2013 at 11:21 AM, Elite notifications@github.com wrote:

Hi,

I see that progress is being made towards making youtube-dl exposed for
use in other projects, I am new to python but would definitely want to give
this a try and wrap YTDL in my project. Can you pls. provide a basic
example to get things started i.e. how to start a download and receive
progress updates in my app ?

Thanks


Reply to this email directly or view it on GitHubhttps://github.com//issues/1865
.

@Elite
Copy link
Author

@Elite Elite commented Dec 4, 2013

I am getting following errors when using this with Python3.3 and PyQT5 ::

raise DownloadError(message, exc_info)
youtube_dl.utils.DownloadError: ERROR: Unable to download video webpage: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:547)>

I know this is an known issue (#883) and tried a fluke with the following ::

ydl_options = {
    'outtmpl': u'%(title)s-%(id)s.%(ext)s',
   'no_check_certificate':'True',
}

which failed including the YTDL.config (located in the root of repo clone) as below ::

// ADD PREDEFINED MACROS HERE!
--no-check-certificate

Pls. post the correct method to get past this roadblock.

UPDATE ::

The below worked -

ydl_options = {
    'outtmpl': u'%(title)s-%(id)s.%(ext)s',
    'nocheckcertificate':'True',
}
@Elite
Copy link
Author

@Elite Elite commented Dec 4, 2013

Stuck now at this -

 File "C:\Python33\lib\idlelib\PyShell.py", line 1318, in write
    return self.shell.write(s, self.tags)
UnicodeEncodeError: 'UCS-2' codec can't encode characters in position 51-51: Non-BMP character not supported in Tk
@phihag
Copy link
Contributor

@phihag phihag commented Dec 4, 2013

@Elite The option should be

ydl_options = {
    'outtmpl': u'%(title)s-%(id)s.%(ext)s',
    'nocheckcertificate': True,
}

However, I cannot reproduce the certificate issue, and we'll have to track down what really happens here - is your provider doing something fishy?

The UCS-2 error is a limitation of tk. Pick a toolkit that can handle all characters, or filter them out in your logger (simply pass in as 'logger' an object with a debug and an error method, then you won't have to deal with stdout and stderr). Note that our example video uses these somewhat rare characters intentionally, so for testing, you can also switch to another test video.

@Elite
Copy link
Author

@Elite Elite commented Dec 4, 2013

@phihag Thanks, I managed to hunt down the correct ydl_option and edited my answer above. I am very new to python, but I am sure will learn and make my way through using help :)

@jaimeMF
Copy link
Collaborator

@jaimeMF jaimeMF commented Dec 4, 2013

@phihag Last time I tried youtube-dl running on python 3.3 in windows I got the certificate problem (I also reproduced it with Ubuntu on a virtual machine)

@grosapepe
Copy link

@grosapepe grosapepe commented Dec 5, 2013

I'm building some kind of graphic interface for the great youtube-dl, I'm using Tkinter and python.

Anyway my gui is thinked only to help a friend who really needs to have a GUI for accessing this good binary and the program is at a real early state ( time is always my enemy!! ).

Here you have a screenshot of what I'm doing, if you feel interested let me know, we can think about a more general purpose design.

image

image 1

@yasoob
Copy link
Contributor

@yasoob yasoob commented Dec 5, 2013

Have you implemented any way to tell the progress of the download to the
user through GUI ?

On Thu, Dec 5, 2013 at 7:53 PM, Giacomo notifications@github.com wrote:

I'm building some kind of graphic interface for the great youtube-dl, I'm
using Tkinter and python.

Anyway my gui is thinked only to help a friend who really needs to have a
GUI for accessing this good binary and the program is at a real early state
( time is always my enemy!! ).

Here you have a screenshot of what I'm doing, if you feel interested let
me know, we can think about a more general purpose design.

[image: image]https://f.cloud.github.com/assets/5319876/1683354/dbd6b020-5dbc-11e3-8f87-cbd8a4c097f1.png

[image: image 1]https://f.cloud.github.com/assets/5319876/1683356/e26d482c-5dbc-11e3-9095-834787db0fde.png


Reply to this email directly or view it on GitHubhttps://github.com//issues/1865#issuecomment-29903479
.

@grosapepe
Copy link

@grosapepe grosapepe commented Dec 5, 2013

yes I can get the output in this way

image

as I mentioned the project is really at an early state and it's' just a simple prototype for a friend.

@Elite
Copy link
Author

@Elite Elite commented Dec 6, 2013

@grosapepe Can you pls. share your work so we can improve upon it?

@grosapepe
Copy link

@grosapepe grosapepe commented Dec 6, 2013

sure, which one is the best place? I mean a copy/past of my tk.py file should be enough or is there a better place where to upload files?

@Elite
Copy link
Author

@Elite Elite commented Dec 7, 2013

@grosapepe A copy-paste here would be fine.

@grosapepe
Copy link

@grosapepe grosapepe commented Dec 7, 2013

here I post a real basic GUI I created in a few hours; it's just functional programming without any class implementation and built-in calls to the main YTDL classes,

I simply controlled the binary with some switches to have a fast and simple solution, much more work can be done.

 import sys
import os
import subprocess
import re
from Tkinter import *
import tkFileDialog
from glob import glob
from string import split,replace

# test url
# https://www.youtube.com/watch?v=BaW_jenozKc
mycolor = '#FFADDE'
mycolor2 = '#303030'
mycolor3 = '#FFFFFF'

master = Tk()
master.title("youtube-dl GUI")
master.configure(bg=mycolor)

frame = Frame(master,bg=mycolor)
frame.pack()

v = StringVar()
v.set('')

v2= IntVar()

def callback():

    link = E1.get()
    print link
    if re.match('^www', link):
        link = 'https://'+link
    elif re.match('^http://', link):
        link = replace(link,'http://','https://') 
    else:
        link = link
    print link
    h = setupDownload(link)
    v.set(h)
    currentdir = os.getcwd()
    print link[32:]
    downloadedFileName = glob(currentdir+'\\'+link[32:]+'.*')
    print downloadedFileName
    listPath = split(downloadedFileName[0],'\\')
    idFileName = listPath[len(listPath)-1]
    saveas(idFileName)

def setupDownload(a):
    stdout = subprocess.Popen('youtube-dl.exe ' + a + ' --max-quality=flv --id ', shell=True, stdout=subprocess.PIPE).stdout
    output = stdout.read()
    return output

def donothing():
   filewin = Toplevel(master)
   button = Button(filewin, text="Do nothing button")
   button.pack()

def checkForUpdates():
    stdout = subprocess.Popen('youtube-dl.exe -U ', shell=True, stdout=subprocess.PIPE).stdout
    output = stdout.read()
    print output
    v.set(output)
    return output

def saveas(idFileName):
    myFormats = [
    ('An Mp3 File','*.mp3'),
    ('All files','*.*'),
    ]
    fileName = tkFileDialog.asksaveasfilename(parent=master,filetypes=myFormats ,title="Save the video as...")
    if len(fileName ) > 0:
        print "saving %s" % fileName
        if (v2.get() == 0):
            subprocess.call(['ffmpeg', '-i', idFileName , '-f' , 'mp3' , fileName+'.mp3' ])
            try:
                os.remove(idFileName)
                v.set("Finish!!!")
            except OSError:
                pass
        elif (v2.get() == 1):
            print idFileName
            print fileName
            os.rename(idFileName,fileName+idFileName[11:])
            v.set('preserving video content')

def main():

    # Menu
    menubar = Menu(master)
    filemenu = Menu(menubar, tearoff=0)
    filemenu.add_command(label="Save as...", command=callback)
    filemenu.add_command(label="Close", command=master.quit)
    filemenu.add_separator()
    filemenu.add_command(label="Exit", command=master.quit)
    menubar.add_cascade(label="File", menu=filemenu)

    editmenu = Menu(master, tearoff=0)
    editmenu.add_command(label="Undo", command=donothing)

    editmenu.add_separator()

    editmenu.add_command(label="Cut", command=donothing)
    editmenu.add_command(label="Copy", command=donothing)
    editmenu.add_command(label="Paste", command=donothing)
    editmenu.add_command(label="Delete", command=donothing)
    editmenu.add_command(label="Select All", command=donothing)
    editmenu.add_separator()

    editmenu.add_command(label="Check for Updates", command=checkForUpdates)

    menubar.add_cascade(label="Edit", menu=editmenu)

    # Application
    w = Label(frame, text="+++===youtube-dl GUI===+++",font=("Helvetica", 11), bg=mycolor)
    w.pack()

    L1 = Label(frame, textvariable=v, borderwidth=2,bg=mycolor)#.pack()
    L1.pack()

    c = Checkbutton(frame, text="Preserve Video", variable=v2)
    c.pack()

    L2 = Label(frame, text="Insert link: ", font=("Helvetica", 8), bg=mycolor)
    L2.pack( side = LEFT)

    global E1
    E1 = Entry(frame, width=50,bd=3)
    E1.insert(0,'https://www.youtube.com/watch?v=BaW_jenozKc')
    E1.pack(side = RIGHT)
    E1.focus_set()

    S1 = Frame(height=2, bd=0, relief=SUNKEN,bg=mycolor)
    S1.pack(fill=X, padx=200, pady=10)

    B1 = Button(master, text="Get Song!",bg=mycolor2,foreground=mycolor3, width=10, command=callback)
    B1.pack()

    S2 = Frame(height=2, bd=0, relief=SUNKEN,bg=mycolor)
    S2.pack(fill=X, padx=200, pady=10)
    master.config(menu=menubar)
    mainloop()

if __name__ == '__main__':
    main()
@jaimeMF
Copy link
Collaborator

@jaimeMF jaimeMF commented Dec 7, 2013

@grosapepe If your are going to work on it, you could create a repository, so that people can easily contribute to the code.

@Elite
Copy link
Author

@Elite Elite commented Dec 8, 2013

@grosapepe Thanks for sharing this but this uses Youtube-dl binary file, since YTDL can be imported as an library as shown and discussed above it would be a more preferred way.

@grosapepe
Copy link

@grosapepe grosapepe commented Dec 8, 2013

ok, I will consider to create a space for this project; as I said it was controlling the binary and not doing internal calls to the library. Anyway it seems to be not so complicated to rewrite those calls importing the library instead. Anyone who feels to give me some help on it... :)

@ghost
Copy link

@ghost ghost commented Dec 8, 2013

Here is mine. Uses tk and threading to update progressbar (does not deal with errors).

https://gist.github.com/pulpe/7854561

@jaimeMF
Copy link
Collaborator

@jaimeMF jaimeMF commented Dec 8, 2013

The script posted by @pulpe seems to be a good start for using the library. If you have any question I'll happily try to help.

@grosapepe
Copy link

@grosapepe grosapepe commented Dec 8, 2013

ok, it seems we have two nice prototypes and that's it! As I expressed also to @phihag my purpose was to create something really professional that aims to be something similar to the zenmap interface for the nmap binary.
I guess the really basic step for that purpose is to define some prerequisites and even some scatches of how the GUI would be in the beta prototype and from there starting to code on parallel inside a working group.
Consider the goodness of this contribute inserted in an open-source environment and consider also all limitations of this approach ( I mean coding in the spare time, no remuneration for this effort and all the stuff that everyone of us understand and obviously already know :)
any suggestion?

@Elite
Copy link
Author

@Elite Elite commented Dec 9, 2013

I managed to make a working prototype in PyQT5, pls. tell how to capture any output other then progress_hook like "Setting Language", error messages and get output for switches like -e, --get-title to populate the GUI info panel?

@phihag
Copy link
Contributor

@phihag phihag commented Dec 9, 2013

@Elite Pass in a 'logger' object to get status output. Look at the return value you're getting from the function calls, these will be the info dictionaries which you can see with -j.

@Elite
Copy link
Author

@Elite Elite commented Dec 9, 2013

OK got it, this works-

info = ydl.extract_info('https://www.youtube.com/watch?v=JzrbQHolJyg',False)
@ghost
Copy link

@ghost ghost commented Dec 9, 2013

If you search github for youtube gui you find a lots of gui implementations.

For example https://github.com/chummm/ydlqt why don't we fork it?

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
6 participants
You can’t perform that action at this time.