jaysonlong / webvideo-downloader

Web video downloader for Bilibili, iQIYI, Tencent Video, MGTV and WeTV. 网站视频下载器,主要支持Bilibili、爱奇艺、腾讯视频、芒果TV、WeTV、愛奇藝台灣站。
1.11k stars 245 forks source link

WeTV無字幕/ WeTV Without subtitle #128

Closed ChunlyShen closed 2 years ago

ChunlyShen commented 2 years ago

WeTV的字幕連結是錯的,所以下載合併後影片不會顯示字幕。請問有辦法修改嗎?謝謝。

Sparh4wk commented 2 years ago

its been already reported in #126

peedan commented 2 years ago

Please solve the problem. It happened for many days(two weeks or longer?). Thank you, @jaysonlong

ChunlyShen commented 2 years ago

I open the "dispatcher.py" file and try to print the "subtitles" variable that I find the download link is incorrect, please see below image image

For example, Subtitles URL is: 'https://subtitle.wetvinfo.com/svp_50125/cdv-ATVenqQXzlY2xukZ_Qc8Ns_J-DCZy28GXQT5gNJf0x5wLpg93mSNkBH0BueEOrxfDvhEX_UfS9lk2pMZATDKEF4Rn4niLUhNJnEse758eLTJtTc_ztfmx6AIsd2irswrLTEwc2IEw70dXrwdmA/gzc_1000117_0b53jaaccaaaqeal4o5vbzqm2sgdefcaajca.f490105.vtt.m3u8?ver=4' (incorrect)

We can see the URL last name is:".vtt.m3u8?ver=4" However, the correct URL last name should be: ".vtt"

Therefore, the correct URL is: 'https://subtitle.wetvinfo.com/svp_50125/cdv-ATVenqQXzlY2xukZ_Qc8Ns_J-DCZy28GXQT5gNJf0x5wLpg93mSNkBH0BueEOrxfDvhEX_UfS9lk2pMZATDKEF4Rn4niLUhNJnEse758eLTJtTc_ztfmx6AIsd2irswrLTEwc2IEw70dXrwdmA/gzc_1000117_0b53jaaccaaaqeal4o5vbzqm2sgdefcaajca.f490105.vtt' (correct)

I only know the error, but I don't know how to fix it.

By the way, if someone wants to download subtitles they can print "subtitles variable" to get the correct link before the error is fixed.

maradonaz commented 2 years ago

I open the "dispatcher.py" file and try to print the "subtitles" variable that I find the download link is incorrect, please see below image image

For example, Subtitles URL is: 'https://subtitle.wetvinfo.com/svp_50125/cdv-ATVenqQXzlY2xukZ_Qc8Ns_J-DCZy28GXQT5gNJf0x5wLpg93mSNkBH0BueEOrxfDvhEX_UfS9lk2pMZATDKEF4Rn4niLUhNJnEse758eLTJtTc_ztfmx6AIsd2irswrLTEwc2IEw70dXrwdmA/gzc_1000117_0b53jaaccaaaqeal4o5vbzqm2sgdefcaajca.f490105.vtt.m3u8?ver=4' (incorrect)

We can see the URL last name is:".vtt.m3u8?ver=4" However, the correct URL last name should be: ".vtt"

Therefore, the correct URL is: 'https://subtitle.wetvinfo.com/svp_50125/cdv-ATVenqQXzlY2xukZ_Qc8Ns_J-DCZy28GXQT5gNJf0x5wLpg93mSNkBH0BueEOrxfDvhEX_UfS9lk2pMZATDKEF4Rn4niLUhNJnEse758eLTJtTc_ztfmx6AIsd2irswrLTEwc2IEw70dXrwdmA/gzc_1000117_0b53jaaccaaaqeal4o5vbzqm2sgdefcaajca.f490105.vtt' (correct)

I only know the error, but I don't know how to fix it.

By the way, if someone wants to download subtitles they can print "subtitles variable" to get the correct link before the error is fixed.

Thank you this was of great help in getting the subtitles even if I have a separate file.

enaskr commented 2 years ago

When I opened .vtt file, I knew just added 8 lines on top of the file. Remove just 8 lines and rename .srt, it worked fine. image

chathos commented 2 years ago

I open the "dispatcher.py" file and try to print the "subtitles" variable that I find the download link is incorrect, please see below image image

For example, Subtitles URL is: 'https://subtitle.wetvinfo.com/svp_50125/cdv-ATVenqQXzlY2xukZ_Qc8Ns_J-DCZy28GXQT5gNJf0x5wLpg93mSNkBH0BueEOrxfDvhEX_UfS9lk2pMZATDKEF4Rn4niLUhNJnEse758eLTJtTc_ztfmx6AIsd2irswrLTEwc2IEw70dXrwdmA/gzc_1000117_0b53jaaccaaaqeal4o5vbzqm2sgdefcaajca.f490105.vtt.m3u8?ver=4' (incorrect)

We can see the URL last name is:".vtt.m3u8?ver=4" However, the correct URL last name should be: ".vtt"

Therefore, the correct URL is: 'https://subtitle.wetvinfo.com/svp_50125/cdv-ATVenqQXzlY2xukZ_Qc8Ns_J-DCZy28GXQT5gNJf0x5wLpg93mSNkBH0BueEOrxfDvhEX_UfS9lk2pMZATDKEF4Rn4niLUhNJnEse758eLTJtTc_ztfmx6AIsd2irswrLTEwc2IEw70dXrwdmA/gzc_1000117_0b53jaaccaaaqeal4o5vbzqm2sgdefcaajca.f490105.vtt' (correct)

I only know the error, but I don't know how to fix it.

By the way, if someone wants to download subtitles they can print "subtitles variable" to get the correct link before the error is fixed.

Link has no problem but ffmpeg downloader not downloading vtt .

enaskr commented 2 years ago

I fixed this issue. but my source is dirty. I learned python just 10 days. This is part of dispatcher.py. I confirmed only WeTV and IQIYI.

`

# For Only WeTV Global (Subtitle changed from webvtt to srt, just remove webvtt header)
# Just Remove webvtt header until "1"
def vtt_to_srt(self, vttFile):
    myFile = open(vttFile, 'r')
    vttfile = myFile.readlines()
    myFile.close()

    for i in range(0,15):
        if ( vttfile[i].startswith('1') ):
            break
        vttfile[i]=''

    srtFileName = vttFile.replace(".vtt",".srt")
    srtFile = open(srtFileName, 'a')
    srtFile.writelines(vttfile)
    srtFile.close()

def handleSubtitles(self, subtitles, fileName, videoName, headers = {}):
    print("-- dispatcher/handleSubtitles")
    subtitleUrls, subtitleNames = [], []
    subtitlesInfo = []
    # For WeTV subtitle file process ( .vtt to .srt )
    subtitleNames1, subtitlesInfo1 = [], []

    for name, url in subtitles:
        # remove .m3u8 from subtitle url
        url = url.replace(".m3u8","")
        subtitleUrls.append(url)
        subtitleName = tools.join(self.tempFilePath, '%s_%s%s' % \
            (fileName, name, tools.getSuffix(url)))
        subtitleNames1.append(subtitleName)
        subtitlesInfo1.append((name, subtitleName))

    self.downloader.downloadAll(subtitleUrls, subtitleNames1, headers, self.hlsThreadCnt)

    for each in subtitleNames1:
        # IF subtitle name is .vtt (This is WeTV)
        if ( ".vtt" in each ):
            # Convert vtt to srt
            self.vtt_to_srt(each)
            # subtitle name extension change from vtt to srt
            each = each.replace(".vtt",".srt")
            subtitleNames.append(each)
            tools.tryFixSrtFile(each)
            # for delete vtt file
            each = each.replace(".srt",".vtt")
            os.remove(each)
        else:
            subtitleNames.append(each)
            tools.tryFixSrtFile(each)

    for name1, each1 in subtitlesInfo1:
        # IF subtitle name is .vtt (This is WeTV)
        if ( ".vtt" in each1 ):
            # subtitle name extension change from vtt to srt
            each1 = each1.replace(".vtt",".srt")
        subtitlesInfo.append((name1, each1))

    targetFileName = tools.integrateSubtitles(subtitlesInfo, videoName)
    self.saveTempFile or tools.removeFiles(subtitleNames)
    return targetFileName

`

ChunlyShen commented 2 years ago

Hi @enaskr. Sorry, I'm new that I change my code to your code and I get the error msg. image

The below photo is my code. What's wrong with my code? image

image

ssettor commented 2 years ago

Hi @enaskr. Sorry, I'm new that I change my code to your code and I get the error msg. image

The below photo is my code. What's wrong with my code? image

image

line 97 myFile = open(vttFile, 'r', encoding='utf-8') line 107 srtFile = open(srtFileName, 'a', encoding='utf-8')

ChunlyShen commented 2 years ago

Hi @ssettor, Thanks a lot for your reply! I edited the code and it can work now! Thank you so much!!! : )

In summary, just follow @enaskr 's code (https://github.com/jaysonlong/webvideo-downloader/issues/128#issuecomment-1093729341 ). However, if it get some unicode error, please edit below (https://github.com/jaysonlong/webvideo-downloader/issues/128#issuecomment-1099816625):

  1. find 「myFile = open(vttFile, 'r')」 ,and change to => 「myFile = open(vttFile, 'r', encoding='utf-8')」
  2. find 「srtFile = open(srtFileName, 'a')」, and change to => 「open(srtFileName, 'a', encoding='utf-8')」
peedan commented 2 years ago

Hi @ssettor, Thanks a lot for your reply! I edited the code and it can work now! Thank you so much!!! : )

In summary, just follow @enaskr 's code (#128 (comment) ). However, if it get some unicode error, please edit below (#128 (comment)):

  1. find 「myFile = open(vttFile, 'r')」 ,and change to => 「myFile = open(vttFile, 'r', encoding='utf-8')」
  2. find 「srtFile = open(srtFileName, 'a')」, and change to => 「open(srtFileName, 'a', encoding='utf-8')」

Hi @ChunlyShen

I have tried many times but it still cannot work. Would you please upload your dispatcher.py to any public free space, such as mega, GD,....etc ? Thanks a lot.

ChunlyShen commented 2 years ago

Hi @peedan Sure:(2022/4/30 Update link) https://drive.google.com/file/d/16Vu2AxbtRLsZeMlmRwZiJ8bSrBue-vxh/view?usp=sharing However, some videos can work, and some videos can't. I am still trying to find why.

I guess the problem gets from [.srt merge to .mp4].

ChunlyShen commented 2 years ago

I found [.srt merge to .mp4] get error reason, it because of "the subtitles file format".

For example:

When I download to get the error, the .srt file are saved to the temp folder. image

image

I compare all [.srt] file content and found something different in the content.

Please see below the photo-A, the time format is 00:00.000 image

Please see below the photo-B, the time format is 00:00:00.000 image

There are [.srt] files that can work for the online player, however, the program "merger function(.srt merge to .mp4)" can't work for the time format of photo-A.

Therefore, solutions are two ways:

  1. Edit the merger code to support the "00:00.000" time format.
  2. Ignore the "00:00.000" time format .srt file, only get "00:00:00.000" .srt file, it can merger to .mp4.

For number 2, my solution is: I only want to get the ["繁體" .srt file] and the format is 00:00:00.000, so I edit my code, please see below: image

image

Finally, I can download the video successfully.