Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F4793069
http2pls
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
http2pls
View Options
#!/usr/bin/env python3
from
bs4
import
BeautifulSoup
from
urllib
import
request
,
parse
from
os
import
path
from
sys
import
argv
,
exit
,
stderr
def
get_url
(
base_url
,
tag
):
relative_url
=
tag
.
get
(
"href"
)
return
parse
.
urljoin
(
base_url
,
relative_url
)
def
is_media_extension
(
extension
):
valid_extensions
=
[
# Videos
".avi"
,
".flv"
,
".mp4"
,
".wmv"
,
".mkv"
,
]
return
extension
in
valid_extensions
def
is_media_link
(
url
):
extension
=
path
.
splitext
(
url
)[
1
]
return
is_media_extension
(
extension
)
def
print_pls
(
url
):
links
=
get_media_links
(
url
)
if
not
links
:
return
print
(
"[playlist]"
)
i
=
0
for
link
in
links
:
i
+=
1
print
(
"File
{:d}
=
{:s}
"
.
format
(
i
,
link
))
print
(
""
)
print
(
"NumberOfEntries=
{:d}
"
.
format
(
i
))
print
(
"Version=2"
)
def
get_media_links
(
url
):
return
[
link
for
link
in
get_links
(
url
)
if
is_media_link
(
link
)]
def
get_links
(
url
):
try
:
with
request
.
urlopen
(
url
)
as
response
:
body
=
response
.
read
()
soup
=
BeautifulSoup
(
body
,
"html.parser"
)
return
[
get_url
(
url
,
link
)
for
link
in
soup
.
find_all
(
"a"
)]
except
ValueError
:
print
(
"No valid URL: "
+
url
,
file
=
stderr
)
return
[]
def
run
():
if
len
(
argv
)
<
2
:
exit
(
1
)
print_pls
(
argv
[
1
])
if
__name__
==
"__main__"
:
run
()
File Metadata
Details
Attached
Mime Type
text/x-python
Expires
Fri, Feb 28, 21:39 (1 d, 4 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2444834
Default Alt Text
http2pls (1 KB)
Attached To
Mode
rOPS Nasqueron Operations
Attached
Detach File
Event Timeline
Log In to Comment