From 8501e877344c53a9dd607289cab316e57e50cc05 Mon Sep 17 00:00:00 2001 From: FireMasterK <20838718+FireMasterK@users.noreply.github.com> Date: Fri, 2 Oct 2020 00:37:32 +0530 Subject: [PATCH 1/2] Add support for multi-architecture Docker builds. --- .dockerignore | 2 ++ .github/dependabot.yml | 7 +++++ .github/workflows/docker-build.yml | 45 ++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+) create mode 100644 .github/dependabot.yml create mode 100644 .github/workflows/docker-build.yml diff --git a/.dockerignore b/.dockerignore index 31bb6fd..432d5d7 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,5 +1,7 @@ .git +.github .gitignore +cache Dockerfile docker-compose.yml LICENSE diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..2c7d170 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,7 @@ +version: 2 +updates: + # Maintain dependencies for GitHub Actions + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "daily" diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml new file mode 100644 index 0000000..615ebcc --- /dev/null +++ b/.github/workflows/docker-build.yml @@ -0,0 +1,45 @@ +name: Docker Multi-Architecture Build + +on: + push: + paths-ignore: + - "**.md" + branches: + - dev-indep + +jobs: + build-docker: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Set up QEMU + uses: docker/setup-qemu-action@v1 + with: + platforms: all + - name: Set up Docker Buildx + id: buildx + uses: docker/setup-buildx-action@v1 + with: + version: latest + - name: Login to DockerHub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + - name: cache docker cache + uses: actions/cache@v2.1.1 + with: + path: ${{ github.workspace }}/cache + key: ${{ runner.os }}-docker-${{ hashFiles('**/requirements.txt') }} + restore-keys: | + ${{ runner.os }}-docker-${{ hashFiles('**/requirements.txt') }} + - name: Build and push + uses: docker/build-push-action@v2 + with: + context: . + file: ./Dockerfile + platforms: linux/amd64,linux/arm64 + push: true + tags: ytorg/yotter:latest + cache-from: type=local,src=cache + cache-to: type=local,dest=cache From c05a53ca996f4f07fda1cbfd9427b175a55a51ee Mon Sep 17 00:00:00 2001 From: 0ihgk1uVBLlTBzVo7F9B <0ihgk1uVBLlTBzVo7F9B@protonmail.com> Date: Sat, 3 Oct 2020 19:06:37 +0200 Subject: [PATCH 2/2] Simplify import process. --- app/routes.py | 75 ++++++++++++++++--------------------- app/templates/settings.html | 10 +---- 2 files changed, 34 insertions(+), 51 deletions(-) diff --git a/app/routes.py b/app/routes.py index a0752ec..4eff283 100644 --- a/app/routes.py +++ b/app/routes.py @@ -47,7 +47,6 @@ YOUTUBERSS = "https://www.youtube.com/feeds/videos.xml?channel_id=" ########################## #### Global variables #### ########################## -ALLOWED_EXTENSIONS = {'json', 'db'} ######################### #### Twitter Logic ###### @@ -296,28 +295,34 @@ def ytsearch(): def ytfollow(channelId): form = EmptyForm() if form.validate_on_submit(): - r = followYoutubeChannel(channelId) + r = followYoutubeChannel(channelId) return redirect(request.referrer) def followYoutubeChannel(channelId): - channelData = YoutubeSearch.channelInfo(channelId, False) try: - if not current_user.is_following_yt(channelId): - follow = youtubeFollow() - follow.channelId = channelId - follow.channelName = channelData[0]['name'] - follow.followers.append(current_user) - db.session.add(follow) - db.session.commit() - flash("{} followed!".format(channelData[0]['name'])) - return True - else: + channelData = YoutubeSearch.channelInfo(channelId, False) + try: + if not current_user.is_following_yt(channelId): + follow = youtubeFollow() + follow.channelId = channelId + follow.channelName = channelData[0]['name'] + follow.followers.append(current_user) + db.session.add(follow) + db.session.commit() + flash("{} followed!".format(channelData[0]['name'])) + return True + else: + return False + except Exception as e: + print(e) + flash("Youtube: Couldn't follow {}. Already followed?".format(channelData[0]['name'])) return False - except Exception as e: - print(e) - flash("Youtube: Couldn't follow {}. Already followed?".format(channelData[0]['name'])) + except KeyError as ke: + print("KeyError: {}:'{}' could not be found".format(ke, channelId)) + flash("Youtube: ChannelId '{}' is not valid".format(channelId)) return False + @app.route('/ytunfollow/', methods=['POST']) @login_required def ytunfollow(channelId): @@ -571,16 +576,12 @@ def importdata(): if file.filename == '': flash('No selected file') return redirect(request.referrer) - if file and allowed_file(file.filename) or 'subscription_manager' in file.filename: + else: option = request.form['import_format'] if option == 'yotter': importYotterSubscriptions(file) - elif option == 'newpipe': - importNewPipeSubscriptions(file) elif option == 'youtube': importYoutubeSubscriptions(file) - elif option == 'freetube': - importFreeTubeSubscriptions(file) return redirect(request.referrer) return redirect(request.referrer) @@ -594,37 +595,25 @@ def deleteme(): logout_user() return redirect(url_for('index')) +def importYoutubeSubscriptions(file): + filename = secure_filename(file.filename) + try: + data = re.findall('(UC[a-zA-Z0-9_-]{22})|(?<=user/)[a-zA-Z0-9_-]+', file.read().decode('utf-8')) + for acc in data: + r = followYoutubeChannel(acc) + except Exception as e: + print(e) + flash("File is not valid.") def importYotterSubscriptions(file): filename = secure_filename(file.filename) data = json.load(file) for acc in data['twitter']: r = followTwitterAccount(acc['username']) - + for acc in data['youtube']: r = followYoutubeChannel(acc['channelId']) -def importNewPipeSubscriptions(file): - filename = secure_filename(file.filename) - data = json.load(file) - for acc in data['subscriptions']: - r = followYoutubeChannel(re.search('(UC[a-zA-Z0-9_-]{22})|(?<=user\/)[a-zA-Z0-9_-]+', acc['url']).group()) - -def importYoutubeSubscriptions(file): - filename = secure_filename(file.filename) - itemlist = minidom.parse(file).getElementsByTagName('outline') - for item in itemlist[1:]: - r = followYoutubeChannel(re.search('UC[a-zA-Z0-9_-]{22}', item.attributes['xmlUrl'].value).group()) - -def importFreeTubeSubscriptions(file): - filename = secure_filename(file.filename) - data = re.findall('UC[a-zA-Z0-9_-]{22}', file.read().decode('utf-8')) - for acc in data: - r = followYoutubeChannel(acc) - -def allowed_file(filename): - return '.' in filename and filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS - @app.route('/register', methods=['GET', 'POST']) def register(): form = RegistrationForm() diff --git a/app/templates/settings.html b/app/templates/settings.html index e0fcfc9..03206c9 100644 --- a/app/templates/settings.html +++ b/app/templates/settings.html @@ -31,7 +31,7 @@
-
Import suscription data
+
Import subscription data
@@ -39,15 +39,9 @@ - -