Spaces:
Running
Running
DebasishDhal99
commited on
Commit
•
5266a81
1
Parent(s):
3cb3678
Update playlists_mismatch.py
Browse files- playlists_mismatch.py +8 -22
playlists_mismatch.py
CHANGED
@@ -3,28 +3,14 @@ from urllib.parse import urlparse, parse_qs
|
|
3 |
def playlists_mismatch_func(playlistlink1, playlistlink2, output = 'link'):
|
4 |
"""Return the ids of videos that are only one of the playlists, and not in the other"""
|
5 |
|
6 |
-
def
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
if query.hostname in {'www.youtube.com', 'youtube.com', 'music.youtube.com'}:
|
15 |
-
if not ignore_playlist:
|
16 |
-
# use case: get playlist id not current video in playlist
|
17 |
-
try:
|
18 |
-
return parse_qs(query. Query)['list'][0]
|
19 |
-
except KeyError:
|
20 |
-
return None
|
21 |
-
if query.path == '/watch': return parse_qs(query.query)['v'][0]
|
22 |
-
if query.path[:7] == '/watch/': return query.path.split('/')[1]
|
23 |
-
if query.path[:7] == '/embed/': return query.path.split('/')[2]
|
24 |
-
if query.path[:3] == '/v/': return query.path.split('/')[2]
|
25 |
-
|
26 |
-
playlist1id = get_yt_id(playlistlink1)
|
27 |
-
playlist2id = get_yt_id(playlistlink2)
|
28 |
print("Playlist IDs obtained")
|
29 |
|
30 |
assert playlist1id!= None, "Playlist 1 link is invalid"
|
|
|
3 |
def playlists_mismatch_func(playlistlink1, playlistlink2, output = 'link'):
|
4 |
"""Return the ids of videos that are only one of the playlists, and not in the other"""
|
5 |
|
6 |
+
def extract_playlist_id(playlistlink):
|
7 |
+
match = re.search(r'list=([^&]+)', playlistlink) #It searches for the string 'list=' followed by >=1 characters that are not '&'.
|
8 |
+
if match:
|
9 |
+
return match.group(1)
|
10 |
+
return None
|
11 |
+
|
12 |
+
playlist1id = extract_playlist_id(playlistlink1)
|
13 |
+
playlist2id = extract_playlist_id(playlistlink2)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
print("Playlist IDs obtained")
|
15 |
|
16 |
assert playlist1id!= None, "Playlist 1 link is invalid"
|