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

How do I cancel Youtube Upload ? #150

Open
funnymobiledev opened this issue Oct 26, 2017 · 11 comments
Open

How do I cancel Youtube Upload ? #150

funnymobiledev opened this issue Oct 26, 2017 · 11 comments

Comments

@funnymobiledev
Copy link

I want to implemment upload function in youtube api with function pause, continue and cancel

How do I make cancel function.

@akshanshjain95
Copy link

It has not been implemented in the youtube api, you will have to do it yourself. For me, I did it using akka actors, and throw an exception while the progress function (setProgressListener provided by the youtube api) was in the MEDIA_IN_PROGRESS case. I am still wondering why is it not implemented in the api itself. Can be a good addition as far as I can think.

@ofarukkalkan
Copy link

i need also this functionality to stop uploading...

@mindforger
Copy link

mindforger commented Feb 19, 2018

I did it using akka actors, and throw an exception while the progress function (setProgressListener provided by the youtube api) was in the MEDIA_IN_PROGRESS case

@akshanshjain95
i don't get behind what your are doing there, can you explain that a bit simpler for one that has not understand the whole docu yet? I just want to know how i can terminate the upload after i called insert_request.next() which blocks my application. I want it to abort the operation and continue my workflow until i can leave the program safely in case of an sig15 for example or maybe even jsut pause this request if i signal to upload a more important file for now

@akshanshjain95
Copy link

akshanshjain95 commented Feb 20, 2018

@mindforger
Ok, so in simple terms, what I did was to start uploading a video on a thread, separate from everything else, and get the status of upload on a different thread. Basically, start upload of video on a different thread and listen to the upload progress on a different one. In the thread you're listening to the upload progress, keep a flag, which changes to some other value when you want to cancel it. Keep checking the flag's value while listening to the upload progress. When the flag value is that of 'cancel', throw an Exception in the listener, which will stop the video upload to youtube. This is a bad way, but I did not find a better way than this to cancel the upload. Also remember that this will leave an unfinished uploaded video on you youtube account. You can delete it either manually or can use the delete functionality provided by the youtube api.

@mindforger
Copy link

mindforger commented Feb 20, 2018

and get the status of upload on a different thread

this is possible? nice!

throw an Exception in the listener

but how? my code is stuck on insert_request.next() while it is uploading isn't it?

(to be clear i have not yet verified that the code really is stuck but from the example script it looks like maybe i should add some debug outputs this evening to look what is going on there :P)

@akshanshjain95
Copy link

@mindforger
Call insert_request.next() on a separate thread and listen to the upload on a separate thread. You code will get stuck when you execute insert_request.next() so there's no way of stopping it on the thread calling this method.

@mindforger
Copy link

mindforger commented Feb 20, 2018

listen to the upload on a separate thread

maybe got a hint where to search for that function or a more comprehensive documentation than this tutorials scattered over the internet (i am sorrys for bothering but i feel like not seeing the woods because of all those trees ... hope that translates right :P)
and how to actually abort it then? i mean can i call something that aborts the .next() call effectively or do i have to kill the thread?

(i honestly never killed a thread forecfully before, i always used soem sort of sleep polling methode to shutdown threads safely)

@akshanshjain95
Copy link

akshanshjain95 commented Feb 20, 2018

@mindforger
There's no function in youtube api for doing this. You'll have to implement th concept yourself. Killing thread is what my idea is hinting towards. I did it using akka, I don't know whether you're familiar with it or not, but what I did was throw an exception on the thread listening to the upload progress.

You cannot call anything to abort .next(). You will have to kill the thread as far as I can think.

@mindforger
Copy link

thanks for spending so much time helping me, i'll try it out this evening, i also have to deal with moving the files from my PC to my PI prior starting the upload (and some way to fill in the meta data for the upload required), so there will be a lot of other issues around before i can try out the multithread upload approach

@akshanshjain95
Copy link

@mindforger
My pleasure. I spent some tough time dealing with this, so I can understand your pain, haha xD.

@mindforger
Copy link

the biggest pain is living with only 1mbit upload ... it's the worst ... especially when you had only a choice between 12mbits upload for the price of sanity becasue of ignorant neighbours or 1mbits but a piece of heaven to live in :)

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

No branches or pull requests

5 participants
@mindforger @ofarukkalkan @akshanshjain95 @funnymobiledev and others