Conversation
| else: | ||
| trytime=10 | ||
| print("%s max try times."%url) | ||
| print(f"{url} max try times.") |
There was a problem hiding this comment.
Function urldown refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring)
| errorfile=open("error.txt","a") | ||
| errorfile.write(link+"\n") | ||
| errorfile.close() | ||
| with open("error.txt","a") as errorfile: | ||
| errorfile.write(link+"\n") |
There was a problem hiding this comment.
Function M3U8_object.__init__ refactored with the following changes:
- Use
withwhen opening file to ensure closure (ensure-file-closed)
| mu=open(m3u8name,"w") | ||
| m3u8=bytes.decode(urllib.request.urlopen(self.link).read()).split("\n") | ||
| for line in m3u8: | ||
| if "#EXT-X-KEY" in line: | ||
| if "IV" not in line: | ||
| pattern=re.compile(r'METHOD=(.*),URI="(.*)"') | ||
| try: | ||
| self.Method=pattern.search(line).group(1) | ||
| self.Key=pattern.search(line).group(2) | ||
| if self.Key: | ||
| if urldown(self.Key): | ||
| print("%s 下载失败。"%self.Key) | ||
| else: | ||
| line=re.sub(pattern,'METHOD=%s,URI="%s"'%(self.Method,self.Key.split("/")[-1]),line) | ||
| except AttributeError: | ||
| print(line) | ||
| else: | ||
| pattern=re.compile(r'METHOD=(.*),URI="(.*)",IV=0x(.*)') | ||
| try: | ||
| self.Method=pattern.search(line).group(1) | ||
| self.Key=pattern.search(line).group(2) | ||
| self.IV=pattern.search(line).group(2) | ||
| except AttributeError: | ||
| print(line) | ||
| with open(m3u8name,"w") as mu: | ||
| m3u8=bytes.decode(urllib.request.urlopen(self.link).read()).split("\n") | ||
| for line in m3u8: | ||
| if "#EXT-X-KEY" in line: | ||
| if "IV" not in line: | ||
| pattern=re.compile(r'METHOD=(.*),URI="(.*)"') | ||
| try: | ||
| self.Method = pattern.search(line)[1] | ||
| self.Key = pattern.search(line)[2] | ||
| if self.Key: | ||
| if urldown(self.Key): | ||
| print(f"{self.Key} 下载失败。") | ||
| else: | ||
| line=re.sub(pattern,'METHOD=%s,URI="%s"'%(self.Method,self.Key.split("/")[-1]),line) | ||
| except AttributeError: | ||
| print(line) | ||
| else: | ||
| line=re.sub(pattern,'METHOD=%s,URI="%s",IV=0x%s'%(self.Method,self.Key.split("/")[-1],self.IV),line) | ||
| mu.write(line+"\n") | ||
| elif "#" not in line : | ||
| self.urls.append(line) | ||
| mu.write(line.split("/")[-1]+"\n") | ||
| else: | ||
| mu.write(line+"\n") | ||
| mu.close() | ||
| pattern=re.compile(r'METHOD=(.*),URI="(.*)",IV=0x(.*)') | ||
| try: | ||
| self.Method = pattern.search(line)[1] | ||
| self.Key = pattern.search(line)[2] | ||
| self.IV = pattern.search(line)[2] | ||
| except AttributeError: | ||
| print(line) | ||
| else: | ||
| line=re.sub(pattern,'METHOD=%s,URI="%s",IV=0x%s'%(self.Method,self.Key.split("/")[-1],self.IV),line) | ||
| mu.write(line+"\n") | ||
| elif "#" not in line : | ||
| self.urls.append(line) | ||
| mu.write(line.split("/")[-1]+"\n") | ||
| else: | ||
| mu.write(line+"\n") |
There was a problem hiding this comment.
Function M3U8_object.decode refactored with the following changes:
- Use
withwhen opening file to ensure closure (ensure-file-closed) - Replace m.group(x) with m[x] for re.Match objects [×5] (
use-getitem-for-re-match-groups) - Replace interpolated string formatting with f-string [×4] (
replace-interpolation-with-fstring) - Merge else clause's nested if statement into elif (
merge-else-if-into-elif)
| p.apply_async(urldown,args=(url+".mp4",)) | ||
| p.apply_async(urldown, args=(f"{url}.mp4", )) |
There was a problem hiding this comment.
Lines 149-149 refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation)
Sourcery Code Quality Report✅ Merging this PR will increase code quality in the affected files by 0.63%.
Here are some functions in these files that still need a tune-up:
Legend and ExplanationThe emojis denote the absolute quality of the code:
The 👍 and 👎 indicate whether the quality has improved or gotten worse with this pull request. Please see our documentation here for details on how these metrics are calculated. We are actively working on this report - lots more documentation and extra metrics to come! Help us improve this quality report! |
Branch
mainrefactored by Sourcery.If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.
See our documentation here.
Run Sourcery locally
Reduce the feedback loop during development by using the Sourcery editor plugin:
Review changes via command line
To manually merge these changes, make sure you're on the
mainbranch, then run:Help us improve this pull request!