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

add --playlist option #46

Merged
merged 3 commits into from Jul 22, 2015
Merged

add --playlist option #46

merged 3 commits into from Jul 22, 2015

Conversation

sbma44
Copy link
Contributor

@sbma44 sbma44 commented Jul 22, 2015

pretty simple: --playlist "playlist title" will iterate through the user's playlists looking for playlist title. If found, the video will be added to it. If not found, the playlist will be created using the privacy settings for the currently-uploading video, then the video will be added to it.

@tokland
Copy link
Owner

tokland commented Jul 22, 2015

Wow, thanks! Can I make some suggestions before pulling?

  • Leave out the spaces removal from the commit, we can do it in a separate one.
  • The code within if options.playlist: is too long. I'd abstract it in a funcion (maybe in a new module youtube_upload/playlists.py?).

@sbma44
Copy link
Contributor Author

sbma44 commented Jul 22, 2015

  • rolled back whitespace commit
  • moved playlist code to playlists.py

you might notice that my import style is different -- feel free to change, but I would recommend moving to this style rather than prefixing everything with youtube_upload. The latter makes development difficult, since it will pull from the version installed in site_packages rather than the file in the current directory. I had to python setup.py install --force every time I made a change, which seemed unnecessary. Possibly I'm missing something, but I think you should be able to just e.g. import auth from files like main.py.

@tokland
Copy link
Owner

tokland commented Jul 22, 2015

Looks good. I have some problems when testint it:

$ PYTHONPATH=. python2 bin/youtube-upload --title "Title" --playlist "Test playlist2" test.mp4 
Using client secrets: /usr/share/youtube_upload/client_secrets.json
Using credentials file: /home/arnau/.youtube-upload-credentials.json
Start upload: test.mp4
100% |#####################################################################| Time: 0:00:03 338.92 kB/s
Traceback (most recent call last):
  File "bin/youtube-upload", line 208, in <module>
    sys.exit(lib.catch_exceptions(EXIT_CODES, main, sys.argv[1:]))
  File "/home/arnau/src/youtube-upload/youtube_upload/lib.py", line 35, in catch_exceptions
    fun(*args, **kwargs)
  File "bin/youtube-upload", line 205, in main
    run_main(parser, options, args)
  File "bin/youtube-upload", line 160, in run_main
    playlists.add_to_playlist(youtube, video_id, options)
  File "/home/arnau/src/youtube-upload/youtube_upload/playlists.py", line 9, in add_to_playlist
    results = request.execute()
  File "/usr/lib/python2.7/site-packages/oauth2client/util.py", line 137, in positional_wrapper
    return wrapped(*args, **kwargs)
  File "/usr/lib/python2.7/site-packages/googleapiclient/http.py", line 729, in execute
    raise HttpError(resp, content, uri=self.uri)
googleapiclient.errors.HttpError: <HttpError 403 when requesting https://www.googleapis.com/youtube/v3/playlists?alt=json&part=id%2Csnippet&mine=true returned "Insufficient Permission">

Any idea?

@sbma44
Copy link
Contributor Author

sbma44 commented Jul 22, 2015

did you regenerate .youtube-upload-credentials.json ? You'll need to reauth -- playlist management requires the https://www.googleapis.com/auth/youtube auth scope. This gets set when you do the oauth2 dance and can't be updated afaik.

Apologies for not mentioning this in the PR text -- definitely set me back a day to figure it out the first time.

@tokland tokland merged commit fb10d6b into tokland:master Jul 22, 2015
@tokland
Copy link
Owner

tokland commented Jul 22, 2015

Oh, of course! Commited, thx very much!

@sbma44
Copy link
Contributor Author

sbma44 commented Jul 22, 2015

👏

@sbma44 sbma44 deleted the playlist-support branch July 22, 2015 15:28
@sbma44 sbma44 restored the playlist-support branch July 22, 2015 15:29
@sbma44
Copy link
Contributor Author

sbma44 commented Jul 22, 2015

ah, sorry, one last thing: probably worth adding a line to the README. I should have thought of this.

@tokland
Copy link
Owner

tokland commented Jul 22, 2015

Good point. 8318a11

@tokland
Copy link
Owner

tokland commented Jul 23, 2015

We have a problem with the relative import from the main executable: #47. What do you think of 0228617?

@sbma44
Copy link
Contributor Author

sbma44 commented Jul 23, 2015

Rats. I don't know an elegant solution here--my experience rolling python packages is more limited than I would like and relative imports seem a bit rough to me. I would love a scenario where both python youtube_upload/bin/youtube-upload and python youtube_upload/youtube_upload/main.py work, for development purposes, but having the installed package operate properly seems like it has to be the priority.

@tokland
Copy link
Owner

tokland commented Jul 23, 2015

Unfortunately, no idea either what's the way to go, I'll have to check it. SO yields 25 ways of doing it :)

@sbma44
Copy link
Contributor Author

sbma44 commented Jul 23, 2015

@tokland looking at it more I think the relative import you've got is the correct way to do it and development should occur through entry points other than main.py

@tokland
Copy link
Owner

tokland commented Jul 23, 2015

greeeat!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants