Spaces:
Runtime error
Runtime error
File size: 25,374 Bytes
22d9367 e7c64ec 22d9367 e7c64ec 22d9367 e7c64ec 22d9367 e7c64ec 22d9367 e7c64ec 22d9367 e7c64ec 22d9367 e7c64ec 22d9367 e7c64ec 22d9367 e7c64ec 22d9367 e7c64ec 22d9367 e7c64ec 22d9367 e7c64ec 22d9367 e7c64ec 22d9367 e7c64ec 22d9367 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 |
{
"cells": [
{
"cell_type": "code",
"execution_count": 41,
"metadata": {},
"outputs": [],
"source": [
"from youtube_transcript_api import YouTubeTranscriptApi\n",
"from nltk.tokenize import TextTilingTokenizer \n",
"import pandas as pd\n",
"import numpy as np\n",
"import requests\n",
"import json\n",
"\n",
"url = \"https://www.youtube.com/watch?v=77zvIYDFSok\"\n",
"video_id = url.split(\"=\")[1]\n",
"\n",
"try:\n",
" raw = YouTubeTranscriptApi.get_transcript(video_id)\n",
"except:\n",
" transcript_list = YouTubeTranscriptApi.list_transcripts(video_id)\n",
" for transcript in transcript_list:\n",
" raw = transcript.translate('en').fetch()\n",
" break\n",
"\n",
"response = requests.get(f\"https://noembed.com/embed?dataType=json&url={url}\")\n",
"data = json.loads(response.content)\n",
"\n",
"title, author = data[\"title\"], data[\"author_name\"]"
]
},
{
"cell_type": "code",
"execution_count": 42,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[{'text': '[Music]', 'start': 2.19, 'duration': 3.5},\n",
" {'text': '[Music]', 'start': 18.73, 'duration': 3.07},\n",
" {'text': '[Applause]', 'start': 27.71, 'duration': 3.289},\n",
" {'text': '[Music]', 'start': 33.68, 'duration': 7.01},\n",
" {'text': '[Laughter] [Music] [Music] [', 'start': 36.05, 'duration': 4.64},\n",
" {'text': 'Applause]', 'start': 59.97, 'duration': 3.2},\n",
" {'text': '[Music]', 'start': 68.78, 'duration': 3.12},\n",
" {'text': 'Recently, the', 'start': 72.18, 'duration': 3.0},\n",
" {'text': \"issue of sexual assault by celebrities has not stopped. It's\",\n",
" 'start': 79.26,\n",
" 'duration': 3.24},\n",
" {'text': \"true that it happened to me. It's\",\n",
" 'start': 87.74,\n",
" 'duration': 3.96},\n",
" {'text': 'reallyembarrassing', 'start': 96.299, 'duration': 3.721},\n",
" {'text': \"[Music] It's disastrous\", 'start': 98.16, 'duration': 4.099},\n",
" {'text': '[Music]', 'start': 102.36, 'duration': 3.18},\n",
" {'text': \"There's also a part where feminists are obsessed with men's genitals. I think their germinating\",\n",
" 'start': 111.6,\n",
" 'duration': 4.5},\n",
" {'text': 'power is a really scary part. I',\n",
" 'start': 113.82,\n",
" 'duration': 4.259},\n",
" {'text': 'think this castration will happen more often as they get castrated.',\n",
" 'start': 121.259,\n",
" 'duration': 3.441},\n",
" {'text': 'In fact, feminism was popular at the time,',\n",
" 'start': 133.58,\n",
" 'duration': 7.659},\n",
" {'text': 'but thanks to its popularity,', 'start': 137.58, 'duration': 8.04},\n",
" {'text': 'a lot of', 'start': 141.239, 'duration': 8.041},\n",
" {'text': 'things happened, such as scolding, ridicule, insults, and',\n",
" 'start': 145.62,\n",
" 'duration': 5.04},\n",
" {'text': 'insults against', 'start': 149.28, 'duration': 2.28},\n",
" {'text': 'men. I', 'start': 150.66, 'duration': 2.7},\n",
" {'text': \"just couldn't stay there. Well, the\",\n",
" 'start': 153.36,\n",
" 'duration': 5.459},\n",
" {'text': 'pepper is 3 cm.', 'start': 160.2, 'duration': 5.58},\n",
" {'text': 'Besides, all men are potential rape',\n",
" 'start': 162.36,\n",
" 'duration': 7.019},\n",
" {'text': 'criminals. Men are useless. Men stopped',\n",
" 'start': 165.78,\n",
" 'duration': 6.599},\n",
" {'text': 'trusting women. If you', 'start': 176.34, 'duration': 4.92},\n",
" {'text': 'reach there, you may be hit by the #MeToo movement, so I',\n",
" 'start': 184.92,\n",
" 'duration': 3.86},\n",
" {'text': 'think there are a lot of them right now. I think',\n",
" 'start': 200.28,\n",
" 'duration': 2.539},\n",
" {'text': 'there may be a little more than in other countries.',\n",
" 'start': 221.76,\n",
" 'duration': 4.8},\n",
" {'text': '[Applause]', 'start': 238.29, 'duration': 3.23},\n",
" {'text': '[Music]', 'start': 243.27, 'duration': 7.169},\n",
" {'text': 'Personally, I', 'start': 245.78, 'duration': 8.019},\n",
" {'text': \"would say it's content that only has these emotions. As an\",\n",
" 'start': 250.439,\n",
" 'duration': 6.061},\n",
" {'text': 'example, I said that we need to strongly pass the anti-discrimination law, but',\n",
" 'start': 253.799,\n",
" 'duration': 4.801},\n",
" {'text': 'this is actually an expression', 'start': 258.6, 'duration': 3.89},\n",
" {'text': 'dictatorship class. Guys', 'start': 259.919, 'duration': 5.111},\n",
" {'text': '[Applause]', 'start': 262.49, 'duration': 4.149},\n",
" {'text': '[Music] I think you', 'start': 265.03, 'duration': 3.949},\n",
" {'text': \"'re talking a lot, but I want to hear it. Oh, you're not going to listen. You're so mean.\",\n",
" 'start': 268.979,\n",
" 'duration': 5.041},\n",
" {'text': 'For example, I went to the bathroom, and I',\n",
" 'start': 295.02,\n",
" 'duration': 2.7},\n",
" {'text': 'saw that it was unisex, but I want it to be safe with the door open. I',\n",
" 'start': 297.72,\n",
" 'duration': 4.8},\n",
" {'text': 'think I was able to see well how men and women cut off harmony at the source. My',\n",
" 'start': 354.18,\n",
" 'duration': 2.6},\n",
" {'text': 'girlfriend is', 'start': 357.96, 'duration': 4.5},\n",
" {'text': 'not satisfied with something like that.',\n",
" 'start': 359.759,\n",
" 'duration': 4.081},\n",
" {'text': 'Could anyone who really thought about gender equality talk about peeing and taking a shower? I think',\n",
" 'start': 371.539,\n",
" 'duration': 3.541},\n",
" {'text': '[Music]', 'start': 378.61, 'duration': 3.159},\n",
" {'text': 'In fact, many companies are', 'start': 384.479, 'duration': 3.321},\n",
" {'text': 'paying for it,', 'start': 388.979, 'duration': 4.44},\n",
" {'text': 'or in the labor market, there', 'start': 390.12, 'duration': 6.74},\n",
" {'text': 'is employment discrimination without any reason for gender inequality.',\n",
" 'start': 393.419,\n",
" 'duration': 3.441},\n",
" {'text': 'Evil men must disappear', 'start': 450.539, 'duration': 7.141},\n",
" {'text': 'Because of these millitons, there are many such people',\n",
" 'start': 454.56,\n",
" 'duration': 7.139},\n",
" {'text': 'in Korean society, and Ha Tae-kyung is a',\n",
" 'start': 457.68,\n",
" 'duration': 4.019},\n",
" {'text': 'representative abolitionist. It',\n",
" 'start': 472.979,\n",
" 'duration': 7.521},\n",
" {'text': 'means that I oppose giving privileges to Han Gender.',\n",
" 'start': 503.099,\n",
" 'duration': 5.641},\n",
" {'text': 'Korean feminists are now', 'start': 504.3, 'duration': 8.58},\n",
" {'text': 'understood as', 'start': 508.74, 'duration': 6.5},\n",
" {'text': 'discriminatory against men. In such a society,',\n",
" 'start': 528.42,\n",
" 'duration': 4.56},\n",
" {'text': 'I', 'start': 534.8, 'duration': 6.479},\n",
" {'text': 'think we should pay more attention to the serious discrimination against women.',\n",
" 'start': 537.18,\n",
" 'duration': 4.099},\n",
" {'text': 'Recently,', 'start': 544.08, 'duration': 3.0},\n",
" {'text': 'when I look at the political situation in Korea, I feel that it is now retreating.',\n",
" 'start': 551.459,\n",
" 'duration': 4.741},\n",
" {'text': '19% of female lawmakers in the National Assembly',\n",
" 'start': 559.62,\n",
" 'duration': 4.44},\n",
" {'text': 'are now 19%.', 'start': 561.06, 'duration': 3.0},\n",
" {'text': 'Why do people who send me messages like this send me messages like this',\n",
" 'start': 592.14,\n",
" 'duration': 3.84},\n",
" {'text': 'when they come every day? It', 'start': 593.76, 'duration': 4.92},\n",
" {'text': \"'s necessary, but it seems that there\",\n",
" 'start': 615.3,\n",
" 'duration': 3.479},\n",
" {'text': 'are many cases where the target is directed at women,',\n",
" 'start': 618.779,\n",
" 'duration': 3.74},\n",
" {'text': \"but if there's a motto that I\", 'start': 645.42, 'duration': 5.82},\n",
" {'text': \"personally take while leading this group, let's\",\n",
" 'start': 647.12,\n",
" 'duration': 5.32},\n",
" {'text': \"create a world where feminists don't have to choose feminism. I\",\n",
" 'start': 657.899,\n",
" 'duration': 3.721},\n",
" {'text': 'choose', 'start': 665.339, 'duration': 5.161},\n",
" {'text': \"feminism because I think you're watching.\",\n",
" 'start': 676.019,\n",
" 'duration': 4.081},\n",
" {'text': 'As a person, I live to protect the woman I love.',\n",
" 'start': 686.959,\n",
" 'duration': 5.701},\n",
" {'text': \"I think I'm about the level of a director who creates a hero.\",\n",
" 'start': 697.82,\n",
" 'duration': 6.94},\n",
" {'text': 'Well,', 'start': 701.04, 'duration': 3.72},\n",
" {'text': 'one day,', 'start': 707.16, 'duration': 10.41},\n",
" {'text': '[Music] We were', 'start': 727.75, 'duration': 4.46},\n",
" {'text': 'humiliated like', 'start': 730.2, 'duration': 5.139},\n",
" {'text': 'this. I', 'start': 736.7, 'duration': 4.84},\n",
" {'text': \"think there are so many messages in this very short video. First of all, I think there's\",\n",
" 'start': 741.54,\n",
" 'duration': 2.64},\n",
" {'text': 'enough room for it to be interpreted as',\n",
" 'start': 744.18,\n",
" 'duration': 2.54},\n",
" {'text': 'sexual', 'start': 756.36, 'duration': 4.979},\n",
" {'text': 'harassment.', 'start': 762.66, 'duration': 5.1},\n",
" {'text': 'But I really', 'start': 777.42, 'duration': 4.38},\n",
" {'text': 'had no intention of interfering with the event.',\n",
" 'start': 780.3,\n",
" 'duration': 3.42},\n",
" {'text': 'It was a chance to share, but I',\n",
" 'start': 791.04,\n",
" 'duration': 7.28},\n",
" {'text': \"think I couldn't give you a good answer after hearing that conversation.\",\n",
" 'start': 795.12,\n",
" 'duration': 3.2},\n",
" {'text': '[Music] I was', 'start': 802.19, 'duration': 2.649},\n",
" {'text': 'very surprised. I', 'start': 803.76, 'duration': 2.04},\n",
" {'text': 'went with my faith,', 'start': 805.8, 'duration': 4.26},\n",
" {'text': 'but', 'start': 819.06, 'duration': 2.6},\n",
" {'text': \"I felt completely betrayed. It's\",\n",
" 'start': 822.019,\n",
" 'duration': 3.991},\n",
" {'text': 'just', 'start': 824.16, 'duration': 4.91},\n",
" {'text': '[Music] [', 'start': 826.01, 'duration': 3.06},\n",
" {'text': 'Music] If', 'start': 831.75, 'duration': 3.09},\n",
" {'text': 'you', 'start': 839.88, 'duration': 5.04},\n",
" {'text': \"feel sexually shameful, that's\", 'start': 842.04, 'duration': 5.7},\n",
" {'text': \"sexual harassment. In Korea, that's the\",\n",
" 'start': 847.74,\n",
" 'duration': 5.06},\n",
" {'text': \"case. It's\", 'start': 853.399, 'duration': 6.641},\n",
" {'text': 'scary to lose everything and become something really different only from the genitals',\n",
" 'start': 864.36,\n",
" 'duration': 5.59},\n",
" {'text': '[Music]', 'start': 864.95, 'duration': 5.0},\n",
" {'text': '[Music]', 'start': 888.91, 'duration': 3.09}]"
]
},
"execution_count": 42,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"raw"
]
},
{
"cell_type": "code",
"execution_count": 43,
"metadata": {},
"outputs": [],
"source": [
"# Convert the list of dictionaries to a pandas dataframe\n",
"df = pd.DataFrame(raw)\n",
"\n",
"# Add end column\n",
"df['end'] = df['start'] + df['duration']\n",
"\n",
"# Add a new column to the dataframe called 'total_words' that contains the total number of words so far in the transcript\n",
"df['total_words'] = df['text'].apply(lambda x: len(x.split())).cumsum()\n",
"\n",
"# Add \"\\n\\n\" at the end of df[\"text\"]\n",
"df[\"text\"] = df[\"text\"] + \"\\n\\n\""
]
},
{
"cell_type": "code",
"execution_count": 44,
"metadata": {},
"outputs": [],
"source": [
"# Merge the text column into a single string and save to a transcript variable\n",
"\n",
"transcript = df['text'].str.cat(sep=' ')"
]
},
{
"cell_type": "code",
"execution_count": 45,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"\"[Music]\\n\\n [Music]\\n\\n [Applause]\\n\\n [Music]\\n\\n [Laughter] [Music] [Music] [\\n\\n Applause]\\n\\n [Music]\\n\\n Recently, the\\n\\n issue of sexual assault by celebrities has not stopped. It's\\n\\n true that it happened to me. It's\\n\\n reallyembarrassing\\n\\n [Music] It's disastrous\\n\\n [Music]\\n\\n There's also a part where feminists are obsessed with men's genitals. I think their germinating\\n\\n power is a really scary part. I\\n\\n think this castration will happen more often as they get castrated.\\n\\n In fact, feminism was popular at the time,\\n\\n but thanks to its popularity,\\n\\n a lot of\\n\\n things happened, such as scolding, ridicule, insults, and\\n\\n insults against\\n\\n men. I\\n\\n just couldn't stay there. Well, the\\n\\n pepper is 3 cm.\\n\\n Besides, all men are potential rape\\n\\n criminals. Men are useless. Men stopped\\n\\n trusting women. If you\\n\\n reach there, you may be hit by the #MeToo movement, so I\\n\\n think there are a lot of them right now. I think\\n\\n there may be a little more than in other countries.\\n\\n [Applause]\\n\\n [Music]\\n\\n Personally, I\\n\\n would say it's content that only has these emotions. As an\\n\\n example, I said that we need to strongly pass the anti-discrimination law, but\\n\\n this is actually an expression\\n\\n dictatorship class. Guys\\n\\n [Applause]\\n\\n [Music] I think you\\n\\n 're talking a lot, but I want to hear it. Oh, you're not going to listen. You're so mean.\\n\\n For example, I went to the bathroom, and I\\n\\n saw that it was unisex, but I want it to be safe with the door open. I\\n\\n think I was able to see well how men and women cut off harmony at the source. My\\n\\n girlfriend is\\n\\n not satisfied with something like that.\\n\\n Could anyone who really thought about gender equality talk about peeing and taking a shower? I think\\n\\n [Music]\\n\\n In fact, many companies are\\n\\n paying for it,\\n\\n or in the labor market, there\\n\\n is employment discrimination without any reason for gender inequality.\\n\\n Evil men must disappear\\n\\n Because of these millitons, there are many such people\\n\\n in Korean society, and Ha Tae-kyung is a\\n\\n representative abolitionist. It\\n\\n means that I oppose giving privileges to Han Gender.\\n\\n Korean feminists are now\\n\\n understood as\\n\\n discriminatory against men. In such a society,\\n\\n I\\n\\n think we should pay more attention to the serious discrimination against women.\\n\\n Recently,\\n\\n when I look at the political situation in Korea, I feel that it is now retreating.\\n\\n 19% of female lawmakers in the National Assembly\\n\\n are now 19%.\\n\\n Why do people who send me messages like this send me messages like this\\n\\n when they come every day? It\\n\\n 's necessary, but it seems that there\\n\\n are many cases where the target is directed at women,\\n\\n but if there's a motto that I\\n\\n personally take while leading this group, let's\\n\\n create a world where feminists don't have to choose feminism. I\\n\\n choose\\n\\n feminism because I think you're watching.\\n\\n As a person, I live to protect the woman I love.\\n\\n I think I'm about the level of a director who creates a hero.\\n\\n Well,\\n\\n one day,\\n\\n [Music] We were\\n\\n humiliated like\\n\\n this. I\\n\\n think there are so many messages in this very short video. First of all, I think there's\\n\\n enough room for it to be interpreted as\\n\\n sexual\\n\\n harassment.\\n\\n But I really\\n\\n had no intention of interfering with the event.\\n\\n It was a chance to share, but I\\n\\n think I couldn't give you a good answer after hearing that conversation.\\n\\n [Music] I was\\n\\n very surprised. I\\n\\n went with my faith,\\n\\n but\\n\\n I felt completely betrayed. It's\\n\\n just\\n\\n [Music] [\\n\\n Music] If\\n\\n you\\n\\n feel sexually shameful, that's\\n\\n sexual harassment. In Korea, that's the\\n\\n case. It's\\n\\n scary to lose everything and become something really different only from the genitals\\n\\n [Music]\\n\\n [Music]\\n\\n\""
]
},
"execution_count": 45,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"transcript"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
"tt = TextTilingTokenizer()\n",
"\n",
"# Tokenize the transcript into segments using the TextTilingTokenizer\n",
"segments = tt.tokenize(transcript)"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
"# # Remove \\n\\n from each segment\n",
"segments = [segment.replace('\\n\\n','').strip() for segment in segments]"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [],
"source": [
"# Calculate a list of word count for each segment\n",
"segments_wc = [len(segment.split()) for segment in segments]\n",
"\n",
"# Make it cumulative\n",
"segments_wc = np.cumsum(segments_wc)"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [],
"source": [
"def to_timestamp(seconds):\n",
" seconds = int(seconds)\n",
"\n",
" hours = seconds // 3600\n",
" minutes = (seconds % 3600) // 60\n",
" seconds_remaining = seconds % 60\n",
" \n",
" if seconds >= 3600:\n",
" return f\"{hours:02d}:{minutes:02d}:{seconds_remaining:02d}\"\n",
" else:\n",
" return f\"{minutes:02d}:{seconds_remaining:02d}\""
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'01:40'"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"to_timestamp(100)"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [],
"source": [
"# For each value in segments_wc, get the index of the closest value in df['total_words']\n",
"# This will be the index of the row in df that is closest to the end of each segment\n",
"idx = [np.argmin(np.abs(df['total_words'] - total_words)) for total_words in segments_wc]\n",
"\n",
"# Get segment end times from idx\n",
"segment_end_times = df['end'].iloc[idx].values\n",
"\n",
"# Add 0.0 to the beginning of segment_end_times\n",
"segment_end_times = np.insert(segment_end_times, 0, 0.0)\n",
"\n",
"# segment_times is a list of tuples containing the start and end times of each segment\n",
"segment_times = [(to_timestamp(segment_end_times[i-1]), to_timestamp(segment_end_times[i])) for i in range(1,len(segment_end_times))]"
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {},
"outputs": [],
"source": [
"# At the beginning of each segment, add the title, author, and segment times\n",
"segments_times = [f\"({to_timestamp(segment_end_times[i-1])}, {to_timestamp(segment_end_times[i])})\" for i in range(1,len(segment_end_times))]"
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"['(00:00, 00:48)',\n",
" '(00:48, 01:10)',\n",
" '(01:10, 01:46)',\n",
" '(01:46, 02:26)',\n",
" '(02:26, 02:57)',\n",
" '(02:57, 03:25)',\n",
" '(03:25, 04:11)',\n",
" '(04:11, 04:41)',\n",
" '(04:41, 05:26)',\n",
" '(05:26, 05:45)',\n",
" '(05:45, 06:13)',\n",
" '(06:13, 06:40)',\n",
" '(06:40, 07:02)',\n",
" '(07:02, 07:54)',\n",
" '(07:54, 08:17)',\n",
" '(08:17, 09:24)',\n",
" '(09:24, 10:10)',\n",
" '(10:10, 11:02)',\n",
" '(11:02, 11:47)',\n",
" '(11:47, 12:09)',\n",
" '(12:09, 12:52)',\n",
" '(12:52, 13:50)',\n",
" '(13:50, 14:15)',\n",
" '(14:15, 14:38)',\n",
" '(14:38, 16:14)',\n",
" '(16:14, 17:16)',\n",
" '(17:16, 17:47)',\n",
" '(17:47, 18:17)',\n",
" '(18:17, 18:56)',\n",
" '(18:56, 19:31)',\n",
" '(19:31, 19:52)',\n",
" '(19:52, 21:03)',\n",
" '(21:03, 21:39)',\n",
" '(21:39, 22:08)',\n",
" '(22:08, 22:42)',\n",
" '(22:42, 23:35)',\n",
" '(23:35, 24:51)',\n",
" '(24:51, 26:01)',\n",
" '(26:01, 26:28)',\n",
" '(26:28, 26:57)',\n",
" '(26:57, 28:37)',\n",
" '(28:37, 29:00)',\n",
" '(29:00, 29:50)',\n",
" '(29:50, 30:12)',\n",
" '(30:12, 30:55)',\n",
" '(30:55, 31:47)',\n",
" '(31:47, 32:54)',\n",
" '(32:54, 33:33)',\n",
" '(33:33, 33:50)',\n",
" '(33:50, 34:20)',\n",
" '(34:20, 34:48)',\n",
" '(34:48, 35:22)',\n",
" '(35:22, 36:14)',\n",
" '(36:14, 37:15)']"
]
},
"execution_count": 23,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"segments_times"
]
},
{
"cell_type": "code",
"execution_count": 72,
"metadata": {},
"outputs": [],
"source": [
"text = '''\n",
"Segment from 'Feminism Is 'Dividing This'' Country' by VICE News\n",
"Timestamp: (10:51, 12:24)\n",
"---\n",
"personally take while leading this group, let's create a world where feminists don't have to choose feminism. I choose feminism because I think you're watching. As a person, I live to protect the woman I love. I think I'm about the level of a director who creates a hero. Well, one day, [Music] We were humiliated like this. I think there are so many messages in this very short video. First of all, I think there's\n",
"---\n",
"'''\n",
"\n",
"# Get the title and timestamp from the text\n",
"import re\n",
"\n",
"# define regular expression patterns\n",
"title_pattern = r\"Segment from '(.+)'\"\n",
"timestamp_pattern = r\"Timestamp: \\((.+)\\)\"\n",
"\n",
"# search for title, source, and timestamp using regular expressions\n",
"title = re.search(title_pattern, text).group(1)\n",
"start_timestamp = re.search(timestamp_pattern, text).group(1).split(\",\")[0]\n",
"\n",
"url = f\"URL: https://www.youtube.com/watch?v={video_id}&t={start_timestamp}\"\n",
"\n",
"# Add url in text before first \"---\"\n",
"text = re.sub(r\"---\", f\"{url}\\n---\", text, count=1)\n"
]
},
{
"cell_type": "code",
"execution_count": 73,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"\"\\nSegment from 'Feminism Is 'Dividing This'' Country' by VICE News\\nTimestamp: (10:51, 12:24)\\nURL: https://www.youtube.com/watch?v=77zvIYDFSok&t=10:51 \\n---\\npersonally take while leading this group, let's create a world where feminists don't have to choose feminism. I choose feminism because I think you're watching. As a person, I live to protect the woman I love. I think I'm about the level of a director who creates a hero. Well, one day, [Music] We were humiliated like this. I think there are so many messages in this very short video. First of all, I think there's\\n---\\n\""
]
},
"execution_count": 73,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"text"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.0"
},
"orig_nbformat": 4
},
"nbformat": 4,
"nbformat_minor": 2
}
|