Jump to content

Dont know how to call it

Go to solution Solved by fizzlesticks,

Sorry I have no Idea from Python, I installed it, but how to I run the Code?

:|

Iam a noob D:

First you'll need the lxml library. Go here and find the right version for the Python version you installed. The number after the cp is the Python version then make sure you get the win32 option if you have 32 bit Python or the amd64 option if you have 64bit Python. 

Then open a command window where ever you downloaded that file to and run the command

 

pip install "filename that you just downloaded here"

 

Next copy the code I posted into a file called whatever.py

And finally open a command window where ever you made that file and run the command

 

python whatever.py

 

and that should create a file called timestamps.txt in the same directory as the file.

Ok, lets keep it short:

I want to create a diagram where you can see the episode lenth of each episode.

Just like this diagramm but with way more episodes 

 

It is a YouTube Playlist just like this one: https://www.youtube.com/playlist?list=PL972376D5D39348DA

But I dont want to write it manualy into my Excel Sheet because there are way over 1300 Episodes

Is there a way a script can write the lenth of each episode into a .txt or something similar?

post-107152-0-36746700-1436090548.png

Link to comment
Share on other sites

Link to post
Share on other sites

There's a little length indicator next to every video you know.

Link to comment
Share on other sites

Link to post
Share on other sites

There's a little length indicator next to every video you know.

Ok, if its so easy please manual write the lenth of each 1251 Episodes into my Excel, Thanks xD

Iam searching for an automatic way :)

Link to comment
Share on other sites

Link to post
Share on other sites

Ok, if its so easy please manual write the lenth of each 1251 Episodes into my Excel, Thanks xD

I am searching for an automatic way :)

 

Why would you do this?

Link to comment
Share on other sites

Link to post
Share on other sites

Why would you do this?

Long story, i just want ^^

Link to comment
Share on other sites

Link to post
Share on other sites

in firefox press F12, go to the console, and run this

[for(x of document.getElementsByClassName("timestamp")) x.firstChild.innerHTML].join("\n")

edit: of course you need to open the playlist page first. the code will put a list of all the lengths in the console window. you can copypaste that into excel, and it should split it automatically one in each cell

Link to comment
Share on other sites

Link to post
Share on other sites

You'll need Python and lxml to run it but this gets all the timestamps and dumps them into a file.

import sysimport urllib.requestfrom lxml import etreeurl = 'https://www.youtube.com/playlist?list=PL972376D5D39348DA'output_filename = 'timestamps.txt'def main():    try:        res = urllib.request.urlopen(url).read()    except:        print('Unable to load page {}.'.format(url))        return 1    tree = etree.ElementTree(etree.HTML(res))    spans = tree.xpath("//div[@class='timestamp']/span")    if spans:        times = [span.text for span in spans]        with open(output_filename, 'w') as out:            out.write('\r\n'.join(times))        return 0    else:        print('No timestamps found.')    return 1if __name__ == '__main__':    sys.exit(main())
edit: or do what Ciccioo said, that looks easier.

1474412270.2748842

Link to comment
Share on other sites

Link to post
Share on other sites

in firefox press F12, go to the console, and run this

[for(x of document.getElementsByClassName("timestamp")) x.firstChild.innerHTML].join("\n")

edit: of course you need to open the playlist page first. the code will put a list of all the lengths in the console window. you can copypaste that into excel, and it should split it automatically one in each cell

Okey, the command looks nice but I have an Error:FzaJ7pr.png

Uncaught SyntaxError: Unexpected token for
    at Object.InjectedScript._evaluateOn (<anonymous>:895:140)
    at Object.InjectedScript._evaluateAndWrap (<anonymous>:828:34)
    at Object.InjectedScript.evaluate (<anonymous>:694:21)
 
What am I doing wrong?
Link to comment
Share on other sites

Link to post
Share on other sites

You'll need Python and lxml to run it but this gets all the timestamps and dumps them into a file.

import sysimport urllib.requestfrom lxml import etreeurl = 'https://www.youtube.com/playlist?list=PL972376D5D39348DA'output_filename = 'timestamps.txt'def main():    try:        res = urllib.request.urlopen(url).read()    except:        print('Unable to load page {}.'.format(url))        return 1    tree = etree.ElementTree(etree.HTML(res))    spans = tree.xpath("//div[@class='timestamp']/span")    if spans:        times = [span.text for span in spans]        with open(output_filename, 'w') as out:            out.write('\r\n'.join(times))        return 0    else:        print('No timestamps found.')    return 1if __name__ == '__main__':    sys.exit(main())
edit: or do what Ciccioo said, that looks easier.

 

Sorry I have no Idea from Python, I installed it, but how to I run the Code?

:|

Iam a noob D:

Link to comment
Share on other sites

Link to post
Share on other sites

Sorry I have no Idea from Python, I installed it, but how to I run the Code?

:|

Iam a noob D:

First you'll need the lxml library. Go here and find the right version for the Python version you installed. The number after the cp is the Python version then make sure you get the win32 option if you have 32 bit Python or the amd64 option if you have 64bit Python. 

Then open a command window where ever you downloaded that file to and run the command

 

pip install "filename that you just downloaded here"

 

Next copy the code I posted into a file called whatever.py

And finally open a command window where ever you made that file and run the command

 

python whatever.py

 

and that should create a file called timestamps.txt in the same directory as the file.

1474412270.2748842

Link to comment
Share on other sites

Link to post
Share on other sites

 

Okey, the command looks nice but I have an Error:

-imagesnip-

Uncaught SyntaxError: Unexpected token for
    at Object.InjectedScript._evaluateOn (<anonymous>:895:140)
    at Object.InjectedScript._evaluateAndWrap (<anonymous>:828:34)
    at Object.InjectedScript.evaluate (<anonymous>:694:21)
 
What am I doing wrong?

 

dunno, can't replicate. what version of firefox are you running? maybe you're a chrome user and your ff is just outdated

this is a more "old school" equivalent of that script

Array.prototype.slice.call(document.getElementsByClassName("timestamp"),0).map(function(x){ return x.firstChild.innerHTML; }).join("\n");

edit: i didn't notice that you were running chrome. apparently chrome's V8 didn't implement the latest ECMAscript proposals (which is understandable, they're not official yet), so you can't use array comprehensions in chrome. the piece of code i just posted will work though, it's all standard ECMAscript

Link to comment
Share on other sites

Link to post
Share on other sites

dunno, can't replicate. what version of firefox are you running? maybe you're a chrome user and your ff is just outdated

this is a more "old school" equivalent of that script

Array.prototype.slice.call(document.getElementsByClassName("timestamp"),0).map(function(x){ return x.firstChild.innerHTML; }).join("\n");

edit: i didn't notice that you were running chrome. apparently chrome's V8 didn't implement the latest ECMAscript proposals (which is understandable, they're not official yet), so you can't use array comprehensions in chrome. the piece of code i just posted will work though, it's all standard ECMAscript

Ok, tyring it with firefox ...

 

OMG <3

Thank you SO SO much :D

Awesome what people can do :o <3

Thanks :) :)

Link to comment
Share on other sites

Link to post
Share on other sites

First you'll need the lxml library. Go here and find the right version for the Python version you installed. The number after the cp is the Python version then make sure you get the win32 option if you have 32 bit Python or the amd64 option if you have 64bit Python. 

Then open a command window where ever you downloaded that file to and run the command

 

pip install "filename that you just downloaded here"

 

Next copy the code I posted into a file called whatever.py

And finally open a command window where ever you made that file and run the command

 

python whatever.py

 

and that should create a file called timestamps.txt in the same directory as the file.

However i tried Ciccioo's Version which worked perfect for me :)

 

 

Thanks for you help anyways <3

Wow Iam so happy :D:)

Link to comment
Share on other sites

Link to post
Share on other sites

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

×