Skip to content

Commit

Permalink
Add new attribute "type" of work.
Browse files Browse the repository at this point in the history
The game types will be aggregated.
  • Loading branch information
ch010060 committed Sep 16, 2020
1 parent 30f88e6 commit b5b80b8
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 13 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pip install tkintertable
pip install requests
```

**Keyword**:"workno", "circle", "title", "cv", "author", "work_age", "release_date", 模板中的這七個關鍵字將會被程式替換
**Keyword**:"workno", "circle", "title", "cv", "author", "work_age", "release_date", "type", 模板中的這8個關鍵字將會被程式替換

*關鍵字分別代表:*
1. workno: 作品編號
Expand All @@ -29,6 +29,7 @@ pip install requests
5. author: 作者
6. work_age: 年齡指定
7. release_date: 發售日
8. type: 作品形式

**Default template**: "workno title "

Expand All @@ -45,12 +46,12 @@ VJ開頭 => 遊戲 作品
例如:
```
"type": "vj"
"to": "(work_age)[release_date][workno][circle] title "
"to": "(type)(work_age)[release_date][workno][circle] title "
```

重命名前:[不必要的前綴] VJ009178 零.軌跡 (要刪掉的後綴)

重命名後:(全年齢)[150417][VJ009178][Falcom] 英雄伝説 零の軌跡
重命名後:(ゲーム)(全年齢)[150417][VJ009178][Falcom] 英雄伝説 零の軌跡

*config.json範例*
```json
Expand Down
18 changes: 13 additions & 5 deletions dlsite_renamer-cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,11 @@ def match_code(work_code):
url = VJ_G_WEBPATH + work_code
r = s.get(url, allow_redirects=False, cookies=R_COOKIE)
if r.status_code != 200:
return r.status_code, "", "", "", [], [], "", ""
return r.status_code, "", "", "", [], [], "", "", ""
except os.error as err:
print("**請求超時!\n")
print(" 請檢查網絡連接\n")
return "", "", "", "", [], [], "", ""
return "", "", "", "", [], [], "", "", ""

# fromstring()在解析xml格式時, 將字串轉換為Element對像, 解析樹的根節點
# 在python中, 對get請求返回的r.content做fromstring()處理, 可以方便進行後續的xpath()定位等
Expand All @@ -168,6 +168,13 @@ def match_code(work_code):
'//*[@id="work_outline"]/tr/th[contains(text(), "声優")]/../td/a/text()')
authorList = tree.xpath(
'//*[@id="work_maker"]/tr/th[contains(text(), "著者")]/../td/a/text()')
type = tree.xpath(
'//*[@id="work_outline"]/tr/th[contains(text(), "作品形式")]/../td/div/a/span/text()')[0]
# 精簡遊戲類型
game_type_list = ["アクション", "クイズ", "アドベンチャー", "ロールプレイング", "テーブル", "デジタルノベル", "シミュレーション", "タイピング", "シューティング", "パズル", "その他ゲーム"]
if type in game_type_list:
type = "ゲーム"

work_age = tree.xpath(
'//*[@id="work_outline"]/tr/th[contains(text(), "年齢指定")]/../td/div/a/span/text()')
if not work_age:
Expand All @@ -179,12 +186,12 @@ def match_code(work_code):
if len(release_date) >= 11:
release_date = release_date[2]+release_date[3]+release_date[5]+release_date[6]+release_date[8]+release_date[9]

return 200, img_url, title, circle, cvList, authorList, work_age[0], release_date
return 200, img_url, title, circle, cvList, authorList, work_age[0], release_date, type

except os.error as err:
print("**請求超時!\n")
print(" 請檢查網絡連接\n")
return "", "", "", "", [], [], "", ""
return "", "", "", "", [], [], "", "", ""

def nameChange(path, del_flag, cover_flag):
print("選擇路徑: " + path + "\n")
Expand All @@ -206,7 +213,7 @@ def nameChange(path, del_flag, cover_flag):
else:
#print('Processing: ' + code)
print('Processing: ' + code + '\n')
r_status, img_url, title, circle, cvList, authorList, work_age, release_date = match_code(code)
r_status, img_url, title, circle, cvList, authorList, work_age, release_date, type = match_code(code)
# 如果順利爬取網頁訊息
if r_status == 200 and title and circle:
if del_flag:
Expand All @@ -224,6 +231,7 @@ def nameChange(path, del_flag, cover_flag):
new_name = new_name.replace("circle", circle)
new_name = new_name.replace("work_age", work_age)
new_name = new_name.replace("release_date", release_date)
new_name = new_name.replace("type", type)

author = ""
if authorList: # 如果authorList非空
Expand Down
18 changes: 13 additions & 5 deletions dlsite_renamer.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,11 @@ def match_code(work_code):
url = VJ_G_WEBPATH + work_code
r = s.get(url, allow_redirects=False, cookies=R_COOKIE)
if r.status_code != 200:
return r.status_code, "", "", "", [], [], "", ""
return r.status_code, "", "", "", [], [], "", "", ""
except os.error as err:
text.insert(tk.END, "**請求超時!\n")
text.insert(tk.END, " 請檢查網絡連接\n")
return "", "", "", "", [], [], "", ""
return "", "", "", "", [], [], "", "", ""

# fromstring()在解析xml格式時, 將字串轉換為Element對像, 解析樹的根節點
# 在python中, 對get請求返回的r.content做fromstring()處理, 可以方便進行後續的xpath()定位等
Expand All @@ -166,6 +166,13 @@ def match_code(work_code):
'//*[@id="work_outline"]/tr/th[contains(text(), "声優")]/../td/a/text()')
authorList = tree.xpath(
'//*[@id="work_maker"]/tr/th[contains(text(), "著者")]/../td/a/text()')
type = tree.xpath(
'//*[@id="work_outline"]/tr/th[contains(text(), "作品形式")]/../td/div/a/span/text()')[0]
# 精簡遊戲類型
game_type_list = ["アクション", "クイズ", "アドベンチャー", "ロールプレイング", "テーブル", "デジタルノベル", "シミュレーション", "タイピング", "シューティング", "パズル", "その他ゲーム"]
if type in game_type_list:
type = "ゲーム"

work_age = tree.xpath(
'//*[@id="work_outline"]/tr/th[contains(text(), "年齢指定")]/../td/div/a/span/text()')
if not work_age:
Expand All @@ -177,12 +184,12 @@ def match_code(work_code):
if len(release_date) >= 11:
release_date = release_date[2]+release_date[3]+release_date[5]+release_date[6]+release_date[8]+release_date[9]

return 200, img_url, title, circle, cvList, authorList, work_age[0], release_date
return 200, img_url, title, circle, cvList, authorList, work_age[0], release_date, type

except os.error as err:
text.insert(tk.END, "**請求超時!\n")
text.insert(tk.END, " 請檢查網絡連接\n")
return "", "", "", "", [], [], "", ""
return "", "", "", "", [], [], "", "", ""

def nameChange():
# askdirectory()檔案對話框, 選擇目錄, 返回目錄名
Expand Down Expand Up @@ -213,7 +220,7 @@ def nameChange():
else:
#print('Processing: ' + code)
text.insert(tk.END, 'Processing: ' + code + '\n')
r_status, img_url, title, circle, cvList, authorList, work_age, release_date = match_code(code)
r_status, img_url, title, circle, cvList, authorList, work_age, release_date, type = match_code(code)
# 如果順利爬取網頁訊息
if r_status == 200 and title and circle:
if deltext.get():
Expand All @@ -231,6 +238,7 @@ def nameChange():
new_name = new_name.replace("circle", circle)
new_name = new_name.replace("work_age", work_age)
new_name = new_name.replace("release_date", release_date)
new_name = new_name.replace("type", type)

author = ""
if authorList: # 如果authorList非空
Expand Down

0 comments on commit b5b80b8

Please sign in to comment.